com.twitter.common.thrift.text
Class TTextProtocol

java.lang.Object
  extended by org.apache.thrift.protocol.TProtocol
      extended by com.twitter.common.thrift.text.TTextProtocol

public class TTextProtocol
extends org.apache.thrift.protocol.TProtocol

A simple text format for serializing/deserializing thrift messages. This format is inefficient in space. For an example, see: tests/resources/com/twitter/common/thrift/text/TTextProtocol_TestData.txt which is a text encoding of the thrift message defined in: src/main/thrift/com/twitter/common/thrift/text/TTextProtocolTest.thrift Whitespace (including newlines) is not significant. No comments are allowed in the json. We support parsing structs and anything embedded in a struct, but not messages (which are generated as part of thrift RPC service definitions). TODO(Alex Roetter): write a wrapper that allows us to read in a file of many structs (perhaps stored in a JsonArray), passing each struct to this class for parsing. See thrift's @see org.apache.thrift.protocol.TJSONProtocol for another example an implementation of the @see TProtocol interface. This class is based on that. TODO(Alex Roetter): Also add a new TEXT_PROTOCOL field to ThriftCodec TODO(Alex Roetter): throw this up on my github. Seems generally useful. TODO(Alex Roetter): add support for enums


Nested Class Summary
static class TTextProtocol.Factory
          Factory
 
Field Summary
 
Fields inherited from class org.apache.thrift.protocol.TProtocol
trans_
 
Constructor Summary
TTextProtocol(org.apache.thrift.transport.TTransport trans)
          Create a parser which can read from trans, and create the output writer that can write to a TTransport
 
Method Summary
 ByteBuffer readBinary()
           
 boolean readBool()
           
 byte readByte()
           
 double readDouble()
           
 org.apache.thrift.protocol.TField readFieldBegin()
           
 void readFieldEnd()
           
 short readI16()
           
 int readI32()
           
 long readI64()
           
 org.apache.thrift.protocol.TList readListBegin()
           
 void readListEnd()
           
 org.apache.thrift.protocol.TMap readMapBegin()
           
 void readMapEnd()
           
 org.apache.thrift.protocol.TMessage readMessageBegin()
           
 void readMessageEnd()
           
 org.apache.thrift.protocol.TSet readSetBegin()
           
 void readSetEnd()
           
 String readString()
           
 org.apache.thrift.protocol.TStruct readStructBegin()
           
 void readStructEnd()
           
 void reset()
           
 void writeBinary(ByteBuffer buf)
           
 void writeBool(boolean b)
           
 void writeByte(byte b)
           
 void writeDouble(double dub)
           
 void writeFieldBegin(org.apache.thrift.protocol.TField field)
           
 void writeFieldEnd()
           
 void writeFieldStop()
           
 void writeI16(short i16)
           
 void writeI32(int i32)
           
 void writeI64(long i64)
           
 void writeListBegin(org.apache.thrift.protocol.TList list)
           
 void writeListEnd()
           
 void writeMapBegin(org.apache.thrift.protocol.TMap map)
           
 void writeMapEnd()
           
 void writeMessageBegin(org.apache.thrift.protocol.TMessage message)
          I believe these two messages are called for a thrift service interface.
 void writeMessageEnd()
           
 void writeSetBegin(org.apache.thrift.protocol.TSet set)
           
 void writeSetEnd()
           
 void writeString(String str)
           
 void writeStructBegin(org.apache.thrift.protocol.TStruct struct)
           
 void writeStructEnd()
           
 
Methods inherited from class org.apache.thrift.protocol.TProtocol
getTransport
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TTextProtocol

public TTextProtocol(org.apache.thrift.transport.TTransport trans)
Create a parser which can read from trans, and create the output writer that can write to a TTransport

Method Detail

reset

public final void reset()
Overrides:
reset in class org.apache.thrift.protocol.TProtocol

writeMessageBegin

public void writeMessageBegin(org.apache.thrift.protocol.TMessage message)
                       throws org.apache.thrift.TException
I believe these two messages are called for a thrift service interface. We don't plan on storing any text objects of that type on disk.

Specified by:
writeMessageBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeMessageEnd

public void writeMessageEnd()
                     throws org.apache.thrift.TException
Specified by:
writeMessageEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeStructBegin

public void writeStructBegin(org.apache.thrift.protocol.TStruct struct)
                      throws org.apache.thrift.TException
Specified by:
writeStructBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeStructEnd

public void writeStructEnd()
                    throws org.apache.thrift.TException
Specified by:
writeStructEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeFieldBegin

