4.0 KiB
Upgrading
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.
Upgrading from v1.6 to v1.7
- The
pbf_writerclass is now a typedef forbasic_pbf_writer<std::string>If you have forward declared it in your code, it might have to change.
Upgrading from v1.5 to v1.6.0
- The
data_viewclass moved fromtypes.hppinto 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_exceptionandinvalid_length_exceptionwhich cover cases that were only checked byassertbefore this version. If you catch specific exceptions in your code you might have to amend it. But just catchingprotozero::exceptionis usually fine for most code (if you catch exceptions at all). - The
pbf_readerconstructor taking astd::pairis now deprecated. If you are compiling withPROTOZERO_STRICT_APIit is not available any more. Use one of the other constructors instead.
Upgrading from v1.4.5 to v1.5.0
- 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.
Upgrading from v1.4.4 to v1.4.5
- The macro
PROTOZERO_DO_NOT_USE_BARE_POINTERis not used any more. If you have been setting this, remove it.
Upgrading from v1.4.0 to v1.4.1
- You can now do
require('protozero')in nodejs to print the path to the include paths for the protozero headers.
Upgrading from v1.3.0 to v1.4.0
-
Functions in
pbf_reader(and the derivedpbf_message) calledget_packed_*()now return aniterator_rangeinstead 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 fromfirstandsecondtobegin()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_readerhas a new methodget_view()returning an object of the newprotozero::data_viewclass. Thedata_viewonly has minimal functionality, but what it has is compatible to thestd::string_viewclass which will be coming in C++17. The view autoconverts to astd::stringif needed. Useget_view()instead ofget_data()giving you a more intuitive interface (calldata()andsize()on the view instead of usingfirstandsecondon thestd::pairreturned byget_data()).You can set the macro
PROTOZERO_USE_VIEW(before includingtypes.hpp) to the name of any class that behaves likeprotozero::data_viewanddata_viewwill be an alias to that class instead of the implementation from protozero. This way you can use the C++17string_viewor a similar class if it is already available on your system.