Hi,
I'm having a lot of trouble serializing data. What am I doing wrong?
std::string serialize(ContactsList& obj, std::string filename) {
shared_ptr<TMemoryBuffer> transportOut(new TMemoryBuffer());
shared_ptr<TBinaryProtocol> protocolOut(new TBinaryProtocol(transportOut));
obj.write(binaryProtcol);
std::string serialized_string = transportOut->getBufferAsString();
return serialized_string;
}
This is the method I call from another method. I expect to get back a
serialized binary string which I can write out to disk. Inside this serialize
method, I create a TMemory buffer, then I wrap it in a TBinaryProtocol, and
then the object's write method, which will write itself into the memory buffer.
Then, I get that buffer back as a string. I'd then write out the serialized
string to disk.
I get this error:
error: no matching function for call to
'addressbook::ContactsList::write(boost::shared_ptr<apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>
>&)
As well as this note:
note: no known conversion for argument 1 from
'boost::shared_ptr<apache::thrift::protocol::TBinaryProtocolT<apache::thrift::transport::TTransport>
>' to 'apache::thrift::protocol::TProtocol*
I'm using Apache Thrift 1.0-dev, C++ 98 if these things make a difference.
Am I understanding everything correctly (probably not cuz it's not working)?
What's the correct way to serialize an object? Pleeeeeaase edify me. Here is
the stackoverflow link:
http://stackoverflow.com/questions/19672155/apache-thrift-serialization-in-c
Thanks,
Jack