blob: e05bd9fc756c5b64009046c6804d117d482c7e0d [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
6/**
7 * The default binary protocol for thrift. Writes all data in a very basic
8 * binary format, essentially just spitting out the raw bytes.
9 *
10 * @author Mark Slee <mcslee@facebook.com>
11 */
12class TBinaryProtocol : public TProtocol {
13 public:
14 TBinaryProtocol() {}
15 ~TBinaryProtocol() {}
16
Mark Slee8d7e1f62006-06-07 06:48:56 +000017 /**
18 * Writing functions.
19 */
Mark Sleee8540632006-05-30 09:24:40 +000020
Mark Slee8d7e1f62006-06-07 06:48:56 +000021 uint32_t writeStructBegin (TTransport* out,
22 const std::string& name) const;
Mark Sleee8540632006-05-30 09:24:40 +000023
Mark Slee8d7e1f62006-06-07 06:48:56 +000024 uint32_t writeStructEnd (TTransport* out) const;
Mark Sleee8540632006-05-30 09:24:40 +000025
Mark Slee8d7e1f62006-06-07 06:48:56 +000026 uint32_t writeFieldBegin (TTransport* out,
27 const std::string& name,
28 const TType fieldType,
29 const uint16_t fieldId) const;
30
31 uint32_t writeFieldEnd (TTransport* out) const;
32
33 uint32_t writeFieldStop (TTransport* out) const;
34
35 uint32_t writeMapBegin (TTransport* out,
36 const TType keyType,
37 const TType valType,
38 const uint32_t size) const;
39
40 uint32_t writeMapEnd (TTransport* out) const;
41
42 uint32_t writeListBegin (TTransport* out,
43 const TType elemType,
44 const uint32_t size) const;
45
46 uint32_t writeListEnd (TTransport* out) const;
47
48 uint32_t writeSetBegin (TTransport* out,
49 const TType elemType,
50 const uint32_t size) const;
51
52 uint32_t writeSetEnd (TTransport* out) const;
53
54 uint32_t writeByte (TTransport* out,
55 const uint8_t byte) const;
56
57 uint32_t writeU32 (TTransport* out,
58 const uint32_t u32) const;
59
60 uint32_t writeI32 (TTransport* out,
61 const int32_t i32) const;
62
63 uint32_t writeU64 (TTransport* out,
64 const uint64_t u64) const;
65
66 uint32_t writeI64 (TTransport* out,
67 const int64_t i64) const;
68
69 uint32_t writeString (TTransport* out,
70 const std::string& str) const;
71
72 /**
73 * Reading functions
74 */
75
76 uint32_t readStructBegin (TTransport* in,
77 std::string& name) const;
78
79 uint32_t readStructEnd (TTransport* in) const;
80
81 uint32_t readFieldBegin (TTransport* in,
82 std::string& name,
83 TType& fieldType,
84 uint16_t& fieldId) const;
85
86 uint32_t readFieldEnd (TTransport* in) const;
87
88 uint32_t readMapBegin (TTransport* in,
89 TType& keyType,
90 TType& valType,
91 uint32_t& size) const;
92
93 uint32_t readMapEnd (TTransport* in) const;
94
95 uint32_t readListBegin (TTransport* in,
96 TType& elemType,
97 uint32_t& size) const;
98
99 uint32_t readListEnd (TTransport* in) const;
100
101 uint32_t readSetBegin (TTransport* in,
102 TType& elemType,
103 uint32_t& size) const;
104
105 uint32_t readSetEnd (TTransport* in) const;
106
107 uint32_t readByte (TTransport* in,
108 uint8_t& byte) const;
109
110 uint32_t readU32 (TTransport* in,
111 uint32_t& u32) const;
112
113 uint32_t readI32 (TTransport* in,
114 int32_t& i32) const;
115
116 uint32_t readU64 (TTransport* in,
117 uint64_t& u64) const;
118
119 uint32_t readI64 (TTransport* in,
120 int64_t& i64) const;
121
122 uint32_t readString (TTransport* in,
123 std::string& str) const;
124
Mark Sleee8540632006-05-30 09:24:40 +0000125};
126
127#endif