thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Abernethy <randy.aberne...@gmail.com>
Subject Re: serializing binary data in C++
Date Wed, 30 Oct 2013 02:34:20 GMT
Hello Jack,

These two lines of code are the issue:

    shared_ptr<TBinaryProtocol> protocolOut(new
TBinaryProtocol(transportOut));
    obj.write(binaryProtcol);


1. I take it that the obj.write(binaryProtcol); is meant to be: obj.write(
protocolOut);

2. The problem with the write is that the Thrift generated write function
wants a TProtocol *
If you change your code to the following I think you will have success:

    obj.write(protocolOut.get());

Best,
Randy


On Tue, Oct 29, 2013 at 6:23 PM, Chan, Jack <jack.chan@flukenetworks.com>wrote:

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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message