Package org.apache.thrift
Class TSerializer
- java.lang.Object
-
- org.apache.thrift.TSerializer
-
public class TSerializer extends java.lang.ObjectGeneric utility for easily serializing objects into a byte array or Java String.
-
-
Constructor Summary
Constructors Constructor Description TSerializer()Create a new TSerializer that uses the TBinaryProtocol by default.TSerializer(TProtocolFactory protocolFactory)Create a new TSerializer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description byte[]serialize(TBase base)Serialize the Thrift object into a byte array.java.lang.StringtoString(TBase base)Serialize the Thrift object into a Java string, using the default JVM charset encoding.
-
-
-
Constructor Detail
-
TSerializer
public TSerializer() throws TTransportExceptionCreate a new TSerializer that uses the TBinaryProtocol by default.- Throws:
TTransportException- if there an error initializing the underlying transport.
-
TSerializer
public TSerializer(TProtocolFactory protocolFactory) throws TTransportException
Create a new TSerializer. It will use the TProtocol specified by the factory that is passed in.- Parameters:
protocolFactory- Factory to create a protocol- Throws:
TTransportException- if there an error initializing the underlying transport.
-
-
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- if an error is encountered during serialization.
-
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- if an error is encountered during serialization.
-
-