blob: 2a922c79e0063e55ab0565182fe050ccc5e6f633 [file] [log] [blame]
David Reissea2cba82009-03-30 21:35:00 +00001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
Mark Slee9f0c6512007-02-28 23:58:26 +000019
Mark Sleef5f2be42006-09-05 21:05:31 +000020#ifndef _THRIFT_PROTOCOL_TPROTOCOL_H_
21#define _THRIFT_PROTOCOL_TPROTOCOL_H_ 1
Mark Sleee8540632006-05-30 09:24:40 +000022
Marc Slemko16698852006-08-04 03:16:10 +000023#include <transport/TTransport.h>
Mark Sleef9831082007-02-20 20:59:21 +000024#include <protocol/TProtocolException.h>
Marc Slemko16698852006-08-04 03:16:10 +000025
26#include <boost/shared_ptr.hpp>
David Reisse4d4ea02009-04-02 21:37:17 +000027#include <boost/static_assert.hpp>
Marc Slemko16698852006-08-04 03:16:10 +000028
Mark Slee8d7e1f62006-06-07 06:48:56 +000029#include <netinet/in.h>
Mark Sleee8540632006-05-30 09:24:40 +000030#include <sys/types.h>
31#include <string>
32#include <map>
David Reiss8dfc7322010-10-06 17:09:58 +000033#include <vector>
Mark Sleee8540632006-05-30 09:24:40 +000034
David Reisse4d4ea02009-04-02 21:37:17 +000035
36// Use this to get around strict aliasing rules.
37// For example, uint64_t i = bitwise_cast<uint64_t>(returns_double());
38// The most obvious implementation is to just cast a pointer,
39// but that doesn't work.
40// For a pretty in-depth explanation of the problem, see
41// http://www.cellperformance.com/mike_acton/2006/06/ (...)
42// understanding_strict_aliasing.html
43template <typename To, typename From>
44static inline To bitwise_cast(From from) {
45 BOOST_STATIC_ASSERT(sizeof(From) == sizeof(To));
46
47 // BAD!!! These are all broken with -O2.
48 //return *reinterpret_cast<To*>(&from); // BAD!!!
49 //return *static_cast<To*>(static_cast<void*>(&from)); // BAD!!!
50 //return *(To*)(void*)&from; // BAD!!!
51
52 // Super clean and paritally blessed by section 3.9 of the standard.
53 //unsigned char c[sizeof(from)];
54 //memcpy(c, &from, sizeof(from));
55 //To to;
56 //memcpy(&to, c, sizeof(c));
57 //return to;
58
59 // Slightly more questionable.
60 // Same code emitted by GCC.
61 //To to;
62 //memcpy(&to, &from, sizeof(from));
63 //return to;
64
65 // Technically undefined, but almost universally supported,
66 // and the most efficient implementation.
67 union {
68 From f;
69 To t;
70 } u;
71 u.f = from;
72 return u.t;
73}
74
75
T Jake Lucianib5e62212009-01-31 22:36:20 +000076namespace apache { namespace thrift { namespace protocol {
Marc Slemko6f038a72006-08-03 18:58:09 +000077
T Jake Lucianib5e62212009-01-31 22:36:20 +000078using apache::thrift::transport::TTransport;
Marc Slemko6f038a72006-08-03 18:58:09 +000079
Bryan Duxbury184d2622010-08-17 17:43:58 +000080#ifdef HAVE_SYS_PARAM_H_
81#include <sys/param.h>
Mark Slee4f261c52007-04-13 00:33:24 +000082#endif
83
Mark Slee1d2ead32007-06-09 01:23:04 +000084#ifndef __BYTE_ORDER
85# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
86# define __BYTE_ORDER BYTE_ORDER
87# define __LITTLE_ENDIAN LITTLE_ENDIAN
88# define __BIG_ENDIAN BIG_ENDIAN
89# else
David Reiss9b903442009-10-21 05:51:28 +000090# include <boost/config.hpp>
91# define __BYTE_ORDER BOOST_BYTE_ORDER
92# define __LITTLE_ENDIAN BOOST_LITTLE_ENDIAN
93# define __BIG_ENDIAN BOOST_BIG_ENDIAN
Mark Slee1d2ead32007-06-09 01:23:04 +000094# endif
95#endif
96
Mark Sleedc8a2a22006-09-19 22:20:18 +000097#if __BYTE_ORDER == __BIG_ENDIAN
David Reisse4d4ea02009-04-02 21:37:17 +000098# define ntohll(n) (n)
99# define htonll(n) (n)
100# if defined(__GNUC__) && defined(__GLIBC__)
101# include <byteswap.h>
102# define htolell(n) bswap_64(n)
103# define letohll(n) bswap_64(n)
104# else /* GNUC & GLIBC */
105# define bswap_64(n) \
106 ( (((n) & 0xff00000000000000ull) >> 56) \
107 | (((n) & 0x00ff000000000000ull) >> 40) \
108 | (((n) & 0x0000ff0000000000ull) >> 24) \
109 | (((n) & 0x000000ff00000000ull) >> 8) \
110 | (((n) & 0x00000000ff000000ull) << 8) \
111 | (((n) & 0x0000000000ff0000ull) << 24) \
112 | (((n) & 0x000000000000ff00ull) << 40) \
113 | (((n) & 0x00000000000000ffull) << 56) )
David Reiss30297862009-08-05 16:42:59 +0000114# define htolell(n) bswap_64(n)
115# define letohll(n) bswap_64(n)
David Reisse4d4ea02009-04-02 21:37:17 +0000116# endif /* GNUC & GLIBC */
Mark Slee4f261c52007-04-13 00:33:24 +0000117#elif __BYTE_ORDER == __LITTLE_ENDIAN
David Reisse4d4ea02009-04-02 21:37:17 +0000118# define htolell(n) (n)
119# define letohll(n) (n)
Mark Slee4f261c52007-04-13 00:33:24 +0000120# if defined(__GNUC__) && defined(__GLIBC__)
121# include <byteswap.h>
122# define ntohll(n) bswap_64(n)
123# define htonll(n) bswap_64(n)
124# else /* GNUC & GLIBC */
Roger Meier5f9614c2010-11-21 16:59:05 +0000125# define ntohll(n) ( (((uint64_t)ntohl(n)) << 32) + ntohl(n >> 32) )
126# define htonll(n) ( (((uint64_t)htonl(n)) << 32) + htonl(n >> 32) )
Mark Slee4f261c52007-04-13 00:33:24 +0000127# endif /* GNUC & GLIBC */
128#else /* __BYTE_ORDER */
129# error "Can't define htonll or ntohll!"
Mark Sleedc8a2a22006-09-19 22:20:18 +0000130#endif
Mark Slee8d7e1f62006-06-07 06:48:56 +0000131
Mark Sleee8540632006-05-30 09:24:40 +0000132/**
Mark Slee8d7e1f62006-06-07 06:48:56 +0000133 * Enumerated definition of the types that the Thrift protocol supports.
134 * Take special note of the T_END type which is used specifically to mark
135 * the end of a sequence of fields.
136 */
137enum TType {
Marc Slemkod42a2c22006-08-10 03:30:18 +0000138 T_STOP = 0,
Marc Slemko5b126d62006-08-11 23:03:42 +0000139 T_VOID = 1,
140 T_BOOL = 2,
141 T_BYTE = 3,
Mark Sleecfc01932006-09-01 22:18:16 +0000142 T_I08 = 3,
Marc Slemko5b126d62006-08-11 23:03:42 +0000143 T_I16 = 6,
Marc Slemko5b126d62006-08-11 23:03:42 +0000144 T_I32 = 8,
145 T_U64 = 9,
146 T_I64 = 10,
Mark Sleec98d0502006-09-06 02:42:25 +0000147 T_DOUBLE = 4,
Marc Slemko5b126d62006-08-11 23:03:42 +0000148 T_STRING = 11,
Marc Slemkod97eb612006-08-24 23:37:36 +0000149 T_UTF7 = 11,
150 T_STRUCT = 12,
151 T_MAP = 13,
152 T_SET = 14,
153 T_LIST = 15,
154 T_UTF8 = 16,
155 T_UTF16 = 17
Mark Slee8d7e1f62006-06-07 06:48:56 +0000156};
157
158/**
Mark Sleef5f2be42006-09-05 21:05:31 +0000159 * Enumerated definition of the message types that the Thrift protocol
160 * supports.
Marc Slemko16698852006-08-04 03:16:10 +0000161 */
162enum TMessageType {
163 T_CALL = 1,
Mark Sleef9831082007-02-20 20:59:21 +0000164 T_REPLY = 2,
David Reissdeda1412009-04-02 19:22:31 +0000165 T_EXCEPTION = 3,
166 T_ONEWAY = 4
Marc Slemko16698852006-08-04 03:16:10 +0000167};
168
David Reiss6806fb82010-10-06 17:09:52 +0000169
170/**
171 * Helper template for implementing TProtocol::skip().
172 *
173 * Templatized to avoid having to make virtual function calls.
174 */
175template <class Protocol_>
176uint32_t skip(Protocol_& prot, TType type) {
177 switch (type) {
178 case T_BOOL:
179 {
180 bool boolv;
181 return prot.readBool(boolv);
182 }
183 case T_BYTE:
184 {
185 int8_t bytev;
186 return prot.readByte(bytev);
187 }
188 case T_I16:
189 {
190 int16_t i16;
191 return prot.readI16(i16);
192 }
193 case T_I32:
194 {
195 int32_t i32;
196 return prot.readI32(i32);
197 }
198 case T_I64:
199 {
200 int64_t i64;
201 return prot.readI64(i64);
202 }
203 case T_DOUBLE:
204 {
205 double dub;
206 return prot.readDouble(dub);
207 }
208 case T_STRING:
209 {
210 std::string str;
211 return prot.readBinary(str);
212 }
213 case T_STRUCT:
214 {
215 uint32_t result = 0;
216 std::string name;
217 int16_t fid;
218 TType ftype;
219 result += prot.readStructBegin(name);
220 while (true) {
221 result += prot.readFieldBegin(name, ftype, fid);
222 if (ftype == T_STOP) {
223 break;
224 }
225 result += skip(prot, ftype);
226 result += prot.readFieldEnd();
227 }
228 result += prot.readStructEnd();
229 return result;
230 }
231 case T_MAP:
232 {
233 uint32_t result = 0;
234 TType keyType;
235 TType valType;
236 uint32_t i, size;
237 result += prot.readMapBegin(keyType, valType, size);
238 for (i = 0; i < size; i++) {
239 result += skip(prot, keyType);
240 result += skip(prot, valType);
241 }
242 result += prot.readMapEnd();
243 return result;
244 }
245 case T_SET:
246 {
247 uint32_t result = 0;
248 TType elemType;
249 uint32_t i, size;
250 result += prot.readSetBegin(elemType, size);
251 for (i = 0; i < size; i++) {
252 result += skip(prot, elemType);
253 }
254 result += prot.readSetEnd();
255 return result;
256 }
257 case T_LIST:
258 {
259 uint32_t result = 0;
260 TType elemType;
261 uint32_t i, size;
262 result += prot.readListBegin(elemType, size);
263 for (i = 0; i < size; i++) {
264 result += skip(prot, elemType);
265 }
266 result += prot.readListEnd();
267 return result;
268 }
Roger Meierc0b5d902010-11-30 20:23:44 +0000269 case T_STOP: case T_VOID: case T_U64: case T_UTF8: case T_UTF16:
270 break;
David Reiss6806fb82010-10-06 17:09:52 +0000271 }
Roger Meierc0b5d902010-11-30 20:23:44 +0000272 return 0;
David Reiss6806fb82010-10-06 17:09:52 +0000273}
274
Marc Slemko16698852006-08-04 03:16:10 +0000275/**
Mark Sleee8540632006-05-30 09:24:40 +0000276 * Abstract class for a thrift protocol driver. These are all the methods that
277 * a protocol must implement. Essentially, there must be some way of reading
278 * and writing all the base types, plus a mechanism for writing out structs
Mark Slee5d06fea2007-03-05 22:18:18 +0000279 * with indexed fields.
280 *
281 * TProtocol objects should not be shared across multiple encoding contexts,
282 * as they may need to maintain internal state in some protocols (i.e. XML).
283 * Note that is is acceptable for the TProtocol module to do its own internal
284 * buffered reads/writes to the underlying TTransport where appropriate (i.e.
285 * when parsing an input XML stream, reading should be batched rather than
286 * looking ahead character by character for a close tag).
Mark Sleee8540632006-05-30 09:24:40 +0000287 *
Mark Sleee8540632006-05-30 09:24:40 +0000288 */
289class TProtocol {
290 public:
291 virtual ~TProtocol() {}
292
293 /**
Mark Slee8d7e1f62006-06-07 06:48:56 +0000294 * Writing functions.
Mark Sleee8540632006-05-30 09:24:40 +0000295 */
296
David Reiss6806fb82010-10-06 17:09:52 +0000297 virtual uint32_t writeMessageBegin_virt(const std::string& name,
298 const TMessageType messageType,
299 const int32_t seqid) = 0;
Marc Slemko16698852006-08-04 03:16:10 +0000300
David Reiss6806fb82010-10-06 17:09:52 +0000301 virtual uint32_t writeMessageEnd_virt() = 0;
Marc Slemko16698852006-08-04 03:16:10 +0000302
303
David Reiss6806fb82010-10-06 17:09:52 +0000304 virtual uint32_t writeStructBegin_virt(const char* name) = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000305
David Reiss6806fb82010-10-06 17:09:52 +0000306 virtual uint32_t writeStructEnd_virt() = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000307
David Reiss6806fb82010-10-06 17:09:52 +0000308 virtual uint32_t writeFieldBegin_virt(const char* name,
309 const TType fieldType,
310 const int16_t fieldId) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000311
David Reiss6806fb82010-10-06 17:09:52 +0000312 virtual uint32_t writeFieldEnd_virt() = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000313
David Reiss6806fb82010-10-06 17:09:52 +0000314 virtual uint32_t writeFieldStop_virt() = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000315
David Reiss6806fb82010-10-06 17:09:52 +0000316 virtual uint32_t writeMapBegin_virt(const TType keyType,
317 const TType valType,
318 const uint32_t size) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000319
David Reiss6806fb82010-10-06 17:09:52 +0000320 virtual uint32_t writeMapEnd_virt() = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000321
David Reiss6806fb82010-10-06 17:09:52 +0000322 virtual uint32_t writeListBegin_virt(const TType elemType,
323 const uint32_t size) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000324
David Reiss6806fb82010-10-06 17:09:52 +0000325 virtual uint32_t writeListEnd_virt() = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000326
David Reiss6806fb82010-10-06 17:09:52 +0000327 virtual uint32_t writeSetBegin_virt(const TType elemType,
328 const uint32_t size) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000329
David Reiss6806fb82010-10-06 17:09:52 +0000330 virtual uint32_t writeSetEnd_virt() = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000331
David Reiss6806fb82010-10-06 17:09:52 +0000332 virtual uint32_t writeBool_virt(const bool value) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000333
David Reiss6806fb82010-10-06 17:09:52 +0000334 virtual uint32_t writeByte_virt(const int8_t byte) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000335
David Reiss6806fb82010-10-06 17:09:52 +0000336 virtual uint32_t writeI16_virt(const int16_t i16) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000337
David Reiss6806fb82010-10-06 17:09:52 +0000338 virtual uint32_t writeI32_virt(const int32_t i32) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000339
David Reiss6806fb82010-10-06 17:09:52 +0000340 virtual uint32_t writeI64_virt(const int64_t i64) = 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000341
David Reiss6806fb82010-10-06 17:09:52 +0000342 virtual uint32_t writeDouble_virt(const double dub) = 0;
Mark Sleec98d0502006-09-06 02:42:25 +0000343
David Reiss6806fb82010-10-06 17:09:52 +0000344 virtual uint32_t writeString_virt(const std::string& str) = 0;
Mark Sleee8540632006-05-30 09:24:40 +0000345
David Reiss6806fb82010-10-06 17:09:52 +0000346 virtual uint32_t writeBinary_virt(const std::string& str) = 0;
347
348 uint32_t writeMessageBegin(const std::string& name,
349 const TMessageType messageType,
350 const int32_t seqid) {
351 T_VIRTUAL_CALL();
352 return writeMessageBegin_virt(name, messageType, seqid);
353 }
354
355 uint32_t writeMessageEnd() {
356 T_VIRTUAL_CALL();
357 return writeMessageEnd_virt();
358 }
359
360
361 uint32_t writeStructBegin(const char* name) {
362 T_VIRTUAL_CALL();
363 return writeStructBegin_virt(name);
364 }
365
366 uint32_t writeStructEnd() {
367 T_VIRTUAL_CALL();
368 return writeStructEnd_virt();
369 }
370
371 uint32_t writeFieldBegin(const char* name,
372 const TType fieldType,
373 const int16_t fieldId) {
374 T_VIRTUAL_CALL();
375 return writeFieldBegin_virt(name, fieldType, fieldId);
376 }
377
378 uint32_t writeFieldEnd() {
379 T_VIRTUAL_CALL();
380 return writeFieldEnd_virt();
381 }
382
383 uint32_t writeFieldStop() {
384 T_VIRTUAL_CALL();
385 return writeFieldStop_virt();
386 }
387
388 uint32_t writeMapBegin(const TType keyType,
389 const TType valType,
390 const uint32_t size) {
391 T_VIRTUAL_CALL();
392 return writeMapBegin_virt(keyType, valType, size);
393 }
394
395 uint32_t writeMapEnd() {
396 T_VIRTUAL_CALL();
397 return writeMapEnd_virt();
398 }
399
400 uint32_t writeListBegin(const TType elemType, const uint32_t size) {
401 T_VIRTUAL_CALL();
402 return writeListBegin_virt(elemType, size);
403 }
404
405 uint32_t writeListEnd() {
406 T_VIRTUAL_CALL();
407 return writeListEnd_virt();
408 }
409
410 uint32_t writeSetBegin(const TType elemType, const uint32_t size) {
411 T_VIRTUAL_CALL();
412 return writeSetBegin_virt(elemType, size);
413 }
414
415 uint32_t writeSetEnd() {
416 T_VIRTUAL_CALL();
417 return writeSetEnd_virt();
418 }
419
420 uint32_t writeBool(const bool value) {
421 T_VIRTUAL_CALL();
422 return writeBool_virt(value);
423 }
424
425 uint32_t writeByte(const int8_t byte) {
426 T_VIRTUAL_CALL();
427 return writeByte_virt(byte);
428 }
429
430 uint32_t writeI16(const int16_t i16) {
431 T_VIRTUAL_CALL();
432 return writeI16_virt(i16);
433 }
434
435 uint32_t writeI32(const int32_t i32) {
436 T_VIRTUAL_CALL();
437 return writeI32_virt(i32);
438 }
439
440 uint32_t writeI64(const int64_t i64) {
441 T_VIRTUAL_CALL();
442 return writeI64_virt(i64);
443 }
444
445 uint32_t writeDouble(const double dub) {
446 T_VIRTUAL_CALL();
447 return writeDouble_virt(dub);
448 }
449
450 uint32_t writeString(const std::string& str) {
451 T_VIRTUAL_CALL();
452 return writeString_virt(str);
453 }
454
455 uint32_t writeBinary(const std::string& str) {
456 T_VIRTUAL_CALL();
457 return writeBinary_virt(str);
458 }
David Reissc005b1b2008-02-15 01:38:18 +0000459
Mark Sleee8540632006-05-30 09:24:40 +0000460 /**
Mark Slee8d7e1f62006-06-07 06:48:56 +0000461 * Reading functions
Mark Sleee8540632006-05-30 09:24:40 +0000462 */
463
David Reiss6806fb82010-10-06 17:09:52 +0000464 virtual uint32_t readMessageBegin_virt(std::string& name,
465 TMessageType& messageType,
466 int32_t& seqid) = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000467
David Reiss6806fb82010-10-06 17:09:52 +0000468 virtual uint32_t readMessageEnd_virt() = 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000469
David Reiss6806fb82010-10-06 17:09:52 +0000470 virtual uint32_t readStructBegin_virt(std::string& name) = 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000471
David Reiss6806fb82010-10-06 17:09:52 +0000472 virtual uint32_t readStructEnd_virt() = 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000473
David Reiss6806fb82010-10-06 17:09:52 +0000474 virtual uint32_t readFieldBegin_virt(std::string& name,
475 TType& fieldType,
476 int16_t& fieldId) = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000477
David Reiss6806fb82010-10-06 17:09:52 +0000478 virtual uint32_t readFieldEnd_virt() = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000479
David Reiss6806fb82010-10-06 17:09:52 +0000480 virtual uint32_t readMapBegin_virt(TType& keyType,
481 TType& valType,
482 uint32_t& size) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000483
David Reiss6806fb82010-10-06 17:09:52 +0000484 virtual uint32_t readMapEnd_virt() = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000485
David Reiss6806fb82010-10-06 17:09:52 +0000486 virtual uint32_t readListBegin_virt(TType& elemType,
487 uint32_t& size) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000488
David Reiss6806fb82010-10-06 17:09:52 +0000489 virtual uint32_t readListEnd_virt() = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000490
David Reiss6806fb82010-10-06 17:09:52 +0000491 virtual uint32_t readSetBegin_virt(TType& elemType,
492 uint32_t& size) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000493
David Reiss6806fb82010-10-06 17:09:52 +0000494 virtual uint32_t readSetEnd_virt() = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000495
David Reiss6806fb82010-10-06 17:09:52 +0000496 virtual uint32_t readBool_virt(bool& value) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000497
David Reiss8dfc7322010-10-06 17:09:58 +0000498 virtual uint32_t readBool_virt(std::vector<bool>::reference value) = 0;
499
David Reiss6806fb82010-10-06 17:09:52 +0000500 virtual uint32_t readByte_virt(int8_t& byte) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000501
David Reiss6806fb82010-10-06 17:09:52 +0000502 virtual uint32_t readI16_virt(int16_t& i16) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000503
David Reiss6806fb82010-10-06 17:09:52 +0000504 virtual uint32_t readI32_virt(int32_t& i32) = 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000505
David Reiss6806fb82010-10-06 17:09:52 +0000506 virtual uint32_t readI64_virt(int64_t& i64) = 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000507
David Reiss6806fb82010-10-06 17:09:52 +0000508 virtual uint32_t readDouble_virt(double& dub) = 0;
Mark Sleec98d0502006-09-06 02:42:25 +0000509
David Reiss6806fb82010-10-06 17:09:52 +0000510 virtual uint32_t readString_virt(std::string& str) = 0;
Mark Sleee8540632006-05-30 09:24:40 +0000511
David Reiss6806fb82010-10-06 17:09:52 +0000512 virtual uint32_t readBinary_virt(std::string& str) = 0;
513
514 uint32_t readMessageBegin(std::string& name,
515 TMessageType& messageType,
516 int32_t& seqid) {
517 T_VIRTUAL_CALL();
518 return readMessageBegin_virt(name, messageType, seqid);
519 }
520
521 uint32_t readMessageEnd() {
522 T_VIRTUAL_CALL();
523 return readMessageEnd_virt();
524 }
525
526 uint32_t readStructBegin(std::string& name) {
527 T_VIRTUAL_CALL();
528 return readStructBegin_virt(name);
529 }
530
531 uint32_t readStructEnd() {
532 T_VIRTUAL_CALL();
533 return readStructEnd_virt();
534 }
535
536 uint32_t readFieldBegin(std::string& name,
537 TType& fieldType,
538 int16_t& fieldId) {
539 T_VIRTUAL_CALL();
540 return readFieldBegin_virt(name, fieldType, fieldId);
541 }
542
543 uint32_t readFieldEnd() {
544 T_VIRTUAL_CALL();
545 return readFieldEnd_virt();
546 }
547
548 uint32_t readMapBegin(TType& keyType, TType& valType, uint32_t& size) {
549 T_VIRTUAL_CALL();
550 return readMapBegin_virt(keyType, valType, size);
551 }
552
553 uint32_t readMapEnd() {
554 T_VIRTUAL_CALL();
555 return readMapEnd_virt();
556 }
557
558 uint32_t readListBegin(TType& elemType, uint32_t& size) {
559 T_VIRTUAL_CALL();
560 return readListBegin_virt(elemType, size);
561 }
562
563 uint32_t readListEnd() {
564 T_VIRTUAL_CALL();
565 return readListEnd_virt();
566 }
567
568 uint32_t readSetBegin(TType& elemType, uint32_t& size) {
569 T_VIRTUAL_CALL();
570 return readSetBegin_virt(elemType, size);
571 }
572
573 uint32_t readSetEnd() {
574 T_VIRTUAL_CALL();
575 return readSetEnd_virt();
576 }
577
578 uint32_t readBool(bool& value) {
579 T_VIRTUAL_CALL();
580 return readBool_virt(value);
581 }
582
583 uint32_t readByte(int8_t& byte) {
584 T_VIRTUAL_CALL();
585 return readByte_virt(byte);
586 }
587
588 uint32_t readI16(int16_t& i16) {
589 T_VIRTUAL_CALL();
590 return readI16_virt(i16);
591 }
592
593 uint32_t readI32(int32_t& i32) {
594 T_VIRTUAL_CALL();
595 return readI32_virt(i32);
596 }
597
598 uint32_t readI64(int64_t& i64) {
599 T_VIRTUAL_CALL();
600 return readI64_virt(i64);
601 }
602
603 uint32_t readDouble(double& dub) {
604 T_VIRTUAL_CALL();
605 return readDouble_virt(dub);
606 }
607
608 uint32_t readString(std::string& str) {
609 T_VIRTUAL_CALL();
610 return readString_virt(str);
611 }
612
613 uint32_t readBinary(std::string& str) {
614 T_VIRTUAL_CALL();
615 return readBinary_virt(str);
616 }
David Reissc005b1b2008-02-15 01:38:18 +0000617
David Reiss8dfc7322010-10-06 17:09:58 +0000618 /*
619 * std::vector is specialized for bool, and its elements are individual bits
620 * rather than bools. We need to define a different version of readBool()
621 * to work with std::vector<bool>.
622 */
623 uint32_t readBool(std::vector<bool>::reference value) {
624 T_VIRTUAL_CALL();
625 return readBool_virt(value);
David Reiss035aed92009-02-10 21:38:48 +0000626 }
627
Mark Sleee8540632006-05-30 09:24:40 +0000628 /**
Mark Slee8d7e1f62006-06-07 06:48:56 +0000629 * Method to arbitrarily skip over data.
Mark Sleee8540632006-05-30 09:24:40 +0000630 */
Mark Slee4af6ed72006-10-25 19:02:49 +0000631 uint32_t skip(TType type) {
David Reiss6806fb82010-10-06 17:09:52 +0000632 T_VIRTUAL_CALL();
633 return skip_virt(type);
634 }
635 virtual uint32_t skip_virt(TType type) {
636 return ::apache::thrift::protocol::skip(*this, type);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000637 }
Mark Sleee8540632006-05-30 09:24:40 +0000638
Mark Slee5ea15f92007-03-05 22:55:59 +0000639 inline boost::shared_ptr<TTransport> getTransport() {
Mark Slee43b6c632007-02-07 00:54:17 +0000640 return ptrans_;
Mark Slee4af6ed72006-10-25 19:02:49 +0000641 }
642
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000643 // TODO: remove these two calls, they are for backwards
644 // compatibility
Mark Slee5ea15f92007-03-05 22:55:59 +0000645 inline boost::shared_ptr<TTransport> getInputTransport() {
Mark Slee43b6c632007-02-07 00:54:17 +0000646 return ptrans_;
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000647 }
Mark Slee5ea15f92007-03-05 22:55:59 +0000648 inline boost::shared_ptr<TTransport> getOutputTransport() {
Mark Slee43b6c632007-02-07 00:54:17 +0000649 return ptrans_;
Mark Slee4af6ed72006-10-25 19:02:49 +0000650 }
651
Mark Sleee8540632006-05-30 09:24:40 +0000652 protected:
Mark Slee5ea15f92007-03-05 22:55:59 +0000653 TProtocol(boost::shared_ptr<TTransport> ptrans):
Mark Slee43b6c632007-02-07 00:54:17 +0000654 ptrans_(ptrans) {
Mark Slee43b6c632007-02-07 00:54:17 +0000655 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000656
Mark Slee5ea15f92007-03-05 22:55:59 +0000657 boost::shared_ptr<TTransport> ptrans_;
Mark Slee4af6ed72006-10-25 19:02:49 +0000658
659 private:
Mark Sleee8540632006-05-30 09:24:40 +0000660 TProtocol() {}
661};
662
Mark Slee4af6ed72006-10-25 19:02:49 +0000663/**
664 * Constructs input and output protocol objects given transports.
665 */
666class TProtocolFactory {
667 public:
668 TProtocolFactory() {}
669
670 virtual ~TProtocolFactory() {}
671
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000672 virtual boost::shared_ptr<TProtocol> getProtocol(boost::shared_ptr<TTransport> trans) = 0;
Mark Slee4af6ed72006-10-25 19:02:49 +0000673};
674
David Reissb7762a02010-10-06 17:10:00 +0000675/**
676 * Dummy protocol class.
677 *
678 * This class does nothing, and should never be instantiated.
679 * It is used only by the generator code.
680 */
681class TDummyProtocol : public TProtocol {
682};
683
T Jake Lucianib5e62212009-01-31 22:36:20 +0000684}}} // apache::thrift::protocol
Marc Slemko6f038a72006-08-03 18:58:09 +0000685
Mark Sleef5f2be42006-09-05 21:05:31 +0000686#endif // #define _THRIFT_PROTOCOL_TPROTOCOL_H_ 1