blob: 3456abf70893927ec59db1020cac4571317bd61b [file] [log] [blame]
Mark Sleee8540632006-05-30 09:24:40 +00001#ifndef T_BINARY_PROTOCOL_H
2#define T_BINARY_PROTOCOL_H
3
Marc Slemko16698852006-08-04 03:16:10 +00004#include <protocol/TProtocol.h>
5
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 */
18class TBinaryProtocol : public TProtocol {
Marc Slemko16698852006-08-04 03:16:10 +000019 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
31 virtual uint32_t writeMessageEnd (shared_ptr<TTransport> out) const;
32
33
34 uint32_t writeStructBegin (shared_ptr<TTransport> out,
Mark Slee8d7e1f62006-06-07 06:48:56 +000035 const std::string& name) const;
Mark Sleee8540632006-05-30 09:24:40 +000036
Marc Slemko16698852006-08-04 03:16:10 +000037 uint32_t writeStructEnd (shared_ptr<TTransport> out) const;
Mark Sleee8540632006-05-30 09:24:40 +000038
Marc Slemko16698852006-08-04 03:16:10 +000039 uint32_t writeFieldBegin (shared_ptr<TTransport> out,
Mark Slee8d7e1f62006-06-07 06:48:56 +000040 const std::string& name,
41 const TType fieldType,
42 const uint16_t fieldId) const;
43
Marc Slemko16698852006-08-04 03:16:10 +000044 uint32_t writeFieldEnd (shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000045
Marc Slemko16698852006-08-04 03:16:10 +000046 uint32_t writeFieldStop (shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000047
Marc Slemko16698852006-08-04 03:16:10 +000048 uint32_t writeMapBegin (shared_ptr<TTransport> out,
Mark Slee8d7e1f62006-06-07 06:48:56 +000049 const TType keyType,
50 const TType valType,
Mark Sleef3c322b2006-06-26 23:52:22 +000051 const int32_t size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000052
Marc Slemko16698852006-08-04 03:16:10 +000053 uint32_t writeMapEnd (shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000054
Marc Slemko16698852006-08-04 03:16:10 +000055 uint32_t writeListBegin (shared_ptr<TTransport> out,
Mark Slee8d7e1f62006-06-07 06:48:56 +000056 const TType elemType,
Mark Sleef3c322b2006-06-26 23:52:22 +000057 const int32_t size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000058
Marc Slemko16698852006-08-04 03:16:10 +000059 uint32_t writeListEnd (shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000060
Marc Slemko16698852006-08-04 03:16:10 +000061 uint32_t writeSetBegin (shared_ptr<TTransport> out,
Mark Slee8d7e1f62006-06-07 06:48:56 +000062 const TType elemType,
Mark Sleef3c322b2006-06-26 23:52:22 +000063 const int32_t size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000064
Marc Slemko16698852006-08-04 03:16:10 +000065 uint32_t writeSetEnd (shared_ptr<TTransport> out) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000066
Marc Slemko16698852006-08-04 03:16:10 +000067 uint32_t writeByte (shared_ptr<TTransport> out,
Mark Slee8d7e1f62006-06-07 06:48:56 +000068 const uint8_t byte) const;
69
Marc Slemko16698852006-08-04 03:16:10 +000070 uint32_t writeU32 (shared_ptr<TTransport> out,
Mark Slee8d7e1f62006-06-07 06:48:56 +000071 const uint32_t u32) const;
72
Marc Slemko16698852006-08-04 03:16:10 +000073 uint32_t writeI32 (shared_ptr<TTransport> out,
Mark Slee8d7e1f62006-06-07 06:48:56 +000074 const int32_t i32) const;
75
Marc Slemko16698852006-08-04 03:16:10 +000076 uint32_t writeU64 (shared_ptr<TTransport> out,
Mark Slee8d7e1f62006-06-07 06:48:56 +000077 const uint64_t u64) const;
78
Marc Slemko16698852006-08-04 03:16:10 +000079 uint32_t writeI64 (shared_ptr<TTransport> out,
Mark Slee8d7e1f62006-06-07 06:48:56 +000080 const int64_t i64) const;
81
Marc Slemko16698852006-08-04 03:16:10 +000082 uint32_t writeString (shared_ptr<TTransport> out,
Mark Slee8d7e1f62006-06-07 06:48:56 +000083 const std::string& str) const;
84
85 /**
86 * Reading functions
87 */
88
Marc Slemko16698852006-08-04 03:16:10 +000089
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 Slee8d7e1f62006-06-07 06:48:56 +000097 std::string& name) const;
98
Marc Slemko16698852006-08-04 03:16:10 +000099 uint32_t readStructEnd (shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000100
Marc Slemko16698852006-08-04 03:16:10 +0000101 uint32_t readFieldBegin (shared_ptr<TTransport> in,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000102 std::string& name,
103 TType& fieldType,
104 uint16_t& fieldId) const;
105
Marc Slemko16698852006-08-04 03:16:10 +0000106 uint32_t readFieldEnd (shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000107
Marc Slemko16698852006-08-04 03:16:10 +0000108 uint32_t readMapBegin (shared_ptr<TTransport> in,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000109 TType& keyType,
110 TType& valType,
Mark Sleef3c322b2006-06-26 23:52:22 +0000111 int32_t& size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000112
Marc Slemko16698852006-08-04 03:16:10 +0000113 uint32_t readMapEnd (shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000114
Marc Slemko16698852006-08-04 03:16:10 +0000115 uint32_t readListBegin (shared_ptr<TTransport> in,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000116 TType& elemType,
Mark Sleef3c322b2006-06-26 23:52:22 +0000117 int32_t& size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000118
Marc Slemko16698852006-08-04 03:16:10 +0000119 uint32_t readListEnd (shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000120
Marc Slemko16698852006-08-04 03:16:10 +0000121 uint32_t readSetBegin (shared_ptr<TTransport> in,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000122 TType& elemType,
Mark Sleef3c322b2006-06-26 23:52:22 +0000123 int32_t& size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000124
Marc Slemko16698852006-08-04 03:16:10 +0000125 uint32_t readSetEnd (shared_ptr<TTransport> in) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000126
Marc Slemko16698852006-08-04 03:16:10 +0000127 uint32_t readByte (shared_ptr<TTransport> in,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000128 uint8_t& byte) const;
129
Marc Slemko16698852006-08-04 03:16:10 +0000130 uint32_t readU32 (shared_ptr<TTransport> in,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000131 uint32_t& u32) const;
132
Marc Slemko16698852006-08-04 03:16:10 +0000133 uint32_t readI32 (shared_ptr<TTransport> in,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000134 int32_t& i32) const;
135
Marc Slemko16698852006-08-04 03:16:10 +0000136 uint32_t readU64 (shared_ptr<TTransport> in,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000137 uint64_t& u64) const;
138
Marc Slemko16698852006-08-04 03:16:10 +0000139 uint32_t readI64 (shared_ptr<TTransport> in,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000140 int64_t& i64) const;
141
Marc Slemko16698852006-08-04 03:16:10 +0000142 uint32_t readString (shared_ptr<TTransport> in,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000143 std::string& str) const;
144
Mark Sleee8540632006-05-30 09:24:40 +0000145};
146
Marc Slemko6f038a72006-08-03 18:58:09 +0000147}}} // facebook::thrift::protocol
148
Mark Sleee8540632006-05-30 09:24:40 +0000149#endif
Marc Slemko6f038a72006-08-03 18:58:09 +0000150