简体   繁体   中英

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.

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序列化:存档“不受支持的版本”异常

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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