org.apache.thrift
Class TSerializer

java.lang.Object
  extended by org.apache.thrift.TSerializer

public class TSerializer
extends java.lang.Object

Generic utility for easily serializing objects into a byte array or Java String.


Constructor Summary
TSerializer()
          Create a new TSerializer that uses the TBinaryProtocol by default.
TSerializer(TProtocolFactory protocolFactory)
          Create a new TSerializer.
 
Method Summary
 byte[] serialize(TBase base)
          Serialize the Thrift object into a byte array.
 java.lang.String toString(TBase base)
          Serialize the Thrift object into a Java string, using the default JVM charset encoding.
 java.lang.String toString(TBase base, java.lang.String charset)
          Serialize the Thrift object into a Java string, using a specified character set for encoding.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TSerializer

public TSerializer()
Create a new TSerializer that uses the TBinaryProtocol by default.


TSerializer

public TSerializer(TProtocolFactory protocolFactory)
Create a new TSerializer. It will use the TProtocol specified by the factory that is passed in.

Parameters:
protocolFactory - Factory to create a protocol
Method Detail

serialize

public byte[] serialize(TBase base)
                 throws TException
Serialize the Thrift object into a byte array. The process is simple, just clear the byte array output, write the object into it, and grab the raw bytes.

Parameters:
base - The object to serialize
Returns:
Serialized object in byte[] format
Throws:
TException

toString

public java.lang.String toString(TBase base,
                                 java.lang.String charset)
                          throws TException
Serialize the Thrift object into a Java string, using a specified character set for encoding.

Parameters:
base - The object to serialize
charset - Valid JVM charset
Returns:
Serialized object as a String
Throws:
TException

toString

public java.lang.String toString(TBase base)
                          throws TException
Serialize the Thrift object into a Java string, using the default JVM charset encoding.

Parameters:
base - The object to serialize
Returns:
Serialized object as a String
Throws:
TException