You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by "zd.wbh" <zd...@163.com> on 2010/07/23 09:13:16 UTC

回复: C++ serialization/deserialization examples

Raghava, you can use TMemoryBuffer, something like:

 shared_ptr<TMemoryBuffer> strBuffer(new TMemoryBuffer());
 shared_ptr<TBinaryProtocol> binaryProtcol(new TBinaryProtocol(strBuffer));
 strBuffer->resetBuffer((uint8_t*) raw, *lengthPtr);
 obj.read(binaryProtcol.get());

serialization is the oppsite, use write method.


---------------------------------------------------------
一键发送本地文件,请用网易闪电邮(fm.163.com)!



发件人: Raghava Mutharaju <m....@gmail.com>
发送时间: 2010-07-23 15:05
主 题: C++ serialization/deserialization examples
收件人: thrift-user@incubator.apache.org



Hello all, 

I am using Thrift to share data between applications written in 2 different 
languages (java & c++). I have used TSerializer and TDeserializer for java 
(Binary Protocol) to serialize a message into a file. I haven't found its 
equivalent classes in C++. Can someone suggest how to serialize/deserialize 
using C++. Some steps or small code snippet would be useful. 

Thank you. 

Regards. 
Raghava. 

Re: C++ serialization/deserialization examples

Posted by Raghava Mutharaju <m....@gmail.com>.
Thank you for the reply :)

If the file (serialized the byte array to a file) size is large, should I
read each record and place it in the buffer? Can I use the TFileTransport
class to read directly from a file as follows?

string empfile = "../EmpInfo.dat";
shared_ptr<TFileTransport> filetrans(new TFileTransport(empfile));
TBinaryProtocol* binary_protocol = new TBinaryProtocol(filetrans);
EmployeeInfo* empinfo = new EmployeeInfo();
empinfo->read(binary_protocol);

Thank you again.

Regards,
Raghava.

On Fri, Jul 23, 2010 at 3:13 AM, zd.wbh <zd...@163.com> wrote:

> Raghava, you can use TMemoryBuffer, something like:
>
>  shared_ptr<TMemoryBuffer> strBuffer(new TMemoryBuffer());
>  shared_ptr<TBinaryProtocol> binaryProtcol(new TBinaryProtocol(strBuffer));
>  strBuffer->resetBuffer((uint8_t*) raw, *lengthPtr);
>  obj.read(binaryProtcol.get());
>
> serialization is the oppsite, use write method.
>
>
> ---------------------------------------------------------
> 一键发送本地文件,请用网易闪电邮(fm.163.com)!
>
>
>
> 发件人: Raghava Mutharaju <m....@gmail.com>
> 发送时间: 2010-07-23 15:05
> 主 题: C++ serialization/deserialization examples
> 收件人: thrift-user@incubator.apache.org
>
>
>
> Hello all,
>
> I am using Thrift to share data between applications written in 2 different
> languages (java & c++). I have used TSerializer and TDeserializer for java
> (Binary Protocol) to serialize a message into a file. I haven't found its
> equivalent classes in C++. Can someone suggest how to serialize/deserialize
> using C++. Some steps or small code snippet would be useful.
>
> Thank you.
>
> Regards.
> Raghava.
>