Package org.apache.thrift
Class TDeserializer
java.lang.Object
org.apache.thrift.TDeserializer
Generic utility for easily deserializing objects from a byte array or Java String.
-
Constructor Summary
ConstructorDescriptionCreate a new TDeserializer that uses the TBinaryProtocol by default.TDeserializer
(Class<? extends TBase> thriftClass, Collection<String> fieldNames, ThriftFieldValueProcessor processor, TProtocolFactory protocolFactory) Construct a new TDeserializer that supports partial deserialization that outputs instances of type controlled by the givenprocessor
.TDeserializer
(Class<? extends TBase> thriftClass, Collection<String> fieldNames, TProtocolFactory protocolFactory) Construct a new TDeserializer that supports partial deserialization that outputsTBase
instances.TDeserializer
(TProtocolFactory protocolFactory) Create a new TDeserializer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
deserialize
(TBase base, byte[] bytes) Deserialize the Thrift object from a byte array.void
deserialize
(TBase base, byte[] bytes, int offset, int length) Deserialize the Thrift object from a byte array.void
deserialize
(TBase base, String data, String charset) Deserialize the Thrift object from a Java string, using a specified character set for decoding.void
fromString
(TBase base, String data) Deserialize the Thrift object from a Java string, using the default JVM charset encoding.Gets the metadata used for partial deserialization.void
partialDeserialize
(TBase tb, byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) Deserialize only a single Thrift object (addressed by recursively using field id) from a byte record.partialDeserializeBool
(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) Deserialize only a boolean field (addressed by recursively using field id) from a byte record.partialDeserializeByte
(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) Deserialize only a byte field (addressed by recursively using field id) from a byte record.partialDeserializeByteArray
(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) Deserialize only a binary field (addressed by recursively using field id) from a byte record.partialDeserializeDouble
(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) Deserialize only a double field (addressed by recursively using field id) from a byte record.partialDeserializeI16
(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) Deserialize only an i16 field (addressed by recursively using field id) from a byte record.partialDeserializeI32
(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) Deserialize only an i32 field (addressed by recursively using field id) from a byte record.partialDeserializeI64
(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) Deserialize only an i64 field (addressed by recursively using field id) from a byte record.partialDeserializeObject
(byte[] bytes) Partially deserializes the given serialized blob.partialDeserializeObject
(byte[] bytes, int offset, int length) Partially deserializes the given serialized blob.partialDeserializeSetFieldIdInUnion
(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) Deserialize only the id of the field set in a TUnion (addressed by recursively using field id) from a byte record.partialDeserializeString
(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) Deserialize only a string field (addressed by recursively using field id) from a byte record.partialDeserializeThriftObject
(TBase base, byte[] bytes, int offset, int length) Partially deserializes the given serialized blob into the givenTBase
instance.
-
Constructor Details
-
TDeserializer
Create a new TDeserializer that uses the TBinaryProtocol by default.- Throws:
TTransportException
- if there an error initializing the underlying transport.
-
TDeserializer
Create a new TDeserializer. 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.
-
TDeserializer
public TDeserializer(Class<? extends TBase> thriftClass, Collection<String> fieldNames, ThriftFieldValueProcessor processor, TProtocolFactory protocolFactory) throws TTransportException Construct a new TDeserializer that supports partial deserialization that outputs instances of type controlled by the givenprocessor
.- Parameters:
thriftClass
- a TBase derived class.fieldNames
- list of fields to deserialize.processor
- the Processor that handles deserialized field values.protocolFactory
- the Factory to create a protocol.- Throws:
TTransportException
-
TDeserializer
public TDeserializer(Class<? extends TBase> thriftClass, Collection<String> fieldNames, TProtocolFactory protocolFactory) throws TTransportException Construct a new TDeserializer that supports partial deserialization that outputsTBase
instances.- Parameters:
thriftClass
- a TBase derived class.fieldNames
- list of fields to deserialize.protocolFactory
- the Factory to create a protocol.- Throws:
TTransportException
-
-
Method Details
-
getMetadata
Gets the metadata used for partial deserialization.- Returns:
- the metadata used for partial deserialization.
-
deserialize
Deserialize the Thrift object from a byte array.- Parameters:
base
- The object to read intobytes
- The array to read from- Throws:
TException
- if an error is encountered during deserialization.
-
deserialize
Deserialize the Thrift object from a byte array.- Parameters:
base
- The object to read intobytes
- The array to read fromoffset
- The offset intobytes
length
- The length to read frombytes
- Throws:
TException
- if an error is encountered during deserialization.
-
deserialize
Deserialize the Thrift object from a Java string, using a specified character set for decoding.- Parameters:
base
- The object to read intodata
- The string to read fromcharset
- Valid JVM charset- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserialize
public void partialDeserialize(TBase tb, byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException Deserialize only a single Thrift object (addressed by recursively using field id) from a byte record.- Parameters:
tb
- The object to read intobytes
- The serialized object to read fromfieldIdPathFirst
- First of the FieldId's that define a path tbfieldIdPathRest
- The rest FieldId's that define a path tb- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserializeBool
public Boolean partialDeserializeBool(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException Deserialize only a boolean field (addressed by recursively using field id) from a byte record.- Parameters:
bytes
- The serialized object to read fromfieldIdPathFirst
- First of the FieldId's that define a path to a boolean fieldfieldIdPathRest
- The rest FieldId's that define a path to a boolean field- Returns:
- the deserialized value.
- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserializeByte
public Byte partialDeserializeByte(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException Deserialize only a byte field (addressed by recursively using field id) from a byte record.- Parameters:
bytes
- The serialized object to read fromfieldIdPathFirst
- First of the FieldId's that define a path to a byte fieldfieldIdPathRest
- The rest FieldId's that define a path to a byte field- Returns:
- the deserialized value.
- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserializeDouble
public Double partialDeserializeDouble(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException Deserialize only a double field (addressed by recursively using field id) from a byte record.- Parameters:
bytes
- The serialized object to read fromfieldIdPathFirst
- First of the FieldId's that define a path to a double fieldfieldIdPathRest
- The rest FieldId's that define a path to a double field- Returns:
- the deserialized value.
- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserializeI16
public Short partialDeserializeI16(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException Deserialize only an i16 field (addressed by recursively using field id) from a byte record.- Parameters:
bytes
- The serialized object to read fromfieldIdPathFirst
- First of the FieldId's that define a path to an i16 fieldfieldIdPathRest
- The rest FieldId's that define a path to an i16 field- Returns:
- the deserialized value.
- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserializeI32
public Integer partialDeserializeI32(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException Deserialize only an i32 field (addressed by recursively using field id) from a byte record.- Parameters:
bytes
- The serialized object to read fromfieldIdPathFirst
- First of the FieldId's that define a path to an i32 fieldfieldIdPathRest
- The rest FieldId's that define a path to an i32 field- Returns:
- the deserialized value.
- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserializeI64
public Long partialDeserializeI64(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException Deserialize only an i64 field (addressed by recursively using field id) from a byte record.- Parameters:
bytes
- The serialized object to read fromfieldIdPathFirst
- First of the FieldId's that define a path to an i64 fieldfieldIdPathRest
- The rest FieldId's that define a path to an i64 field- Returns:
- the deserialized value.
- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserializeString
public String partialDeserializeString(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException Deserialize only a string field (addressed by recursively using field id) from a byte record.- Parameters:
bytes
- The serialized object to read fromfieldIdPathFirst
- First of the FieldId's that define a path to a string fieldfieldIdPathRest
- The rest FieldId's that define a path to a string field- Returns:
- the deserialized value.
- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserializeByteArray
public ByteBuffer partialDeserializeByteArray(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException Deserialize only a binary field (addressed by recursively using field id) from a byte record.- Parameters:
bytes
- The serialized object to read fromfieldIdPathFirst
- First of the FieldId's that define a path to a binary fieldfieldIdPathRest
- The rest FieldId's that define a path to a binary field- Returns:
- the deserialized value.
- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserializeSetFieldIdInUnion
public Short partialDeserializeSetFieldIdInUnion(byte[] bytes, TFieldIdEnum fieldIdPathFirst, TFieldIdEnum... fieldIdPathRest) throws TException Deserialize only the id of the field set in a TUnion (addressed by recursively using field id) from a byte record.- Parameters:
bytes
- The serialized object to read fromfieldIdPathFirst
- First of the FieldId's that define a path to a TUnionfieldIdPathRest
- The rest FieldId's that define a path to a TUnion- Returns:
- the deserialized value.
- Throws:
TException
- if an error is encountered during deserialization.
-
fromString
Deserialize the Thrift object from a Java string, using the default JVM charset encoding.- Parameters:
base
- The object to read intodata
- The string to read from- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserializeObject
Partially deserializes the given serialized blob.- Parameters:
bytes
- the serialized blob.- Returns:
- deserialized instance.
- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserializeThriftObject
public Object partialDeserializeThriftObject(TBase base, byte[] bytes, int offset, int length) throws TException Partially deserializes the given serialized blob into the givenTBase
instance.- Parameters:
base
- the instance into which the given blob is deserialized.bytes
- the serialized blob.offset
- the blob is read starting at this offset.length
- the size of blob read (in number of bytes).- Returns:
- deserialized instance.
- Throws:
TException
- if an error is encountered during deserialization.
-
partialDeserializeObject
Partially deserializes the given serialized blob.- Parameters:
bytes
- the serialized blob.offset
- the blob is read starting at this offset.length
- the size of blob read (in number of bytes).- Returns:
- deserialized instance.
- Throws:
TException
- if an error is encountered during deserialization.
-