Serialization with Apache Thrift on Objective-C

It is possible to use Apache Thrift only as serializer and deserializer on Objective-C. To do it, you should use:

  • TMemoryBuffer as transport.
  • TBinaryProtocol as protocol.

Serializer example:

// SimpleMessage is a Thrift message
SimpleMessage *message = [[SimpleMessage alloc] init];
...

TMemoryBuffer *tBuffer = [[TMemoryBuffer alloc] init];
TBinaryProtocol *tProtocol = [[TBinaryProtocol alloc] initWithTransport:tBuffer];

[message write:tProtocol];

NSData *data = [tBuffer getBuffer];

Note that, TMemoryBuffer doesn’t support framing. You should encode frame size yourself, if you need it.

Advertisements

One thought on “Serialization with Apache Thrift on Objective-C

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s