Class TTextProtocol
public final class TTextProtocol extends TProtocol
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.
Messages must be formatted as a JSON object with a field 'method' containing
the message name, 'type' containing the message type as an uppercase string
corresponding to TMessageType
, 'args' containing a JSON object with
the actual arguments, and an optional 'seqid' field containing the sequence
id. If 'seqid' is not provided, it will be treated as 0. 'args' should use
the argument names as defined in the service definition.
Example:
{
"method": "GetItem",
"type": "CALL",
"args": {
"id": 1,
"fetchAll": true
},
"seqid": 100
}
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: Support map enum keys specified as strings.
TODO: Support string values for enums that have been typedef'd.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description TTextProtocol(TTransport trans)
Create a parser which can read from trans, and create the output writer that can write to a TTransport.TTextProtocol(TTransport trans, boolean useNamedEnums)
Create a parser which can read from trans, and create the output writer that can write to a TTransport, optionally enabling serialization of named enums. -
Method Summary
-
Constructor Details
-
TTextProtocol
Create a parser which can read from trans, and create the output writer that can write to a TTransport. -
TTextProtocol
Create a parser which can read from trans, and create the output writer that can write to a TTransport, optionally enabling serialization of named enums.
-
-
Method Details
-
getScheme
-
reset
public void reset() -
writeMessageBegin
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 classTProtocol
- Throws:
TException
-
writeMessageEnd
- Specified by:
writeMessageEnd
in classTProtocol
- Throws:
TException
-
writeStructBegin
- Specified by:
writeStructBegin
in classTProtocol
- Throws:
TException
-
writeStructEnd
- Specified by:
writeStructEnd
in classTProtocol
- Throws:
TException
-
writeFieldBegin
- Specified by:
writeFieldBegin
in classTProtocol
- Throws:
TException
-
writeFieldEnd
- Specified by:
writeFieldEnd
in classTProtocol
- Throws:
TException
-
writeFieldStop
- Specified by:
writeFieldStop
in classTProtocol
- Throws:
TException
-
writeMapBegin
- Specified by:
writeMapBegin
in classTProtocol
- Throws:
TException
-
writeMapEnd
- Specified by:
writeMapEnd
in classTProtocol
- Throws:
TException
-
writeListBegin
- Specified by:
writeListBegin
in classTProtocol
- Throws:
TException
-
writeListEnd
- Specified by:
writeListEnd
in classTProtocol
- Throws:
TException
-
writeSetBegin
- Specified by:
writeSetBegin
in classTProtocol
- Throws:
TException
-
writeSetEnd
- Specified by:
writeSetEnd
in classTProtocol
- Throws:
TException
-
writeBool
- Specified by:
writeBool
in classTProtocol
- Throws:
TException
-
writeByte
- Specified by:
writeByte
in classTProtocol
- Throws:
TException
-
writeI16
- Specified by:
writeI16
in classTProtocol
- Throws:
TException
-
writeI32
- Specified by:
writeI32
in classTProtocol
- Throws:
TException
-
writeI64
- Specified by:
writeI64
in classTProtocol
- Throws:
TException
-
writeDouble
- Specified by:
writeDouble
in classTProtocol
- Throws:
TException
-
writeString
- Specified by:
writeString
in classTProtocol
- Throws:
TException
-
writeBinary
- Specified by:
writeBinary
in classTProtocol
- Throws:
TException
-
readMessageBegin
- Specified by:
readMessageBegin
in classTProtocol
- Throws:
TException
-
readMessageEnd
- Specified by:
readMessageEnd
in classTProtocol
- Throws:
TException
-
readStructBegin
- Specified by:
readStructBegin
in classTProtocol
- Throws:
TException
-
readStructEnd
- Specified by:
readStructEnd
in classTProtocol
- Throws:
TException
-
readFieldBegin
- Specified by:
readFieldBegin
in classTProtocol
- Throws:
TException
-
readFieldEnd
- Specified by:
readFieldEnd
in classTProtocol
- Throws:
TException
-
readMapBegin
- Specified by:
readMapBegin
in classTProtocol
- Throws:
TException
-
readMapEnd
- Specified by:
readMapEnd
in classTProtocol
- Throws:
TException
-
readListBegin
- Specified by:
readListBegin
in classTProtocol
- Throws:
TException
-
readListEnd
- Specified by:
readListEnd
in classTProtocol
- Throws:
TException
-
readSetBegin
- Specified by:
readSetBegin
in classTProtocol
- Throws:
TException
-
readSetEnd
- Specified by:
readSetEnd
in classTProtocol
- Throws:
TException
-
readBool
- Specified by:
readBool
in classTProtocol
- Throws:
TException
-
readByte
- Specified by:
readByte
in classTProtocol
- Throws:
TException
-
readI16
- Specified by:
readI16
in classTProtocol
- Throws:
TException
-
readI32
- Specified by:
readI32
in classTProtocol
- Throws:
TException
-
readI64
- Specified by:
readI64
in classTProtocol
- Throws:
TException
-
readDouble
- Specified by:
readDouble
in classTProtocol
- Throws:
TException
-
readString
- Specified by:
readString
in classTProtocol
- Throws:
TException
-
readBinary
- Specified by:
readBinary
in classTProtocol
- Throws:
TException
-