blob: 0f0560a1caba5fd9e27f1165e0a8acfdaed5a787 [file] [log] [blame]
Mark Sleee8540632006-05-30 09:24:40 +00001#ifndef T_BINARY_PROTOCOL_H
2#define T_BINARY_PROTOCOL_H
3
4#include "protocol/TProtocol.h"
5
Marc Slemko6f038a72006-08-03 18:58:09 +00006namespace facebook { namespace thrift { namespace protocol {
7
Mark Sleee8540632006-05-30 09:24:40 +00008/**
9 * The default binary protocol for thrift. Writes all data in a very basic
10 * binary format, essentially just spitting out the raw bytes.
11 *
12 * @author Mark Slee <mcslee@facebook.com>
13 */
14class TBinaryProtocol : public TProtocol {
15 public:
16 TBinaryProtocol() {}
17 ~TBinaryProtocol() {}
18
Mark Slee8d7e1f62006-06-07 06:48:56 +000019 /**
20 * Writing functions.
21 */
Mark Sleee8540632006-05-30 09:24:40 +000022
Mark Slee8d7e1f62006-06-07 06:48:56 +000023 uint32_t writeStructBegin (TTransport* out,
24 const std::string& name) const;
Mark Sleee8540632006-05-30 09:24:40 +000025
Mark Slee8d7e1f62006-06-07 06:48:56 +000026 uint32_t writeStructEnd (TTransport* out) const;
Mark Sleee8540632006-05-30 09:24:40 +000027
Mark Slee8d7e1f62006-06-07 06:48:56 +000028 uint32_t writeFieldBegin (TTransport* out,
29 const std::string& name,
30 const TType fieldType,
31 const uint16_t fieldId) const;
32
33 uint32_t writeFieldEnd (TTransport* out) const;
34
35 uint32_t writeFieldStop (TTransport* out) const;
36
37 uint32_t writeMapBegin (TTransport* out,
38 const TType keyType,
39 const TType valType,
Mark Sleef3c322b2006-06-26 23:52:22 +000040 const int32_t size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000041
42 uint32_t writeMapEnd (TTransport* out) const;
43
44 uint32_t writeListBegin (TTransport* out,
45 const TType elemType,
Mark Sleef3c322b2006-06-26 23:52:22 +000046 const int32_t size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000047
48 uint32_t writeListEnd (TTransport* out) const;
49
50 uint32_t writeSetBegin (TTransport* out,
51 const TType elemType,
Mark Sleef3c322b2006-06-26 23:52:22 +000052 const int32_t size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000053
54 uint32_t writeSetEnd (TTransport* out) const;
55
56 uint32_t writeByte (TTransport* out,
57 const uint8_t byte) const;
58
59 uint32_t writeU32 (TTransport* out,
60 const uint32_t u32) const;
61
62 uint32_t writeI32 (TTransport* out,
63 const int32_t i32) const;
64
65 uint32_t writeU64 (TTransport* out,
66 const uint64_t u64) const;
67
68 uint32_t writeI64 (TTransport* out,
69 const int64_t i64) const;
70
71 uint32_t writeString (TTransport* out,
72 const std::string& str) const;
73
74 /**
75 * Reading functions
76 */
77
78 uint32_t readStructBegin (TTransport* in,
79 std::string& name) const;
80
81 uint32_t readStructEnd (TTransport* in) const;
82
83 uint32_t readFieldBegin (TTransport* in,
84 std::string& name,
85 TType& fieldType,
86 uint16_t& fieldId) const;
87
88 uint32_t readFieldEnd (TTransport* in) const;
89
90 uint32_t readMapBegin (TTransport* in,
91 TType& keyType,
92 TType& valType,
Mark Sleef3c322b2006-06-26 23:52:22 +000093 int32_t& size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +000094
95 uint32_t readMapEnd (TTransport* in) const;
96
97 uint32_t readListBegin (TTransport* in,
98 TType& elemType,
Mark Sleef3c322b2006-06-26 23:52:22 +000099 int32_t& size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000100
101 uint32_t readListEnd (TTransport* in) const;
102
103 uint32_t readSetBegin (TTransport* in,
104 TType& elemType,
Mark Sleef3c322b2006-06-26 23:52:22 +0000105 int32_t& size) const;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000106
107 uint32_t readSetEnd (TTransport* in) const;
108
109 uint32_t readByte (TTransport* in,
110 uint8_t& byte) const;
111
112 uint32_t readU32 (TTransport* in,
113 uint32_t& u32) const;
114
115 uint32_t readI32 (TTransport* in,
116 int32_t& i32) const;
117
118 uint32_t readU64 (TTransport* in,
119 uint64_t& u64) const;
120
121 uint32_t readI64 (TTransport* in,
122 int64_t& i64) const;
123
124 uint32_t readString (TTransport* in,
125 std::string& str) const;
126
Mark Sleee8540632006-05-30 09:24:40 +0000127};
128
Marc Slemko6f038a72006-08-03 18:58:09 +0000129}}} // facebook::thrift::protocol
130
Mark Sleee8540632006-05-30 09:24:40 +0000131#endif
Marc Slemko6f038a72006-08-03 18:58:09 +0000132