You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by Apache Wiki <wi...@apache.org> on 2008/07/15 18:25:50 UTC

[Thrift Wiki] Update of "ThriftUsageJava" by StuartSierra

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Thrift Wiki" for change notification.

The following page has been changed by StuartSierra:
http://wiki.apache.org/thrift/ThriftUsageJava

The comment on the change is:
Created page with some examples

New page:
Assuming you're using the definitions in "tutorial.thrift":

== Importing the Classes ==

You may not need all of these.

{{{
import com.facebook.thrift.TBase;
import com.facebook.thrift.TException;
import com.facebook.thrift.TSerializer;
import com.facebook.thrift.protocol.TBinaryProtocol;
import com.facebook.thrift.protocol.TProtocol;
import com.facebook.thrift.protocol.TProtocolFactory;
import com.facebook.thrift.protocol.TSimpleJSONProtocol;
import com.facebook.thrift.transport.TIOStreamTransport;
import com.facebook.thrift.transport.TTransport;

import tutorial.Work;
import tutorial.Operation;
import tutorial.Constants;
}}}

== Creating Objects, Using Constants ==

{{{
Work work = new Work();
work.num1 = 7;
work.num2 = 9;
work.op = Operation.ADD;
}}}

== Serializing to a Byte Array ==

{{{
TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
byte[] bytes = serializer.serialize(work);
}}}