blob: 89f4d4abd1cc05666a07be0b5460608de3640d76 [file] [log] [blame]
Mark Sleee8540632006-05-30 09:24:40 +00001#ifndef T_BINARY_PROTOCOL_H
2#define T_BINARY_PROTOCOL_H
3
Marc Slemkod42a2c22006-08-10 03:30:18 +00004#include "TProtocol.h"
Marc Slemko16698852006-08-04 03:16:10 +00005
6#include <boost/shared_ptr.hpp>
Mark Sleee8540632006-05-30 09:24:40 +00007
Marc Slemko6f038a72006-08-03 18:58:09 +00008namespace facebook { namespace thrift { namespace protocol {
9
Marc Slemko16698852006-08-04 03:16:10 +000010using namespace boost;
11
Mark Sleee8540632006-05-30 09:24:40 +000012/**
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 Slemko0b4ffa92006-08-11 02:49:29 +000018 class TBinaryProtocol : public TProtocol {
19 public:
Mark Sleee8540632006-05-30 09:24:40 +000020 TBinaryProtocol() {}
21 ~TBinaryProtocol() {}
22
Mark Slee8d7e1f62006-06-07 06:48:56 +000023 /**
24 * Writing functions.
25 */
Mark Sleee8540632006-05-30 09:24:40 +000026
Marc Slemko16698852006-08-04 03:16:10 +000027 virtual uint32_t writeMessageBegin(shared_ptr<TTransport> out,
28 const TMessageType messageType,
29 const uint32_t seqid) const;
30
Marc Slemko0b4ffa92006-08-11 02:49:29 +000031 virtual uint32_t writeMessageEnd(shared_ptr<TTransport> out) const;
Marc Slemko16698852006-08-04 03:16:10 +000032
33
Marc Slemko0b4ffa92006-08-11 02:49:29 +000034 uint32_t writeStructBegin(shared_ptr<TTransport> out,
35 const std::string& name) const;
Mark Sleee8540632006-05-30 09:24:40 +000036
Marc Slemko0b4ffa92006-08-11 02:49:29 +000037 uint32_t writeStructEnd(shared_ptr<TTransport> out) const;
Mark Sleee8540632006-05-30 09:24:40 +000038
Marc Slemko0b4ffa92006-08-11 02:49:29 +000039 uint32_t writeFieldBegin(shared_ptr<TTransport> out,
40 const std::string& name,
41 const TType fieldType,
42 const int16_t fieldId) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000043
Marc Slemko0b4ffa92006-08-11 02:49:29 +000044 uint32_t writeFieldEnd(shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000045
Marc Slemko0b4ffa92006-08-11 02:49:29 +000046 uint32_t writeFieldStop(shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000047
Marc Slemko0b4ffa92006-08-11 02:49:29 +000048 uint32_t writeMapBegin(shared_ptr<TTransport> out,
49 const TType keyType,
50 const TType valType,
51 const int32_t size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000052
Marc Slemko0b4ffa92006-08-11 02:49:29 +000053 uint32_t writeMapEnd(shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000054
Marc Slemko0b4ffa92006-08-11 02:49:29 +000055 uint32_t writeListBegin(shared_ptr<TTransport> out,
56 const TType elemType,
57 const int32_t size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000058
Marc Slemko0b4ffa92006-08-11 02:49:29 +000059 uint32_t writeListEnd(shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000060
Marc Slemko0b4ffa92006-08-11 02:49:29 +000061 uint32_t writeSetBegin(shared_ptr<TTransport> out,
62 const TType elemType,
63 const int32_t size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000064
Marc Slemko0b4ffa92006-08-11 02:49:29 +000065 uint32_t writeSetEnd(shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000066
Marc Slemko0b4ffa92006-08-11 02:49:29 +000067 uint32_t writeBool(shared_ptr<TTransport> out,
68 const bool value) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000069
Marc Slemko0b4ffa92006-08-11 02:49:29 +000070 uint32_t writeByte(shared_ptr<TTransport> out,
71 const uint8_t byte) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000072
Marc Slemko0b4ffa92006-08-11 02:49:29 +000073 uint32_t writeU16(shared_ptr<TTransport> out,
74 const uint16_t u16) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000075
Marc Slemko0b4ffa92006-08-11 02:49:29 +000076 uint32_t writeI16(shared_ptr<TTransport> out,
77 const int16_t i16) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000078
Marc Slemko0b4ffa92006-08-11 02:49:29 +000079 uint32_t writeU32(shared_ptr<TTransport> out,
80 const uint32_t u32) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000081
Marc Slemko0b4ffa92006-08-11 02:49:29 +000082 uint32_t writeI32(shared_ptr<TTransport> out,
83 const int32_t i32) const;
84
85 uint32_t writeU64(shared_ptr<TTransport> out,
86 const uint64_t u64) const;
87
88 uint32_t writeI64(shared_ptr<TTransport> out,
89 const int64_t i64) const;
90
91 uint32_t writeString(shared_ptr<TTransport> out,
92 const std::string& str) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000093
94 /**
95 * Reading functions
96 */
97
Marc Slemko16698852006-08-04 03:16:10 +000098
Marc Slemko0b4ffa92006-08-11 02:49:29 +000099 uint32_t readMessasgeBegin(shared_ptr<TTransport> in,
100 TMessageType& messageType,
101 uint32_t& seqid) const;
Marc Slemko16698852006-08-04 03:16:10 +0000102
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000103 uint32_t readMessageEnd(shared_ptr<TTransport> in) const;
Marc Slemko16698852006-08-04 03:16:10 +0000104
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000105 uint32_t readStructBegin(shared_ptr<TTransport> in,
106 std::string& name) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000107
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000108 uint32_t readStructEnd(shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000109
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000110 uint32_t readFieldBegin(shared_ptr<TTransport> in,
111 std::string& name,
112 TType& fieldType,
113 int16_t& fieldId) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000114
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000115 uint32_t readFieldEnd(shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000116
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000117 uint32_t readMapBegin(shared_ptr<TTransport> in,
118 TType& keyType,
119 TType& valType,
120 int32_t& size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000121
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000122 uint32_t readMapEnd(shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000123
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000124 uint32_t readListBegin(shared_ptr<TTransport> in,
125 TType& elemType,
126 int32_t& size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000127
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000128 uint32_t readListEnd(shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000129
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000130 uint32_t readSetBegin(shared_ptr<TTransport> in,
131 TType& elemType,
132 int32_t& size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000133
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000134 uint32_t readSetEnd(shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000135
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000136 uint32_t readBool(shared_ptr<TTransport> in,
137 bool& value) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000138
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000139 uint32_t readByte(shared_ptr<TTransport> in,
140 uint8_t& byte) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000141
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000142 uint32_t readU16(shared_ptr<TTransport> in,
143 uint16_t& u16) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000144
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000145 uint32_t readI16(shared_ptr<TTransport> in,
146 int16_t& i16) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000147
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000148 uint32_t readU32(shared_ptr<TTransport> in,
149 uint32_t& u32) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000150
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000151 uint32_t readI32(shared_ptr<TTransport> in,
152 int32_t& i32) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000153
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000154 uint32_t readU64(shared_ptr<TTransport> in,
155 uint64_t& u64) const;
156
157 uint32_t readI64(shared_ptr<TTransport> in,
158 int64_t& i64) const;
159
160 uint32_t readString(shared_ptr<TTransport> in,
161 std::string& str) const;
Mark Sleee8540632006-05-30 09:24:40 +0000162};
163
Marc Slemko6f038a72006-08-03 18:58:09 +0000164}}} // facebook::thrift::protocol
165
Mark Sleee8540632006-05-30 09:24:40 +0000166#endif
Marc Slemko6f038a72006-08-03 18:58:09 +0000167