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