【问题标题】:How to use boost serialization with CORBA (ACE/TAO)如何在 CORBA (ACE/TAO) 中使用 boost 序列化
【发布时间】:2023-03-11 14:58:01
【问题描述】:

我正在尝试序列化一个数据结构,通过网络发送它并在另一端反序列化它。如果双方始终编译为 x64 或 x86,则工作得非常好,但它不会在两者之间工作,即使我只序列化一个布尔值。

序列化代码:

Myclass myc;
std::stringstream ss;
boost::archive::text_oarchive oa(ss);
oa << myc;

// get stringstream's length
ss.seekg(0, ios::end);
int len = ss.tellg();
ss.seekg(0, ios::beg);

// allocate CORBA type and copy the stringstream buffer over
const std::string copy = ss.str();  // copy since str() only generates a temporary  object
const char* buffer = copy.c_str();

// ByteSequence is a sequence of octets which again is defined as a raw, platform-independent byte type by the CORBA standard
IDL::ByteSequence_var byteSeq(new IDL::ByteSequence());
byteSeq->length(len);
memcpy(byteSeq->get_buffer(), buffer, len);

return byteSeq._retn();

反序列化代码:

IDL::ByteSequence_var byteSeq;
byteSeq = _remoteObject->getMyClass();

// copy CORBA input sequence to local char buffer
int seqLen = byteSeq->length();
std::unique_ptr<char[]> buffer(new char[seqLen]);
memcpy(buffer.get(), byteSeq->get_buffer(), seqLen);

// put buffer into a stringstream
std::stringstream ss;
std::stringbuf* ssbuf = ss.rdbuf();
ssbuf->sputn(buffer.get(), seqLen);

// deserialize from stringstream
// throws exception 'Unsupported version' between x86 and x64
boost::archive::text_iarchive ia(ss);

MyClass result;
ia >> result;

【问题讨论】:

    标签: serialization boost corba ace-tao


    【解决方案1】:

    据我所知,未经测试,这是由各种架构上的不同 boost 版本引起的,另请参阅 Boost serialization: archive "unsupported version" exception

    【讨论】:

    • 是的,这也是我在此期间自己发现的问题。一开始我并没有真正考虑到这一点,因为我没想到在增加一个版本号(一侧是 1.55,另一侧是 1.56)之后,boost 就不能再读取自己的档案了。
    猜你喜欢
    • 1970-01-01
    • 2011-03-02
    • 1970-01-01
    • 1970-01-01
    • 2014-08-08
    • 1970-01-01
    • 2018-06-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多