blob: 3c31d1e418a7feeec44195b4c71418f96e1e1a76 [file] [log] [blame]
David Reiss00dcccf2007-07-21 01:18:10 +00001// Copyright (c) 2006- Facebook
2// Distributed under the Thrift Software License
3//
4// See accompanying file LICENSE or visit the Thrift site at:
5// http://developers.facebook.com/thrift/
6
7#ifndef _THRIFT_PROTOCOL_TONEWAYPROTOCOL_H_
8#define _THRIFT_PROTOCOL_TONEWAYPROTOCOL_H_ 1
9
10#include "TProtocol.h"
11
David Reiss0c90f6f2008-02-06 22:18:40 +000012namespace facebook { namespace thrift { namespace protocol {
David Reiss00dcccf2007-07-21 01:18:10 +000013
14/**
15 * Abstract class for implementing a protocol that can only be written,
16 * not read.
17 *
18 * @author David Reiss <dreiss@facebook.com>
19 */
20class TWriteOnlyProtocol : public TProtocol {
21 public:
22 /**
23 * @param subclass_name The name of the concrete subclass.
24 */
25 TWriteOnlyProtocol(boost::shared_ptr<TTransport> trans,
26 const std::string& subclass_name)
27 : TProtocol(trans)
28 , subclass_(subclass_name)
29 {}
30
31 // All writing functions remain abstract.
32
33 /**
34 * Reading functions all throw an exception.
35 */
36
37 uint32_t readMessageBegin(std::string& name,
David Reiss96d23882007-07-26 21:10:32 +000038 TMessageType& messageType,
39 int32_t& seqid) {
David Reiss00dcccf2007-07-21 01:18:10 +000040 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
41 subclass_ + " does not support reading (yet).");
42 }
43
44 uint32_t readMessageEnd() {
45 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
46 subclass_ + " does not support reading (yet).");
47 }
48
49 uint32_t readStructBegin(std::string& name) {
50 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
51 subclass_ + " does not support reading (yet).");
52 }
53
54 uint32_t readStructEnd() {
55 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
56 subclass_ + " does not support reading (yet).");
57 }
58
59 uint32_t readFieldBegin(std::string& name,
David Reiss96d23882007-07-26 21:10:32 +000060 TType& fieldType,
61 int16_t& fieldId) {
David Reiss00dcccf2007-07-21 01:18:10 +000062 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
63 subclass_ + " does not support reading (yet).");
64 }
David Reiss0c90f6f2008-02-06 22:18:40 +000065
David Reiss00dcccf2007-07-21 01:18:10 +000066 uint32_t readFieldEnd() {
67 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
68 subclass_ + " does not support reading (yet).");
69 }
David Reiss0c90f6f2008-02-06 22:18:40 +000070
David Reiss00dcccf2007-07-21 01:18:10 +000071 uint32_t readMapBegin(TType& keyType,
David Reiss96d23882007-07-26 21:10:32 +000072 TType& valType,
73 uint32_t& size) {
David Reiss00dcccf2007-07-21 01:18:10 +000074 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
75 subclass_ + " does not support reading (yet).");
76 }
77
78 uint32_t readMapEnd() {
79 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
80 subclass_ + " does not support reading (yet).");
81 }
82
83 uint32_t readListBegin(TType& elemType,
84 uint32_t& size) {
85 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
86 subclass_ + " does not support reading (yet).");
87 }
David Reiss0c90f6f2008-02-06 22:18:40 +000088
David Reiss00dcccf2007-07-21 01:18:10 +000089 uint32_t readListEnd() {
90 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
91 subclass_ + " does not support reading (yet).");
92 }
93
94 uint32_t readSetBegin(TType& elemType,
David Reiss96d23882007-07-26 21:10:32 +000095 uint32_t& size) {
David Reiss00dcccf2007-07-21 01:18:10 +000096 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
97 subclass_ + " does not support reading (yet).");
98 }
99
100 uint32_t readSetEnd() {
101 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
102 subclass_ + " does not support reading (yet).");
103 }
104
105 uint32_t readBool(bool& value) {
106 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
107 subclass_ + " does not support reading (yet).");
108 }
109
110 uint32_t readByte(int8_t& byte) {
111 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
112 subclass_ + " does not support reading (yet).");
113 }
114
115 uint32_t readI16(int16_t& i16) {
116 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
117 subclass_ + " does not support reading (yet).");
118 }
119
120 uint32_t readI32(int32_t& i32) {
121 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
122 subclass_ + " does not support reading (yet).");
123 }
124
125 uint32_t readI64(int64_t& i64) {
126 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
127 subclass_ + " does not support reading (yet).");
128 }
129
130 uint32_t readDouble(double& dub) {
131 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
132 subclass_ + " does not support reading (yet).");
133 }
134
135 uint32_t readString(std::string& str) {
136 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
137 subclass_ + " does not support reading (yet).");
138 }
139
David Reissc005b1b2008-02-15 01:38:18 +0000140 uint32_t readBinary(std::string& str) {
141 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
142 subclass_ + " does not support reading (yet).");
143 }
David Reiss00dcccf2007-07-21 01:18:10 +0000144
145 private:
146 std::string subclass_;
147};
148
David Reisse0e3d1b2008-04-08 05:06:45 +0000149
150/**
151 * Abstract class for implementing a protocol that can only be read,
152 * not written.
153 *
154 * @author David Reiss <dreiss@facebook.com>
155 */
156class TReadOnlyProtocol : public TProtocol {
157 public:
158 /**
159 * @param subclass_name The name of the concrete subclass.
160 */
161 TReadOnlyProtocol(boost::shared_ptr<TTransport> trans,
162 const std::string& subclass_name)
163 : TProtocol(trans)
164 , subclass_(subclass_name)
165 {}
166
167 // All reading functions remain abstract.
168
169 /**
170 * Writing functions all throw an exception.
171 */
172
173 uint32_t writeMessageBegin(const std::string& name,
174 const TMessageType messageType,
175 const int32_t seqid) {
176 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
177 subclass_ + " does not support writing (yet).");
178 }
179
180 uint32_t writeMessageEnd() {
181 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
182 subclass_ + " does not support writing (yet).");
183 }
184
185
186 uint32_t writeStructBegin(const std::string& name) {
187 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
188 subclass_ + " does not support writing (yet).");
189 }
190
191 uint32_t writeStructEnd() {
192 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
193 subclass_ + " does not support writing (yet).");
194 }
195
196 uint32_t writeFieldBegin(const std::string& name,
197 const TType fieldType,
198 const int16_t fieldId) {
199 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
200 subclass_ + " does not support writing (yet).");
201 }
202
203 uint32_t writeFieldEnd() {
204 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
205 subclass_ + " does not support writing (yet).");
206 }
207
208 uint32_t writeFieldStop() {
209 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
210 subclass_ + " does not support writing (yet).");
211 }
212
213 uint32_t writeMapBegin(const TType keyType,
214 const TType valType,
215 const uint32_t size) {
216 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
217 subclass_ + " does not support writing (yet).");
218 }
219
220 uint32_t writeMapEnd() {
221 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
222 subclass_ + " does not support writing (yet).");
223 }
224
225 uint32_t writeListBegin(const TType elemType,
226 const uint32_t size) {
227 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
228 subclass_ + " does not support writing (yet).");
229 }
230
231 uint32_t writeListEnd() {
232 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
233 subclass_ + " does not support writing (yet).");
234 }
235
236 uint32_t writeSetBegin(const TType elemType,
237 const uint32_t size) {
238 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
239 subclass_ + " does not support writing (yet).");
240 }
241
242 uint32_t writeSetEnd() {
243 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
244 subclass_ + " does not support writing (yet).");
245 }
246
247 uint32_t writeBool(const bool value) {
248 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
249 subclass_ + " does not support writing (yet).");
250 }
251
252 uint32_t writeByte(const int8_t byte) {
253 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
254 subclass_ + " does not support writing (yet).");
255 }
256
257 uint32_t writeI16(const int16_t i16) {
258 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
259 subclass_ + " does not support writing (yet).");
260 }
261
262 uint32_t writeI32(const int32_t i32) {
263 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
264 subclass_ + " does not support writing (yet).");
265 }
266
267 uint32_t writeI64(const int64_t i64) {
268 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
269 subclass_ + " does not support writing (yet).");
270 }
271
272 uint32_t writeDouble(const double dub) {
273 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
274 subclass_ + " does not support writing (yet).");
275 }
276
277 uint32_t writeString(const std::string& str) {
278 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
279 subclass_ + " does not support writing (yet).");
280 }
281
282 uint32_t writeBinary(const std::string& str) {
283 throw TProtocolException(TProtocolException::NOT_IMPLEMENTED,
284 subclass_ + " does not support writing (yet).");
285 }
286
287 private:
288 std::string subclass_;
289};
290
David Reiss00dcccf2007-07-21 01:18:10 +0000291}}} // facebook::thrift::protocol
292
293#endif // #ifndef _THRIFT_PROTOCOL_TBINARYPROTOCOL_H_