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

276 Views Asked by At

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;
1

There are 1 best solutions below

1
On BEST ANSWER

As far as I can tell without testing this is caused by different boost versions on the various architectures, see also Boost serialization: archive "unsupported version" exception