Backward compatible vector (de) serialization with Boost.serialization

Sorry for cross-registration. After you sent to the user mailing list and one week without any answers, I tend to post this issue on stackoverflow. Original post, slightly edited:

Hi,

I am upgrading from Boost v1.35 to the new version. However, I have some deprecated serialized strings that I want to read in the new version.

After some testing, I found that, apparently, a newer version (in this case 1.40, but also later) could not correctly deserialize std :: vector instances from 1.35 generated lines. Can someone give my pointer as to what might be the problem here?

Thanks a lot!

Ewald

== Details ==

I use text archives and gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9)

A test vector is a structure with two elements, long integers 1 and 2.

Archive line for the corresponding lib versions:

1.35: archive: 22 serialization::archive 4 2 1 2
1.40: archive: 22 serialization::archive 5 2 0 1 2

Now:

 // includes #include <boost/serialization/vector.hpp> #include <boost/archive/text_iarchive.hpp> #include <boost/archive/text_oarchive.hpp> std::vector<long> testvector; std::string val = "22 serialization::archive 4 2 1 2"; // v1.35 archive { std::stringstream ss(std::stringstream::in | std::stringstream::out); ss << val << std::endl; boost::archive::text_iarchive ia(ss); ia >> BOOST_SERIALIZATION_NVP(testvector); } 

The result when executed with lib v1.40: testvector contains two elements, {2, 2} - instead of {1, 2}

Note: s11n and de-s11n with the same lib version work fine.

+6
source share
1 answer

There is a boost/serialization/vector_135.hpp file, at least in Boost 1.48 with this comment:

vector_135.hpp: serialization for stl vector templates for compatibility with release 1.35, which had an error

I assume you can enable it instead of boost/serialization/vector.hpp . The disadvantage, of course, is that the new serialized vectors will also be in this wrong format.

EDIT:

A brief description of the code suggests that if the file is used, load() will be able to deserialize both formats, but save() will be serialized in the new format. So the only flaw seems to be ugly to include a name.

+1
source

Source: https://habr.com/ru/post/902666/


All Articles