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

时间:2014-10-23 17:06:04

标签: serialization boost corba ace-tao

我尝试序列化数据结构,通过网络发送数据并在另一端反序列化。如果双方都被编译为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;

1 个答案:

答案 0 :(得分:0)

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