Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 1 | #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ |
| 2 | #define _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ 1 |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 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 | */ |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 18 | class TBinaryProtocol : public TProtocol { |
| 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, |
Marc Slemko | 91f6748 | 2006-08-11 23:58:57 +0000 | [diff] [blame] | 28 | const std::string name, |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 29 | const TMessageType messageType, |
Mark Slee | cfc0193 | 2006-09-01 22:18:16 +0000 | [diff] [blame] | 30 | const int32_t seqid) const; |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 31 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 32 | virtual uint32_t writeMessageEnd(shared_ptr<TTransport> out) const; |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 33 | |
| 34 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 35 | uint32_t writeStructBegin(shared_ptr<TTransport> out, |
| 36 | const std::string& name) const; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 37 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 38 | uint32_t writeStructEnd(shared_ptr<TTransport> out) const; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 39 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 40 | uint32_t writeFieldBegin(shared_ptr<TTransport> out, |
| 41 | const std::string& name, |
| 42 | const TType fieldType, |
| 43 | const int16_t fieldId) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 44 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 45 | uint32_t writeFieldEnd(shared_ptr<TTransport> out) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 46 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 47 | uint32_t writeFieldStop(shared_ptr<TTransport> out) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 48 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 49 | uint32_t writeMapBegin(shared_ptr<TTransport> out, |
| 50 | const TType keyType, |
| 51 | const TType valType, |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 52 | const uint32_t size) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 53 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 54 | uint32_t writeMapEnd(shared_ptr<TTransport> out) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 55 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 56 | uint32_t writeListBegin(shared_ptr<TTransport> out, |
| 57 | const TType elemType, |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 58 | const uint32_t size) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 59 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 60 | uint32_t writeListEnd(shared_ptr<TTransport> out) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 61 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 62 | uint32_t writeSetBegin(shared_ptr<TTransport> out, |
| 63 | const TType elemType, |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 64 | const uint32_t size) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 65 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 66 | uint32_t writeSetEnd(shared_ptr<TTransport> out) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 67 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 68 | uint32_t writeBool(shared_ptr<TTransport> out, |
| 69 | const bool value) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 70 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 71 | uint32_t writeByte(shared_ptr<TTransport> out, |
Mark Slee | cfc0193 | 2006-09-01 22:18:16 +0000 | [diff] [blame] | 72 | const int8_t byte) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 73 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 74 | uint32_t writeI16(shared_ptr<TTransport> out, |
| 75 | const int16_t i16) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 76 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 77 | uint32_t writeI32(shared_ptr<TTransport> out, |
| 78 | const int32_t i32) const; |
| 79 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 80 | uint32_t writeI64(shared_ptr<TTransport> out, |
| 81 | const int64_t i64) const; |
| 82 | |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame^] | 83 | uint32_t writeDouble(shared_ptr<TTransport> out, |
| 84 | const double dub) const; |
| 85 | |
| 86 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 87 | uint32_t writeString(shared_ptr<TTransport> out, |
| 88 | const std::string& str) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * Reading functions |
| 92 | */ |
| 93 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 94 | |
Marc Slemko | e6889de | 2006-08-12 00:32:53 +0000 | [diff] [blame] | 95 | uint32_t readMessageBegin(shared_ptr<TTransport> in, |
| 96 | std::string& name, |
| 97 | TMessageType& messageType, |
Mark Slee | cfc0193 | 2006-09-01 22:18:16 +0000 | [diff] [blame] | 98 | int32_t& seqid) const; |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 99 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 100 | uint32_t readMessageEnd(shared_ptr<TTransport> in) const; |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 101 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 102 | uint32_t readStructBegin(shared_ptr<TTransport> in, |
| 103 | std::string& name) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 104 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 105 | uint32_t readStructEnd(shared_ptr<TTransport> in) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 106 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 107 | uint32_t readFieldBegin(shared_ptr<TTransport> in, |
| 108 | std::string& name, |
| 109 | TType& fieldType, |
| 110 | int16_t& fieldId) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 111 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 112 | uint32_t readFieldEnd(shared_ptr<TTransport> in) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 113 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 114 | uint32_t readMapBegin(shared_ptr<TTransport> in, |
| 115 | TType& keyType, |
| 116 | TType& valType, |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 117 | uint32_t& size) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 118 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 119 | uint32_t readMapEnd(shared_ptr<TTransport> in) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 120 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 121 | uint32_t readListBegin(shared_ptr<TTransport> in, |
| 122 | TType& elemType, |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 123 | uint32_t& size) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 124 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 125 | uint32_t readListEnd(shared_ptr<TTransport> in) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 126 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 127 | uint32_t readSetBegin(shared_ptr<TTransport> in, |
| 128 | TType& elemType, |
Marc Slemko | b09f588 | 2006-08-23 22:03:34 +0000 | [diff] [blame] | 129 | uint32_t& size) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 130 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 131 | uint32_t readSetEnd(shared_ptr<TTransport> in) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 132 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 133 | uint32_t readBool(shared_ptr<TTransport> in, |
| 134 | bool& value) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 135 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 136 | uint32_t readByte(shared_ptr<TTransport> in, |
Mark Slee | cfc0193 | 2006-09-01 22:18:16 +0000 | [diff] [blame] | 137 | int8_t& byte) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 138 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 139 | uint32_t readI16(shared_ptr<TTransport> in, |
| 140 | int16_t& i16) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 141 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 142 | uint32_t readI32(shared_ptr<TTransport> in, |
| 143 | int32_t& i32) const; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 144 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 145 | uint32_t readI64(shared_ptr<TTransport> in, |
| 146 | int64_t& i64) const; |
| 147 | |
Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame^] | 148 | uint32_t readDouble(shared_ptr<TTransport> in, |
| 149 | double& dub) const; |
| 150 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame] | 151 | uint32_t readString(shared_ptr<TTransport> in, |
| 152 | std::string& str) const; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 155 | }}} // facebook::thrift::protocol |
| 156 | |
Mark Slee | f5f2be4 | 2006-09-05 21:05:31 +0000 | [diff] [blame] | 157 | #endif // #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ |
| 158 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 159 | |