Package org.apache.thrift.protocol
Class TProtocol
- java.lang.Object
-
- org.apache.thrift.protocol.TProtocol
-
- All Implemented Interfaces:
TReadProtocol,TWriteProtocol
- Direct Known Subclasses:
TBinaryProtocol,TCompactProtocol,TJSONProtocol,TProtocolDecorator,TSimpleJSONProtocol
public abstract class TProtocol extends java.lang.Object implements TWriteProtocol, TReadProtocol
Protocol interface definition.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTProtocol.ReadCallback<T,R>static interfaceTProtocol.ReadCollectionCallback<R>static interfaceTProtocol.ReadMapEntryCallback<K,V>static interfaceTProtocol.WriteCallback<T>
-
Field Summary
Fields Modifier and Type Field Description protected byte[]skippedBytesprotected TTransporttrans_Transport
-
Constructor Summary
Constructors Modifier Constructor Description protectedTProtocol(TTransport trans)Constructor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcheckReadBytesAvailable(TList list)protected voidcheckReadBytesAvailable(TMap map)protected voidcheckReadBytesAvailable(TSet set)abstract intgetMinSerializedSize(byte type)Return min serialized size in bytesjava.lang.Class<? extends IScheme>getScheme()Scheme accessorTTransportgetTransport()Transport accessor<T> booleanreadField(TProtocol.ReadCallback<TField,T> callback)read a field by delegating to a callback, handlesbeginandendautomatically, and returns whether thestop signalwas encountered.intreadFieldBeginData()<T extends java.util.List<?>>
TreadList(TProtocol.ReadCallback<TList,T> callback)<T> java.util.List<T>readList(TProtocol.ReadCollectionCallback<T> callback)<T> java.util.List<T>readList(TProtocol.ReadCollectionCallback<T> callback, java.util.function.IntFunction<java.util.List<T>> listCreator)<T extends java.util.Map<?,?>>
TreadMap(TProtocol.ReadCallback<TMap,T> callback)<K,V>
java.util.Map<K,V>readMap(TProtocol.ReadMapEntryCallback<K,V> callback)<K,V>
java.util.Map<K,V>readMap(TProtocol.ReadMapEntryCallback<K,V> callback, java.util.function.IntFunction<java.util.Map<K,V>> mapCreator)<T> TreadMessage(TProtocol.ReadCallback<TMessage,T> callback)<T extends java.util.Set<?>>
TreadSet(TProtocol.ReadCallback<TSet,T> callback)<T> java.util.Set<T>readSet(TProtocol.ReadCollectionCallback<T> callback)<T> java.util.Set<T>readSet(TProtocol.ReadCollectionCallback<T> callback, java.util.function.IntFunction<java.util.Set<T>> setCreator)<T> TreadStruct(TProtocol.ReadCallback<TStruct,T> callback)voidreset()Reset any internal state back to a blank slate.voidskip(byte fieldType)voidskip(byte fieldType, int maxDepth)protected voidskipBinary()protected voidskipBool()The default implementation of all skip() methods calls the corresponding read() method.protected voidskipByte()protected voidskipBytes(int numBytes)protected voidskipDouble()protected voidskipI16()protected voidskipI32()protected voidskipI64()voidwriteField(TField field, TProtocol.WriteCallback<java.lang.Void> callback)<T> voidwriteList(byte elementType, java.util.List<T> list, TProtocol.WriteCallback<T> callback)<K,V>
voidwriteMap(byte keyType, byte valueType, java.util.Map<K,V> map, TProtocol.WriteCallback<java.util.Map.Entry<K,V>> callback)voidwriteMessage(TMessage message, TProtocol.WriteCallback<java.lang.Void> callback)<T> voidwriteSet(byte elementType, java.util.Set<T> set, TProtocol.WriteCallback<T> callback)voidwriteStruct(TStruct struct, TProtocol.WriteCallback<java.lang.Void> callback)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.thrift.protocol.TReadProtocol
readBinary, readBool, readByte, readDouble, readFieldBegin, readFieldEnd, readI16, readI32, readI64, readListBegin, readListEnd, readMapBegin, readMapEnd, readMessageBegin, readMessageEnd, readSetBegin, readSetEnd, readString, readStructBegin, readStructEnd
-
Methods inherited from interface org.apache.thrift.protocol.TWriteProtocol
writeBinary, writeBool, writeByte, writeDouble, writeFieldBegin, writeFieldEnd, writeFieldStop, writeI16, writeI32, writeI64, writeListBegin, writeListEnd, writeMapBegin, writeMapEnd, writeMessageBegin, writeMessageEnd, writeSetBegin, writeSetEnd, writeString, writeStructBegin, writeStructEnd
-
-
-
-
Field Detail
-
trans_
protected TTransport trans_
Transport
-
skippedBytes
protected byte[] skippedBytes
-
-
Constructor Detail
-
TProtocol
protected TProtocol(TTransport trans)
Constructor
-
-
Method Detail
-
getTransport
public TTransport getTransport()
Transport accessor
-
checkReadBytesAvailable
protected void checkReadBytesAvailable(TMap map) throws TException
- Throws:
TException
-
checkReadBytesAvailable
protected void checkReadBytesAvailable(TList list) throws TException
- Throws:
TException
-
checkReadBytesAvailable
protected void checkReadBytesAvailable(TSet set) throws TException
- Throws:
TException
-
getMinSerializedSize
public abstract int getMinSerializedSize(byte type) throws TExceptionReturn min serialized size in bytes- Parameters:
type- Returns the minimum amount of bytes needed to store the smallest possible instance of TType.- Returns:
- min serialized size
- Throws:
TException- when error happens
-
writeSet
public final <T> void writeSet(byte elementType, java.util.Set<T> set, TProtocol.WriteCallback<T> callback) throws TException- Throws:
TException
-
writeList
public final <T> void writeList(byte elementType, java.util.List<T> list, TProtocol.WriteCallback<T> callback) throws TException- Throws:
TException
-
writeMap
public final <K,V> void writeMap(byte keyType, byte valueType, java.util.Map<K,V> map, TProtocol.WriteCallback<java.util.Map.Entry<K,V>> callback) throws TException- Throws:
TException
-
writeField
public final void writeField(TField field, TProtocol.WriteCallback<java.lang.Void> callback) throws TException
- Throws:
TException
-
writeStruct
public final void writeStruct(TStruct struct, TProtocol.WriteCallback<java.lang.Void> callback) throws TException
- Throws:
TException
-
writeMessage
public final void writeMessage(TMessage message, TProtocol.WriteCallback<java.lang.Void> callback) throws TException
- Throws:
TException
-
readMessage
public final <T> T readMessage(TProtocol.ReadCallback<TMessage,T> callback) throws TException
- Type Parameters:
T- result message type- Parameters:
callback- callback for actual reading- Returns:
- the message read
- Throws:
TException- when any sub-operation failed
-
readStruct
public final <T> T readStruct(TProtocol.ReadCallback<TStruct,T> callback) throws TException
- Type Parameters:
T- result struct type- Parameters:
callback- callback for actual reading- Returns:
- the struct read
- Throws:
TException- when any sub-operation failed
-
readField
public final <T> boolean readField(TProtocol.ReadCallback<TField,T> callback) throws java.lang.Exception
read a field by delegating to a callback, handlesbeginandendautomatically, and returns whether thestop signalwas encountered. Because the value is not returned, you (the compiler generated code in most cases) are expected to set the field yourself within the callback.- Type Parameters:
T- result field type- Parameters:
callback- callback for reading a field- Returns:
- true if a stop signal was encountered, false otherwise
- Throws:
java.lang.Exception- when any sub-operation failed
-
readMap
public final <T extends java.util.Map<?,?>> T readMap(TProtocol.ReadCallback<TMap,T> callback) throws TException
- Type Parameters:
T- result map type- Parameters:
callback- callback for reading the map- Returns:
- the map read
- Throws:
TException- when any sub-operation fails
-
readMap
public final <K,V> java.util.Map<K,V> readMap(TProtocol.ReadMapEntryCallback<K,V> callback) throws TException
read aMapof elements by delegating key and value reading to the callback, handlesbeginandendautomatically.- Type Parameters:
K- key typeV- value type- Parameters:
callback- callback for reading keys and values, calls toTProtocol.ReadMapEntryCallback.getKey()andTProtocol.ReadMapEntryCallback.getValue()will be in alternating orders, i.e. k1, v1, k2, v2, .., k_n, v_n- Returns:
- the map read
- Throws:
TException- when any sub-operation fails
-
readMap
public final <K,V> java.util.Map<K,V> readMap(TProtocol.ReadMapEntryCallback<K,V> callback, java.util.function.IntFunction<java.util.Map<K,V>> mapCreator) throws TException
read aMapof elements by delegating key and value reading to the callback, handlesbeginandendautomatically, with a specialized map creator given the size hint.- Type Parameters:
K- key typeV- value type- Parameters:
callback- callback for reading keys and values, calls toTProtocol.ReadMapEntryCallback.getKey()andTProtocol.ReadMapEntryCallback.getValue()will be in alternating orders, i.e. k1, v1, k2, v2, .., k_n, v_nmapCreator- map creator given the size hint- Returns:
- the map read
- Throws:
TException- when any sub-operation fails
-
readList
public final <T extends java.util.List<?>> T readList(TProtocol.ReadCallback<TList,T> callback) throws TException
- Type Parameters:
T- result list type- Parameters:
callback- callback for reading the list- Returns:
- the list read
- Throws:
TException- when any sub-operation fails
-
readList
public final <T> java.util.List<T> readList(TProtocol.ReadCollectionCallback<T> callback) throws TException
- Type Parameters:
T- element type- Parameters:
callback- callback for reading one element- Returns:
- list of elements read
- Throws:
TException- when any sub-operation fails
-
readList
public final <T> java.util.List<T> readList(TProtocol.ReadCollectionCallback<T> callback, java.util.function.IntFunction<java.util.List<T>> listCreator) throws TException
read aListby delegating element reading to the callback, handlesbeginandendautomatically, with a specialized list creator given the size hint.- Type Parameters:
T- element type- Parameters:
callback- callback for reading one elementlistCreator- list creator given size hint- Returns:
- list of elements read
- Throws:
TException- when any sub-operation fails
-
readSet
public final <T extends java.util.Set<?>> T readSet(TProtocol.ReadCallback<TSet,T> callback) throws TException
- Type Parameters:
T- result set type- Parameters:
callback- callback for reading the set- Returns:
- the set read
- Throws:
TException- when any sub-operation fails
-
readSet
public final <T> java.util.Set<T> readSet(TProtocol.ReadCollectionCallback<T> callback) throws TException
read aSetof elements by delegating element reading to the callback, handlesbeginandendautomatically- Type Parameters:
T- element type- Parameters:
callback- callback for reading one element- Returns:
- set of elements read
- Throws:
TException- when any sub-operation fails
-
readSet
public final <T> java.util.Set<T> readSet(TProtocol.ReadCollectionCallback<T> callback, java.util.function.IntFunction<java.util.Set<T>> setCreator) throws TException
read aSetof elements by delegating element reading to the callback, handlesbeginandendautomatically, with a specialized set creator given the size hint.- Type Parameters:
T- element type- Parameters:
callback- callback for reading one elmentsetCreator- set creator given size hint- Returns:
- set of elements read
- Throws:
TException- when any sub-operation fails
-
reset
public void reset()
Reset any internal state back to a blank slate. This method only needs to be implemented for stateful protocols.
-
getScheme
public java.lang.Class<? extends IScheme> getScheme()
Scheme accessor
-
readFieldBeginData
public int readFieldBeginData() throws TException- Throws:
TException
-
skip
public void skip(byte fieldType) throws TException- Throws:
TException
-
skip
public void skip(byte fieldType, int maxDepth) throws TException- Throws:
TException
-
skipBool
protected void skipBool() throws TExceptionThe default implementation of all skip() methods calls the corresponding read() method. Protocols that derive from this class are strongly encouraged to provide a more efficient alternative.- Throws:
TException
-
skipByte
protected void skipByte() throws TException- Throws:
TException
-
skipI16
protected void skipI16() throws TException- Throws:
TException
-
skipI32
protected void skipI32() throws TException- Throws:
TException
-
skipI64
protected void skipI64() throws TException- Throws:
TException
-
skipDouble
protected void skipDouble() throws TException- Throws:
TException
-
skipBinary
protected void skipBinary() throws TException- Throws:
TException
-
skipBytes
protected void skipBytes(int numBytes) throws TException- Throws:
TException
-
-