是否Boost.Serialization不同序列在不同平台上? [英] Does Boost.Serialization serialize differently on different platforms?

查看:181
本文介绍了是否Boost.Serialization不同序列在不同平台上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用Boost.Serialization序列化的std ::地图。在code看起来像这样

I use Boost.Serialization to serialize a std::map. The code looks like this

void Dictionary::serialize(std::string & buffer)
{
  try {
    std::stringstream ss;
    boost::archive::binary_oarchive archive(ss);
    archive << dict_; 
    buffer = ss.str();
  } catch (const std::exception & ex) {
    throw DictionaryException(ex.what());
  }
}

void Dictionary::deserialize(const char * const data, int length)
{
  try {
    namespace io = boost::iostreams;
    io::array_source source(data, length);
    io::stream<io::array_source> in(source);
    boost::archive::binary_iarchive archive(in);
    archive >> dict_;
  } catch (const std::exception & ex) {
    throw DictionaryException(ex.what());
  }
}

我编译和测试code在Mac雪豹和在Ubuntu 10.04清醒。有两个系统提升1.40。在Mac上我建了code自己。在Ubuntu的盒子我通过资质得到的二进制文件。

I compiled and tested the code on a Mac Snow Leopard and on Ubuntu Lucid 10.04. There is Boost 1.40 on both systems. On the Mac I built the code myself. On the Ubuntu box I got the binaries via aptitude.

问题:当我序列化Mac上的地图,我不能反序列化的Ubuntu的框。我得到的无效的签名异常,如果我尝试。

Problem: When I serialize the map on the Mac I can't deserialize it on the Ubuntu box. I get an invalid signature exception if I try.

推荐答案

请尝试使用 text_iarchive text_oarchive 代替二进制档案。从<一个href=\"http://www.boost.org/doc/libs/1_44_0/libs/serialization/doc/tutorial.html\">documentation

try using a text_iarchive and text_oarchive instead of binary archives. From the documentation

在本教程中,我们使用了
  特别是存档类 -
  text_oarchive保存和
  text_iarchive加载。文本
  归档数据呈现为文本,并
  跨平台移植。此外
  文字档​​案,图书馆包括
  存档类本机二进制数据
  和xml格式的数据。接口
  所有存档类都是相同的。
  一旦序列被定义
  一类,这个类可以
  序列化到任何类型的档案。

In this tutorial, we have used a particular archive class - text_oarchive for saving and text_iarchive for loading. text archives render data as text and are portable across platforms. In addition to text archives, the library includes archive class for native binary data and xml formatted data. Interfaces to all archive classes are all identical. Once serialization has been defined for a class, that class can be serialized to any type of archive.

这篇关于是否Boost.Serialization不同序列在不同平台上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