blob: 7f36a578858a8f96a5dc7023db2d1010ce54b6a9 [file] [log] [blame]
Mark Sleef5f2be42006-09-05 21:05:31 +00001#ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_
2#define _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_ 1
Mark Sleee8540632006-05-30 09:24:40 +00003
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,
Marc Slemko91f67482006-08-11 23:58:57 +000028 const std::string name,
Marc Slemko16698852006-08-04 03:16:10 +000029 const TMessageType messageType,
Mark Sleecfc01932006-09-01 22:18:16 +000030 const int32_t seqid) const;
Marc Slemko16698852006-08-04 03:16:10 +000031
Marc Slemko0b4ffa92006-08-11 02:49:29 +000032 virtual uint32_t writeMessageEnd(shared_ptr<TTransport> out) const;
Marc Slemko16698852006-08-04 03:16:10 +000033
34
Marc Slemko0b4ffa92006-08-11 02:49:29 +000035 uint32_t writeStructBegin(shared_ptr<TTransport> out,
36 const std::string& name) const;
Mark Sleee8540632006-05-30 09:24:40 +000037
Marc Slemko0b4ffa92006-08-11 02:49:29 +000038 uint32_t writeStructEnd(shared_ptr<TTransport> out) const;
Mark Sleee8540632006-05-30 09:24:40 +000039
Marc Slemko0b4ffa92006-08-11 02:49:29 +000040 uint32_t writeFieldBegin(shared_ptr<TTransport> out,
41 const std::string& name,
42 const TType fieldType,
43 const int16_t fieldId) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000044
Marc Slemko0b4ffa92006-08-11 02:49:29 +000045 uint32_t writeFieldEnd(shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000046
Marc Slemko0b4ffa92006-08-11 02:49:29 +000047 uint32_t writeFieldStop(shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000048
Marc Slemko0b4ffa92006-08-11 02:49:29 +000049 uint32_t writeMapBegin(shared_ptr<TTransport> out,
50 const TType keyType,
51 const TType valType,
Marc Slemkob09f5882006-08-23 22:03:34 +000052 const uint32_t size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000053
Marc Slemko0b4ffa92006-08-11 02:49:29 +000054 uint32_t writeMapEnd(shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000055
Marc Slemko0b4ffa92006-08-11 02:49:29 +000056 uint32_t writeListBegin(shared_ptr<TTransport> out,
57 const TType elemType,
Marc Slemkob09f5882006-08-23 22:03:34 +000058 const uint32_t size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000059
Marc Slemko0b4ffa92006-08-11 02:49:29 +000060 uint32_t writeListEnd(shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000061
Marc Slemko0b4ffa92006-08-11 02:49:29 +000062 uint32_t writeSetBegin(shared_ptr<TTransport> out,
63 const TType elemType,
Marc Slemkob09f5882006-08-23 22:03:34 +000064 const uint32_t size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000065
Marc Slemko0b4ffa92006-08-11 02:49:29 +000066 uint32_t writeSetEnd(shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000067
Marc Slemko0b4ffa92006-08-11 02:49:29 +000068 uint32_t writeBool(shared_ptr<TTransport> out,
69 const bool value) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000070
Marc Slemko0b4ffa92006-08-11 02:49:29 +000071 uint32_t writeByte(shared_ptr<TTransport> out,
Mark Sleecfc01932006-09-01 22:18:16 +000072 const int8_t byte) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000073
Marc Slemko0b4ffa92006-08-11 02:49:29 +000074 uint32_t writeI16(shared_ptr<TTransport> out,
75 const int16_t i16) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000076
Marc Slemko0b4ffa92006-08-11 02:49:29 +000077 uint32_t writeI32(shared_ptr<TTransport> out,
78 const int32_t i32) const;
79
Marc Slemko0b4ffa92006-08-11 02:49:29 +000080 uint32_t writeI64(shared_ptr<TTransport> out,
81 const int64_t i64) const;
82
Mark Sleec98d0502006-09-06 02:42:25 +000083 uint32_t writeDouble(shared_ptr<TTransport> out,
84 const double dub) const;
85
86
Marc Slemko0b4ffa92006-08-11 02:49:29 +000087 uint32_t writeString(shared_ptr<TTransport> out,
88 const std::string& str) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000089
90 /**
91 * Reading functions
92 */
93
Marc Slemko16698852006-08-04 03:16:10 +000094
Marc Slemkoe6889de2006-08-12 00:32:53 +000095 uint32_t readMessageBegin(shared_ptr<TTransport> in,
96 std::string& name,
97 TMessageType& messageType,
Mark Sleecfc01932006-09-01 22:18:16 +000098 int32_t& seqid) const;
Marc Slemko16698852006-08-04 03:16:10 +000099
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000100 uint32_t readMessageEnd(shared_ptr<TTransport> in) const;
Marc Slemko16698852006-08-04 03:16:10 +0000101
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000102 uint32_t readStructBegin(shared_ptr<TTransport> in,
103 std::string& name) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000104
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000105 uint32_t readStructEnd(shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000106
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000107 uint32_t readFieldBegin(shared_ptr<TTransport> in,
108 std::string& name,
109 TType& fieldType,
110 int16_t& fieldId) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000111
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000112 uint32_t readFieldEnd(shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000113
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000114 uint32_t readMapBegin(shared_ptr<TTransport> in,
115 TType& keyType,
116 TType& valType,
Marc Slemkob09f5882006-08-23 22:03:34 +0000117 uint32_t& size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000118
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000119 uint32_t readMapEnd(shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000120
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000121 uint32_t readListBegin(shared_ptr<TTransport> in,
122 TType& elemType,
Marc Slemkob09f5882006-08-23 22:03:34 +0000123 uint32_t& size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000124
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000125 uint32_t readListEnd(shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000126
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000127 uint32_t readSetBegin(shared_ptr<TTransport> in,
128 TType& elemType,
Marc Slemkob09f5882006-08-23 22:03:34 +0000129 uint32_t& size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000130
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000131 uint32_t readSetEnd(shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000132
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000133 uint32_t readBool(shared_ptr<TTransport> in,
134 bool& value) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000135
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000136 uint32_t readByte(shared_ptr<TTransport> in,
Mark Sleecfc01932006-09-01 22:18:16 +0000137 int8_t& byte) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000138
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000139 uint32_t readI16(shared_ptr<TTransport> in,
140 int16_t& i16) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000141
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000142 uint32_t readI32(shared_ptr<TTransport> in,
143 int32_t& i32) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000144
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000145 uint32_t readI64(shared_ptr<TTransport> in,
146 int64_t& i64) const;
147
Mark Sleec98d0502006-09-06 02:42:25 +0000148 uint32_t readDouble(shared_ptr<TTransport> in,
149 double& dub) const;
150
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000151 uint32_t readString(shared_ptr<TTransport> in,
152 std::string& str) const;
Mark Sleee8540632006-05-30 09:24:40 +0000153};
154
Marc Slemko6f038a72006-08-03 18:58:09 +0000155}}} // facebook::thrift::protocol
156
Mark Sleef5f2be42006-09-05 21:05:31 +0000157#endif // #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_
158
Marc Slemko6f038a72006-08-03 18:58:09 +0000159