nikk
nikk

Reputation: 2877

What serialization framework does Apache Thrift use?

What serialization framework does Facebook's Apache Thrift use in a Java environment? Java built-in serialization or Kryo, or something else?

EDIT:

I see that Thrift has a class called TSerializer which seems to implement TBase which implements java.io.serialializable. I may not get the order right.

Upvotes: 1

Views: 1209

Answers (1)

JensG
JensG

Reputation: 13411

Thrift uses its own mechanisms, in Thrift-speak these are called Transport. This is the case across all languages to ensure interoperatbility. One of these Transports is the TFileTransport, and another, popular one is TSocket.

If you look at the code, you will find that thrird-party libraries are in general used very sparsely, for several reasons. Available built-in mechanisms are also not used, because these are typically a language specific thing and thus not portable across languages.

Last not least one of the key features of Thrift is its openness. Anyone can easily write his or her own Transport or Protocol implementations and plug them into the system. Some of them can be found in the /contrib folder.

Let's say the target environment was Java. What serialization method would it implement -- Java's native serialization? I see that Thrift has a class called TSerializer [...]

You just instantiate the TSerializer and use it. If you have special requirements regarding the protocol, use the alternative CTOR to e.g. pass amn instance of TJSONProtocolFactory or whatever else you need. By default the serializer assumes TBinaryProtocol.

Then you simply call

TSerializer  serializer = new TSerializer();
TBytes data = serializer.serialize( myThriftObject);

and do whatever you want with data.

Upvotes: 1

Related Questions