简体   繁体   English

Boost序列化在32位和64位机器之间不起作用。 还有其他任何序列化/压缩库吗?

[英]Boost serialization does not work between 32bit and 64bit machine. Any other serialization / compression library?

I am trying to use the boost library to serialize on 64bit machine and de-serialize on 32bit machine. 我正在尝试使用boost库在64位机器上进行序列化并在32位机器上进行反序列化。 However, it seems it does not work. 但是,它似乎不起作用。 (I use 1.57.0). (我用1.57.0)。

If I run the following code 如果我运行以下代码

boost::asio::streambuf buf;
std::ostream os(&buf);
boost::archive::binary_oarchive oa(os);
printf("Buffer size %d\n",(int)buf.size());

The output of 32bit machine is 37 and the output of 64bit machine is 41 . 32位机器的输出是37位和64位机的输出为41。

Is there any other good serialize library I can Use? 我可以使用其他任何好的序列化库吗? How about cereal ? 麦片怎么样?

It's great if the library can do compression as well (zlib/gzip etc.). 如果库也可以进行压缩(zlib / gzip等),那就太棒了。

It does work. 它确实有效。 It just doesn't create compatible archives. 它只是不创建兼容的档案。 If you want that you should look at the archive implementation that EOS made: 如果您需要,您应该查看EOS所做的存档实现:

You can drop-in replace Boost's binary_[io]archive with it. 您可以直接替换Boost的binary_ [io]存档。 No need to change anything else. 无需改变任何其他内容。


PS. PS。 Of course, spell out your types in an architecture-independent way too, of course. 当然,也可以用与架构无关的方式拼出你的类型。 So uint32_t , not ``size_t` 所以uint32_t ,而不是``size_t`

The binary archives created by boost::serialization will not work if you change the architecture of the machine. 如果更改机器的体系结构,boost :: serialization创建的二进制存档将不起作用。 The text archives are a good option in this scenario. 在这种情况下,文本存档是一个很好的选择。 Boost::archive::text_oarchive and boost::archive::text_iarchive can be used the exact same way but are safe across architectures and platforms. Boost :: archive :: text_oarchive和boost :: archive :: text_iarchive可以使用完全相同的方式,但在架构和平台之间是安全的。 The data is written in an ascii format instead of a binary format so there are trade offs there that will need to be addressed for your purpose. 数据以ascii格式而不是二进制格式写入,因此需要在那里进行权衡以达到您的目的。

为了这个目的,我建议使用'cereal'来提供JSON / XML序列化。

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

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