This file contains instructions for users of Protozero who are upgrading from one version to another.
You do not need to change anything if only the minor version changes, but it is better to keep up with changes if you can. The switch to the next major version will be easier then. And you might get some more convenient usage.
To help you with upgrading to new versions, you can define the C++ preprocessor
macro PROTOZERO_STRICT_API
in which case Protozero will compile without the
code used for backwards compatibilty. You will then get compile errors for
older API usages.
- The
pbf_writer
class is now a typedef forbasic_pbf_writer<std::string>
If you have forward declared it in your code, it might have to change.
- The
data_view
class moved fromtypes.hpp
into its own header filedata_view.hpp
. Most people should not include those headers directly, but if you do, you might have to change your includes. - There are two new exceptions
invalid_tag_exception
andinvalid_length_exception
which cover cases that were only checked byassert
before this version. If you catch specific exceptions in your code you might have to amend it. But just catchingprotozero::exception
is usually fine for most code (if you catch exceptions at all). - The
pbf_reader
constructor taking astd::pair
is now deprecated. If you are compiling withPROTOZERO_STRICT_API
it is not available any more. Use one of the other constructors instead.
- New functions for checking tag and type at the same time to make your program more robust. Read the section "Repeated fields in messages" in the new Advanced Topics documentation.
- The macro
PROTOZERO_DO_NOT_USE_BARE_POINTER
is not used any more. If you have been setting this, remove it.
- You can now do
require('protozero')
in nodejs to print the path to the include paths for the protozero headers.
-
Functions in
pbf_reader
(and the derivedpbf_message
) calledget_packed_*()
now return aniterator_range
instead of astd::pair
. The new class is derived fromstd::pair
, so changes are usually not strictly necessary. For future compatibility, you should change all attribute accesses on the returned objects fromfirst
andsecond
tobegin()
andend()
, respectively. So change something like this:auto x = message.get_packed_int32(); for (auto it = x.first; it != x.second; ++it) { .... }
to:
auto x = message.get_packed_int32(); for (auto it = x.begin(); it != x.end(); ++it) { .... }
or even better use the range-based for loop:
auto x = message.get_packed_int32(); for (auto val : x) { .... }
Ranges can also be used in this way. This will change the range in-place:
auto range = message.get_packed_int32(); while (!range.empty()) { auto value = range.front(); range.drop_front(); .... }
-
The class
pbf_reader
has a new methodget_view()
returning an object of the newprotozero::data_view
class. Thedata_view
only has minimal functionality, but what it has is compatible to thestd::string_view
class which will be coming in C++17. The view autoconverts to astd::string
if needed. Useget_view()
instead ofget_data()
giving you a more intuitive interface (calldata()
andsize()
on the view instead of usingfirst
andsecond
on thestd::pair
returned byget_data()
).You can set the macro
PROTOZERO_USE_VIEW
(before includingtypes.hpp
) to the name of any class that behaves likeprotozero::data_view
anddata_view
will be an alias to that class instead of the implementation from protozero. This way you can use the C++17string_view
or a similar class if it is already available on your system.