Package org.apache.thrift
Class TSerializer
java.lang.Object
org.apache.thrift.TSerializer
Generic utility for easily serializing objects into a byte array or Java String.
-
Constructor Summary
ConstructorDescriptionCreate a new TSerializer that uses the TBinaryProtocol by default.TSerializer
(TProtocolFactory protocolFactory) Create a new TSerializer. -
Method Summary
-
Constructor Details
-
TSerializer
Create a new TSerializer that uses the TBinaryProtocol by default.- Throws:
TTransportException
- if there an error initializing the underlying transport.
-
TSerializer
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 is an error initializing the underlying transport.
-
-
Method Details
-
serialize
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
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.
-