简体   繁体   English

向量(反)序列化与Boost.serialization的向后兼容性

[英]Backwards compatibility of vector (de)serialization with Boost.serialization

Sorry for cross posting. 抱歉交叉发布。 After posting to the mailing list boost-users and one week without any responses I am inclined to post the issue at stackoverflow. 发布到邮件列表boost-users后一周没有任何回复我倾向于在stackoverflow发布问题。 Original Post, slightly re-edited: 原帖,稍加重新编辑:

Hi list, 嗨列表,

I am migrating from Boost v1.35 to a new version. 我正在从Boost v1.35迁移到新版本。 I have, however, some legacy serialized strings that I want to be readable by the new version. 但是,我有一些遗留的序列化字符串,我想让新版本可读。

After some testing I found that apparently the newer version (in this case 1.40 but also later) cannot correctly deserialize std::vector instances from 1.35 generated strings. 经过一些测试后,我发现显然较新的版本(在本例中为1.40但后来)无法从1.35生成的字符串中正确反序列化std :: vector实例。 Can anyone give my a pointer as to what may be the problem here? 任何人都可以指出我的问题可能是什么问题吗?

Thanks a lot! 非常感谢!

Ewald 埃瓦尔德

==Details== == ==详细

I use text archives, and gcc version 4.4.1 (Ubuntu 4.4.1-4ubuntu9) 我使用文本存档和gcc版本4.4.1(Ubuntu 4.4.1-4ubuntu9)

The test vector is a structure with 2 items, the long integers 1 and 2. 测试向量是具有2个项的结构,长整数1和2。

Archive string for respective lib versions: 各个lib版本的归档字符串:

1.35: archive: 22 serialization::archive 4 2 1 2 1.35: archive: 22 serialization::archive 4 2 1 2
1.40: archive: 22 serialization::archive 5 2 0 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);
}

Result when executing with lib v1.40: testvector contains two elements, {2, 2} -- instead of {1, 2} 使用lib v1.40执行时的结果:testvector包含两个元素{2, 2} - 而不是{1, 2}

Note: s11n and de-s11n with the same lib version works perfect. 注意:具有相同lib版本的s11n和de-s11n工作正常。

There is a file boost/serialization/vector_135.hpp at least in Boost 1.48 with this comment: 至少在Boost 1.48中有一个文件boost/serialization/vector_135.hpp ,评论如下:

vector_135.hpp: serialization for stl vector templates for compatibility with release 1.35, which had a bug vector_135.hpp:用于与版本1.35兼容的stl矢量模板的序列化,它有一个bug

I presume you could include it instead of boost/serialization/vector.hpp . 我认为你可以包含它而不是boost/serialization/vector.hpp The downside, of course, is that newly serialized vectors will be in that buggy format too in that case. 当然,缺点是在这种情况下,新的序列化载体也会处于那种错误的格式。

EDIT: 编辑:

Brief study of the code suggests if the file is used, load() will be able to deserialize both formats, but save() will serialize in the new format. 对代码的简要研究表明,如果使用该文件, load()将能够反序列化两种格式,但save()将以新格式序列化。 So, the only downside seems to be ugly include name then. 因此,唯一的缺点似乎是丑陋包括名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM