简体   繁体   English

如何在CORBA(ACE / TAO)中使用Boost序列化

[英]How to use boost serialization with CORBA (ACE/TAO)

I'm trying to serialize a data struct, send it over the network and deserialize it on the other side. 我正在尝试序列化数据结构,通过网络发送它,然后在另一端反序列化它。 Works perfectly fine if both sides are consistently compiled as x64 or x86 but it won't work between the two, even if I only serialize a single boolean. 如果双方被一致地编译为x64或x86,则工作得很好,但是即使我只序列化一个布尔值,也无法在两者之间工作。

Serialization code: 序列化代码:

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();

Deserialization code: 反序列化代码:

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;

据我所知,未经测试,这是由各种体系结构上不同的Boost版本引起的,另请参见Boost序列化:存档“不受支持的版本”异常

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

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