Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 1 | #ifndef T_BINARY_PROTOCOL_H |
| 2 | #define T_BINARY_PROTOCOL_H |
| 3 | |
| 4 | #include "protocol/TProtocol.h" |
| 5 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame^] | 6 | namespace facebook { namespace thrift { namespace protocol { |
| 7 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 8 | /** |
| 9 | * The default binary protocol for thrift. Writes all data in a very basic |
| 10 | * binary format, essentially just spitting out the raw bytes. |
| 11 | * |
| 12 | * @author Mark Slee <mcslee@facebook.com> |
| 13 | */ |
| 14 | class TBinaryProtocol : public TProtocol { |
| 15 | public: |
| 16 | TBinaryProtocol() {} |
| 17 | ~TBinaryProtocol() {} |
| 18 | |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 19 | /** |
| 20 | * Writing functions. |
| 21 | */ |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 22 | |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 23 | uint32_t writeStructBegin (TTransport* out, |
| 24 | const std::string& name) const; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 25 | |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 26 | uint32_t writeStructEnd (TTransport* out) const; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 27 | |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 28 | uint32_t writeFieldBegin (TTransport* out, |
| 29 | const std::string& name, |
| 30 | const TType fieldType, |
| 31 | const uint16_t fieldId) const; |
| 32 | |
| 33 | uint32_t writeFieldEnd (TTransport* out) const; |
| 34 | |
| 35 | uint32_t writeFieldStop (TTransport* out) const; |
| 36 | |
| 37 | uint32_t writeMapBegin (TTransport* out, |
| 38 | const TType keyType, |
| 39 | const TType valType, |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 40 | const int32_t size) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 41 | |
| 42 | uint32_t writeMapEnd (TTransport* out) const; |
| 43 | |
| 44 | uint32_t writeListBegin (TTransport* out, |
| 45 | const TType elemType, |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 46 | const int32_t size) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 47 | |
| 48 | uint32_t writeListEnd (TTransport* out) const; |
| 49 | |
| 50 | uint32_t writeSetBegin (TTransport* out, |
| 51 | const TType elemType, |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 52 | const int32_t size) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 53 | |
| 54 | uint32_t writeSetEnd (TTransport* out) const; |
| 55 | |
| 56 | uint32_t writeByte (TTransport* out, |
| 57 | const uint8_t byte) const; |
| 58 | |
| 59 | uint32_t writeU32 (TTransport* out, |
| 60 | const uint32_t u32) const; |
| 61 | |
| 62 | uint32_t writeI32 (TTransport* out, |
| 63 | const int32_t i32) const; |
| 64 | |
| 65 | uint32_t writeU64 (TTransport* out, |
| 66 | const uint64_t u64) const; |
| 67 | |
| 68 | uint32_t writeI64 (TTransport* out, |
| 69 | const int64_t i64) const; |
| 70 | |
| 71 | uint32_t writeString (TTransport* out, |
| 72 | const std::string& str) const; |
| 73 | |
| 74 | /** |
| 75 | * Reading functions |
| 76 | */ |
| 77 | |
| 78 | uint32_t readStructBegin (TTransport* in, |
| 79 | std::string& name) const; |
| 80 | |
| 81 | uint32_t readStructEnd (TTransport* in) const; |
| 82 | |
| 83 | uint32_t readFieldBegin (TTransport* in, |
| 84 | std::string& name, |
| 85 | TType& fieldType, |
| 86 | uint16_t& fieldId) const; |
| 87 | |
| 88 | uint32_t readFieldEnd (TTransport* in) const; |
| 89 | |
| 90 | uint32_t readMapBegin (TTransport* in, |
| 91 | TType& keyType, |
| 92 | TType& valType, |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 93 | int32_t& size) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 94 | |
| 95 | uint32_t readMapEnd (TTransport* in) const; |
| 96 | |
| 97 | uint32_t readListBegin (TTransport* in, |
| 98 | TType& elemType, |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 99 | int32_t& size) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 100 | |
| 101 | uint32_t readListEnd (TTransport* in) const; |
| 102 | |
| 103 | uint32_t readSetBegin (TTransport* in, |
| 104 | TType& elemType, |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 105 | int32_t& size) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 106 | |
| 107 | uint32_t readSetEnd (TTransport* in) const; |
| 108 | |
| 109 | uint32_t readByte (TTransport* in, |
| 110 | uint8_t& byte) const; |
| 111 | |
| 112 | uint32_t readU32 (TTransport* in, |
| 113 | uint32_t& u32) const; |
| 114 | |
| 115 | uint32_t readI32 (TTransport* in, |
| 116 | int32_t& i32) const; |
| 117 | |
| 118 | uint32_t readU64 (TTransport* in, |
| 119 | uint64_t& u64) const; |
| 120 | |
| 121 | uint32_t readI64 (TTransport* in, |
| 122 | int64_t& i64) const; |
| 123 | |
| 124 | uint32_t readString (TTransport* in, |
| 125 | std::string& str) const; |
| 126 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame^] | 129 | }}} // facebook::thrift::protocol |
| 130 | |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 131 | #endif |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame^] | 132 | |