public void writeFieldBegin(org.apache.thrift.protocol.TField field)
                     throws org.apache.thrift.TException
Specified by:
writeFieldBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeFieldEnd

public void writeFieldEnd()
                   throws org.apache.thrift.TException
Specified by:
writeFieldEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeFieldStop

public void writeFieldStop()
                    throws org.apache.thrift.TException
Specified by:
writeFieldStop in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeMapBegin

public void writeMapBegin(org.apache.thrift.protocol.TMap map)
                   throws org.apache.thrift.TException
Specified by:
writeMapBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeMapEnd

public void writeMapEnd()
                 throws org.apache.thrift.TException
Specified by:
writeMapEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeListBegin

public void writeListBegin(org.apache.thrift.protocol.TList list)
                    throws org.apache.thrift.TException
Specified by:
writeListBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeListEnd

public void writeListEnd()
                  throws org.apache.thrift.TException
Specified by:
writeListEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeSetBegin

public void writeSetBegin(org.apache.thrift.protocol.TSet set)
                   throws org.apache.thrift.TException
Specified by:
writeSetBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeSetEnd

public void writeSetEnd()
                 throws org.apache.thrift.TException
Specified by:
writeSetEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeBool

public void writeBool(boolean b)
               throws org.apache.thrift.TException
Specified by:
writeBool in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeByte

public void writeByte(byte b)
               throws org.apache.thrift.TException
Specified by:
writeByte in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeI16

public void writeI16(short i16)
              throws org.apache.thrift.TException
Specified by:
writeI16 in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeI32

public void writeI32(int i32)
              throws org.apache.thrift.TException
Specified by:
writeI32 in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeI64

public void writeI64(long i64)
              throws org.apache.thrift.TException
Specified by:
writeI64 in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeDouble

public void writeDouble(double dub)
                 throws org.apache.thrift.TException
Specified by:
writeDouble in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeString

public void writeString(String str)
                 throws org.apache.thrift.TException
Specified by:
writeString in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

writeBinary

public void writeBinary(ByteBuffer buf)
                 throws org.apache.thrift.TException
Specified by:
writeBinary in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readMessageBegin

public org.apache.thrift.protocol.TMessage readMessageBegin()
                                                     throws org.apache.thrift.TException
Specified by:
readMessageBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readMessageEnd

public void readMessageEnd()
                    throws org.apache.thrift.TException
Specified by:
readMessageEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readStructBegin

public org.apache.thrift.protocol.TStruct readStructBegin()
                                                   throws org.apache.thrift.TException
Specified by:
readStructBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readStructEnd

public void readStructEnd()
                   throws org.apache.thrift.TException
Specified by:
readStructEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readFieldBegin

public org.apache.thrift.protocol.TField readFieldBegin()
                                                 throws org.apache.thrift.TException
Specified by:
readFieldBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readFieldEnd

public void readFieldEnd()
                  throws org.apache.thrift.TException
Specified by:
readFieldEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readMapBegin

public org.apache.thrift.protocol.TMap readMapBegin()
                                             throws org.apache.thrift.TException
Specified by:
readMapBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readMapEnd

public void readMapEnd()
                throws org.apache.thrift.TException
Specified by:
readMapEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readListBegin

public org.apache.thrift.protocol.TList readListBegin()
                                               throws org.apache.thrift.TException
Specified by:
readListBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readListEnd

public void readListEnd()
                 throws org.apache.thrift.TException
Specified by:
readListEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readSetBegin

public org.apache.thrift.protocol.TSet readSetBegin()
                                             throws org.apache.thrift.TException
Specified by:
readSetBegin in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readSetEnd

public void readSetEnd()
                throws org.apache.thrift.TException
Specified by:
readSetEnd in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readBool

public boolean readBool()
                 throws org.apache.thrift.TException
Specified by:
readBool in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readByte

public byte readByte()
              throws org.apache.thrift.TException
Specified by:
readByte in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readI16

public short readI16()
              throws org.apache.thrift.TException
Specified by:
readI16 in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readI32

public int readI32()
            throws org.apache.thrift.TException
Specified by:
readI32 in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readI64

public long readI64()
             throws org.apache.thrift.TException
Specified by:
readI64 in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readDouble

public double readDouble()
                  throws org.apache.thrift.TException
Specified by:
readDouble in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readString

public String readString()
                  throws org.apache.thrift.TException
Specified by:
readString in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException

readBinary

public ByteBuffer readBinary()
                      throws org.apache.thrift.TException
Specified by:
readBinary in class org.apache.thrift.protocol.TProtocol
Throws:
org.apache.thrift.TException