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 Object implements TWriteProtocol, TReadProtocol
Protocol interface definition.
  • Field Details

    • trans_

      protected TTransport trans_
      Transport
    • skippedBytes

      protected byte[] skippedBytes
  • Constructor Details

    • TProtocol

      protected TProtocol(TTransport trans)
      Constructor
  • Method Details

    • 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 TException
      Return 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, Set<T> set, TProtocol.WriteCallback<T> callback) throws TException
      Throws:
      TException
    • writeList

      public final <T> void writeList(byte elementType, List<T> list, TProtocol.WriteCallback<T> callback) throws TException
      Throws:
      TException
    • writeMap

      public final <K, V> void writeMap(byte keyType, byte valueType, Map<K,V> map, TProtocol.WriteCallback<Map.Entry<K,V>> callback) throws TException
      Throws:
      TException
    • writeField

      public final void writeField(TField field, TProtocol.WriteCallback<Void> callback) throws TException
      Throws:
      TException
    • writeStruct

      public final void writeStruct(TStruct struct, TProtocol.WriteCallback<Void> callback) throws TException
      Throws:
      TException
    • writeMessage

      public final void writeMessage(TMessage message, TProtocol.WriteCallback<Void> callback) throws TException
      Throws:
      TException
    • readMessage

      public final <T> T readMessage(TProtocol.ReadCallback<TMessage,T> callback) throws TException
      read a message by delegating to a callback, handles begin and end automatically.
      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
      read a struct by delegating to a callback, handles begin and end automatically.
      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 Exception
      read a field by delegating to a callback, handles begin and end automatically, and returns whether the stop signal was 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:
      Exception - when any sub-operation failed
    • readMap

      public final <T extends Map<?, ?>> T readMap(TProtocol.ReadCallback<TMap,T> callback) throws TException
      read a Map of elements by delegating to the callback, handles begin and end automatically.
      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> Map<K,V> readMap(TProtocol.ReadMapEntryCallback<K,V> callback) throws TException
      read a Map of elements by delegating key and value reading to the callback, handles begin and end automatically.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      callback - callback for reading keys and values, calls to TProtocol.ReadMapEntryCallback.getKey() and TProtocol.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> Map<K,V> readMap(TProtocol.ReadMapEntryCallback<K,V> callback, IntFunction<Map<K,V>> mapCreator) throws TException
      read a Map of elements by delegating key and value reading to the callback, handles begin and end automatically, with a specialized map creator given the size hint.
      Type Parameters:
      K - key type
      V - value type
      Parameters:
      callback - callback for reading keys and values, calls to TProtocol.ReadMapEntryCallback.getKey() and TProtocol.ReadMapEntryCallback.getValue() will be in alternating orders, i.e. k1, v1, k2, v2, .., k_n, v_n
      mapCreator - map creator given the size hint
      Returns:
      the map read
      Throws:
      TException - when any sub-operation fails
    • readList

      public final <T extends List<?>> T readList(TProtocol.ReadCallback<TList,T> callback) throws TException
      read a List by delegating to the callback, handles begin and end automatically.
      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> List<T> readList(TProtocol.ReadCollectionCallback<T> callback) throws TException
      read a List by delegating element reading to the callback, handles begin and end automatically.
      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> List<T> readList(TProtocol.ReadCollectionCallback<T> callback, IntFunction<List<T>> listCreator) throws TException
      read a List by delegating element reading to the callback, handles begin and end automatically, with a specialized list creator given the size hint.
      Type Parameters:
      T - element type
      Parameters:
      callback - callback for reading one element
      listCreator - list creator given size hint
      Returns:
      list of elements read
      Throws:
      TException - when any sub-operation fails
    • readSet

      public final <T extends Set<?>> T readSet(TProtocol.ReadCallback<TSet,T> callback) throws TException
      read a Set of elements by delegating to the callback, handles begin and end automatically
      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> Set<T> readSet(TProtocol.ReadCollectionCallback<T> callback) throws TException
      read a Set of elements by delegating element reading to the callback, handles begin and end automatically
      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> Set<T> readSet(TProtocol.ReadCollectionCallback<T> callback, IntFunction<Set<T>> setCreator) throws TException
      read a Set of elements by delegating element reading to the callback, handles begin and end automatically, with a specialized set creator given the size hint.
      Type Parameters:
      T - element type
      Parameters:
      callback - callback for reading one elment
      setCreator - 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 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 TException
      The 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