Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thrift: Is it possible to do only serialization with C++ Thrift library?

With C++ Apache Thrift library, is it possible to use only Serialization/Deserialization and not use RPC services?

As I understand from this page, it is possible to do with Java library. However, I could not find the similar classes for C++ library.

like image 563
Lazylabs Avatar asked Sep 08 '12 07:09

Lazylabs


People also ask

When should I use Apache Thrift?

Apache Thrift allows you to define data types and service interfaces in a simple definition file. Taking that file as input, the compiler generates code to be used to easily build RPC clients and servers that communicate seamlessly across programming languages.

Is Apache Thrift an RPC?

Apache Thrift is a set of code-generation tools that allows developers to build RPC clients and servers by just defining the data types and service interfaces in a simple definition file.

What is Thrift format?

Thrift is an interface definition language and binary communication protocol used for defining and creating services for numerous programming languages. It was developed at Facebook for "scalable cross-language services development" and as of 2020 is an open source project in the Apache Software Foundation.


2 Answers

Yes it is possible. Thrift lacks documentation about this subject. Well, about anything really.

Here i found this:

http://mail-archives.apache.org/mod_mbox/thrift-user/201010.mbox/%[email protected]%3E

i personally use boost::serialization if there is no need to transfer data over network. Much clear syntax and supports JSON, XML and binary output/input.

like image 190
mikbal Avatar answered Nov 10 '22 23:11

mikbal


If you simply want to serialize into bytes (without having to write to a file), you can use TMemoryBuffer.

boost::shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer());
boost::shared_ptr<TBinaryProtocol> binaryProtcol(new TBinaryProtocol(buffer));

obj->write(binaryProtcol.get());
obj->read((binaryProtcol.get()));
like image 40
jeffreyveon Avatar answered Nov 10 '22 23:11

jeffreyveon