blob: 2e24f750740eceaab77872cc27f2050c92eee984 [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>
33
David Reisse4d4ea02009-04-02 21:37:17 +000034
35// Use this to get around strict aliasing rules.
36// For example, uint64_t i = bitwise_cast<uint64_t>(returns_double());
37// The most obvious implementation is to just cast a pointer,
38// but that doesn't work.
39// For a pretty in-depth explanation of the problem, see
40// http://www.cellperformance.com/mike_acton/2006/06/ (...)
41// understanding_strict_aliasing.html
42template <typename To, typename From>
43static inline To bitwise_cast(From from) {
44 BOOST_STATIC_ASSERT(sizeof(From) == sizeof(To));
45
46 // BAD!!! These are all broken with -O2.
47 //return *reinterpret_cast<To*>(&from); // BAD!!!
48 //return *static_cast<To*>(static_cast<void*>(&from)); // BAD!!!
49 //return *(To*)(void*)&from; // BAD!!!
50
51 // Super clean and paritally blessed by section 3.9 of the standard.
52 //unsigned char c[sizeof(from)];
53 //memcpy(c, &from, sizeof(from));
54 //To to;
55 //memcpy(&to, c, sizeof(c));
56 //return to;
57
58 // Slightly more questionable.
59 // Same code emitted by GCC.
60 //To to;
61 //memcpy(&to, &from, sizeof(from));
62 //return to;
63
64 // Technically undefined, but almost universally supported,
65 // and the most efficient implementation.
66 union {
67 From f;
68 To t;
69 } u;
70 u.f = from;
71 return u.t;
72}
73
74
T Jake Lucianib5e62212009-01-31 22:36:20 +000075namespace apache { namespace thrift { namespace protocol {
Marc Slemko6f038a72006-08-03 18:58:09 +000076
T Jake Lucianib5e62212009-01-31 22:36:20 +000077using apache::thrift::transport::TTransport;
Marc Slemko6f038a72006-08-03 18:58:09 +000078
Bryan Duxbury184d2622010-08-17 17:43:58 +000079#ifdef HAVE_SYS_PARAM_H_
80#include <sys/param.h>
Mark Slee4f261c52007-04-13 00:33:24 +000081#endif
82
Mark Slee1d2ead32007-06-09 01:23:04 +000083#ifndef __BYTE_ORDER
84# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
85# define __BYTE_ORDER BYTE_ORDER
86# define __LITTLE_ENDIAN LITTLE_ENDIAN
87# define __BIG_ENDIAN BIG_ENDIAN
88# else
David Reiss9b903442009-10-21 05:51:28 +000089# include <boost/config.hpp>
90# define __BYTE_ORDER BOOST_BYTE_ORDER
91# define __LITTLE_ENDIAN BOOST_LITTLE_ENDIAN
92# define __BIG_ENDIAN BOOST_BIG_ENDIAN
Mark Slee1d2ead32007-06-09 01:23:04 +000093# endif
94#endif
95
Mark Sleedc8a2a22006-09-19 22:20:18 +000096#if __BYTE_ORDER == __BIG_ENDIAN
David Reisse4d4ea02009-04-02 21:37:17 +000097# define ntohll(n) (n)
98# define htonll(n) (n)
99# if defined(__GNUC__) && defined(__GLIBC__)
100# include <byteswap.h>
101# define htolell(n) bswap_64(n)
102# define letohll(n) bswap_64(n)
103# else /* GNUC & GLIBC */
104# define bswap_64(n) \
105 ( (((n) & 0xff00000000000000ull) >> 56) \
106 | (((n) & 0x00ff000000000000ull) >> 40) \
107 | (((n) & 0x0000ff0000000000ull) >> 24) \
108 | (((n) & 0x000000ff00000000ull) >> 8) \
109 | (((n) & 0x00000000ff000000ull) << 8) \
110 | (((n) & 0x0000000000ff0000ull) << 24) \
111 | (((n) & 0x000000000000ff00ull) << 40) \
112 | (((n) & 0x00000000000000ffull) << 56) )
David Reiss30297862009-08-05 16:42:59 +0000113# define htolell(n) bswap_64(n)
114# define letohll(n) bswap_64(n)
David Reisse4d4ea02009-04-02 21:37:17 +0000115# endif /* GNUC & GLIBC */
Mark Slee4f261c52007-04-13 00:33:24 +0000116#elif __BYTE_ORDER == __LITTLE_ENDIAN
David Reisse4d4ea02009-04-02 21:37:17 +0000117# define htolell(n) (n)
118# define letohll(n) (n)
Mark Slee4f261c52007-04-13 00:33:24 +0000119# if defined(__GNUC__) && defined(__GLIBC__)
120# include <byteswap.h>
121# define ntohll(n) bswap_64(n)
122# define htonll(n) bswap_64(n)
123# else /* GNUC & GLIBC */
124# define ntohll(n) ( (((unsigned long long)ntohl(n)) << 32) + ntohl(n >> 32) )
125# define htonll(n) ( (((unsigned long long)htonl(n)) << 32) + htonl(n >> 32) )
126# endif /* GNUC & GLIBC */
127#else /* __BYTE_ORDER */
128# error "Can't define htonll or ntohll!"
Mark Sleedc8a2a22006-09-19 22:20:18 +0000129#endif
Mark Slee8d7e1f62006-06-07 06:48:56 +0000130
Mark Sleee8540632006-05-30 09:24:40 +0000131/**
Mark Slee8d7e1f62006-06-07 06:48:56 +0000132 * Enumerated definition of the types that the Thrift protocol supports.
133 * Take special note of the T_END type which is used specifically to mark
134 * the end of a sequence of fields.
135 */
136enum TType {
Marc Slemkod42a2c22006-08-10 03:30:18 +0000137 T_STOP = 0,
Marc Slemko5b126d62006-08-11 23:03:42 +0000138 T_VOID = 1,
139 T_BOOL = 2,
140 T_BYTE = 3,
Mark Sleecfc01932006-09-01 22:18:16 +0000141 T_I08 = 3,
Marc Slemko5b126d62006-08-11 23:03:42 +0000142 T_I16 = 6,
Marc Slemko5b126d62006-08-11 23:03:42 +0000143 T_I32 = 8,
144 T_U64 = 9,
145 T_I64 = 10,
Mark Sleec98d0502006-09-06 02:42:25 +0000146 T_DOUBLE = 4,
Marc Slemko5b126d62006-08-11 23:03:42 +0000147 T_STRING = 11,
Marc Slemkod97eb612006-08-24 23:37:36 +0000148 T_UTF7 = 11,
149 T_STRUCT = 12,
150 T_MAP = 13,
151 T_SET = 14,
152 T_LIST = 15,
153 T_UTF8 = 16,
154 T_UTF16 = 17
Mark Slee8d7e1f62006-06-07 06:48:56 +0000155};
156
157/**
Mark Sleef5f2be42006-09-05 21:05:31 +0000158 * Enumerated definition of the message types that the Thrift protocol
159 * supports.
Marc Slemko16698852006-08-04 03:16:10 +0000160 */
161enum TMessageType {
162 T_CALL = 1,
Mark Sleef9831082007-02-20 20:59:21 +0000163 T_REPLY = 2,
David Reissdeda1412009-04-02 19:22:31 +0000164 T_EXCEPTION = 3,
165 T_ONEWAY = 4
Marc Slemko16698852006-08-04 03:16:10 +0000166};
167
168/**
Mark Sleee8540632006-05-30 09:24:40 +0000169 * Abstract class for a thrift protocol driver. These are all the methods that
170 * a protocol must implement. Essentially, there must be some way of reading
171 * and writing all the base types, plus a mechanism for writing out structs
Mark Slee5d06fea2007-03-05 22:18:18 +0000172 * with indexed fields.
173 *
174 * TProtocol objects should not be shared across multiple encoding contexts,
175 * as they may need to maintain internal state in some protocols (i.e. XML).
176 * Note that is is acceptable for the TProtocol module to do its own internal
177 * buffered reads/writes to the underlying TTransport where appropriate (i.e.
178 * when parsing an input XML stream, reading should be batched rather than
179 * looking ahead character by character for a close tag).
Mark Sleee8540632006-05-30 09:24:40 +0000180 *
Mark Sleee8540632006-05-30 09:24:40 +0000181 */
182class TProtocol {
183 public:
184 virtual ~TProtocol() {}
185
186 /**
Mark Slee8d7e1f62006-06-07 06:48:56 +0000187 * Writing functions.
Mark Sleee8540632006-05-30 09:24:40 +0000188 */
189
Mark Slee82a6c0f2007-04-04 21:08:21 +0000190 virtual uint32_t writeMessageBegin(const std::string& name,
191 const TMessageType messageType,
192 const int32_t seqid) = 0;
Marc Slemko16698852006-08-04 03:16:10 +0000193
Mark Slee4af6ed72006-10-25 19:02:49 +0000194 virtual uint32_t writeMessageEnd() = 0;
Marc Slemko16698852006-08-04 03:16:10 +0000195
196
David Reiss64120002008-04-29 23:12:24 +0000197 virtual uint32_t writeStructBegin(const char* name) = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000198
Mark Slee4af6ed72006-10-25 19:02:49 +0000199 virtual uint32_t writeStructEnd() = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000200
David Reiss64120002008-04-29 23:12:24 +0000201 virtual uint32_t writeFieldBegin(const char* name,
David Reiss96d23882007-07-26 21:10:32 +0000202 const TType fieldType,
203 const int16_t fieldId) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000204
Mark Slee4af6ed72006-10-25 19:02:49 +0000205 virtual uint32_t writeFieldEnd() = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000206
Mark Slee4af6ed72006-10-25 19:02:49 +0000207 virtual uint32_t writeFieldStop() = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000208
Mark Slee4af6ed72006-10-25 19:02:49 +0000209 virtual uint32_t writeMapBegin(const TType keyType,
David Reiss96d23882007-07-26 21:10:32 +0000210 const TType valType,
211 const uint32_t size) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000212
Mark Slee4af6ed72006-10-25 19:02:49 +0000213 virtual uint32_t writeMapEnd() = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000214
Mark Slee4af6ed72006-10-25 19:02:49 +0000215 virtual uint32_t writeListBegin(const TType elemType,
David Reiss96d23882007-07-26 21:10:32 +0000216 const uint32_t size) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000217
Mark Slee4af6ed72006-10-25 19:02:49 +0000218 virtual uint32_t writeListEnd() = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000219
Mark Slee4af6ed72006-10-25 19:02:49 +0000220 virtual uint32_t writeSetBegin(const TType elemType,
David Reiss96d23882007-07-26 21:10:32 +0000221 const uint32_t size) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000222
Mark Slee4af6ed72006-10-25 19:02:49 +0000223 virtual uint32_t writeSetEnd() = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000224
Mark Slee4af6ed72006-10-25 19:02:49 +0000225 virtual uint32_t writeBool(const bool value) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000226
Mark Slee4af6ed72006-10-25 19:02:49 +0000227 virtual uint32_t writeByte(const int8_t byte) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000228
Mark Slee4af6ed72006-10-25 19:02:49 +0000229 virtual uint32_t writeI16(const int16_t i16) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000230
Mark Slee4af6ed72006-10-25 19:02:49 +0000231 virtual uint32_t writeI32(const int32_t i32) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000232
Mark Slee4af6ed72006-10-25 19:02:49 +0000233 virtual uint32_t writeI64(const int64_t i64) = 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000234
Mark Slee4af6ed72006-10-25 19:02:49 +0000235 virtual uint32_t writeDouble(const double dub) = 0;
Mark Sleec98d0502006-09-06 02:42:25 +0000236
Mark Slee4af6ed72006-10-25 19:02:49 +0000237 virtual uint32_t writeString(const std::string& str) = 0;
Mark Sleee8540632006-05-30 09:24:40 +0000238
David Reissc005b1b2008-02-15 01:38:18 +0000239 virtual uint32_t writeBinary(const std::string& str) = 0;
240
Mark Sleee8540632006-05-30 09:24:40 +0000241 /**
Mark Slee8d7e1f62006-06-07 06:48:56 +0000242 * Reading functions
Mark Sleee8540632006-05-30 09:24:40 +0000243 */
244
Mark Slee4af6ed72006-10-25 19:02:49 +0000245 virtual uint32_t readMessageBegin(std::string& name,
David Reiss96d23882007-07-26 21:10:32 +0000246 TMessageType& messageType,
247 int32_t& seqid) = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000248
Mark Slee4af6ed72006-10-25 19:02:49 +0000249 virtual uint32_t readMessageEnd() = 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000250
Mark Slee4af6ed72006-10-25 19:02:49 +0000251 virtual uint32_t readStructBegin(std::string& name) = 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000252
Mark Slee4af6ed72006-10-25 19:02:49 +0000253 virtual uint32_t readStructEnd() = 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000254
Mark Slee4af6ed72006-10-25 19:02:49 +0000255 virtual uint32_t readFieldBegin(std::string& name,
David Reiss96d23882007-07-26 21:10:32 +0000256 TType& fieldType,
257 int16_t& fieldId) = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000258
Mark Slee4af6ed72006-10-25 19:02:49 +0000259 virtual uint32_t readFieldEnd() = 0;
David Reiss0c90f6f2008-02-06 22:18:40 +0000260
Mark Slee4af6ed72006-10-25 19:02:49 +0000261 virtual uint32_t readMapBegin(TType& keyType,
David Reiss96d23882007-07-26 21:10:32 +0000262 TType& valType,
263 uint32_t& size) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000264
Mark Slee4af6ed72006-10-25 19:02:49 +0000265 virtual uint32_t readMapEnd() = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000266
Mark Slee4af6ed72006-10-25 19:02:49 +0000267 virtual uint32_t readListBegin(TType& elemType,
David Reiss96d23882007-07-26 21:10:32 +0000268 uint32_t& size) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000269
Mark Slee4af6ed72006-10-25 19:02:49 +0000270 virtual uint32_t readListEnd() = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000271
Mark Slee4af6ed72006-10-25 19:02:49 +0000272 virtual uint32_t readSetBegin(TType& elemType,
David Reiss96d23882007-07-26 21:10:32 +0000273 uint32_t& size) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000274
Mark Slee4af6ed72006-10-25 19:02:49 +0000275 virtual uint32_t readSetEnd() = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000276
Mark Slee4af6ed72006-10-25 19:02:49 +0000277 virtual uint32_t readBool(bool& value) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000278
Mark Slee4af6ed72006-10-25 19:02:49 +0000279 virtual uint32_t readByte(int8_t& byte) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000280
Mark Slee4af6ed72006-10-25 19:02:49 +0000281 virtual uint32_t readI16(int16_t& i16) = 0;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000282
Mark Slee4af6ed72006-10-25 19:02:49 +0000283 virtual uint32_t readI32(int32_t& i32) = 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000284
Mark Slee4af6ed72006-10-25 19:02:49 +0000285 virtual uint32_t readI64(int64_t& i64) = 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000286
Mark Slee4af6ed72006-10-25 19:02:49 +0000287 virtual uint32_t readDouble(double& dub) = 0;
Mark Sleec98d0502006-09-06 02:42:25 +0000288
Mark Slee4af6ed72006-10-25 19:02:49 +0000289 virtual uint32_t readString(std::string& str) = 0;
Mark Sleee8540632006-05-30 09:24:40 +0000290
David Reissc005b1b2008-02-15 01:38:18 +0000291 virtual uint32_t readBinary(std::string& str) = 0;
292
David Reiss035aed92009-02-10 21:38:48 +0000293 uint32_t readBool(std::vector<bool>::reference ref) {
294 bool value;
295 uint32_t rv = readBool(value);
296 ref = value;
David Reiss57b50062009-02-25 00:59:55 +0000297 return rv;
David Reiss035aed92009-02-10 21:38:48 +0000298 }
299
Mark Sleee8540632006-05-30 09:24:40 +0000300 /**
Mark Slee8d7e1f62006-06-07 06:48:56 +0000301 * Method to arbitrarily skip over data.
Mark Sleee8540632006-05-30 09:24:40 +0000302 */
Mark Slee4af6ed72006-10-25 19:02:49 +0000303 uint32_t skip(TType type) {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000304 switch (type) {
Mark Slee78f58e22006-09-02 04:17:07 +0000305 case T_BOOL:
306 {
307 bool boolv;
Mark Slee4af6ed72006-10-25 19:02:49 +0000308 return readBool(boolv);
Mark Slee78f58e22006-09-02 04:17:07 +0000309 }
Mark Slee8d7e1f62006-06-07 06:48:56 +0000310 case T_BYTE:
311 {
Mark Slee78f58e22006-09-02 04:17:07 +0000312 int8_t bytev;
Mark Slee4af6ed72006-10-25 19:02:49 +0000313 return readByte(bytev);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000314 }
Mark Sleecfc01932006-09-01 22:18:16 +0000315 case T_I16:
Mark Slee8d7e1f62006-06-07 06:48:56 +0000316 {
Mark Sleecfc01932006-09-01 22:18:16 +0000317 int16_t i16;
Mark Slee4af6ed72006-10-25 19:02:49 +0000318 return readI16(i16);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000319 }
320 case T_I32:
321 {
322 int32_t i32;
Mark Slee4af6ed72006-10-25 19:02:49 +0000323 return readI32(i32);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000324 }
Mark Slee8d7e1f62006-06-07 06:48:56 +0000325 case T_I64:
326 {
327 int64_t i64;
Mark Slee4af6ed72006-10-25 19:02:49 +0000328 return readI64(i64);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000329 }
Mark Sleec98d0502006-09-06 02:42:25 +0000330 case T_DOUBLE:
331 {
332 double dub;
Mark Slee4af6ed72006-10-25 19:02:49 +0000333 return readDouble(dub);
Mark Sleec98d0502006-09-06 02:42:25 +0000334 }
Mark Slee8d7e1f62006-06-07 06:48:56 +0000335 case T_STRING:
336 {
337 std::string str;
David Reissc005b1b2008-02-15 01:38:18 +0000338 return readBinary(str);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000339 }
340 case T_STRUCT:
341 {
342 uint32_t result = 0;
343 std::string name;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000344 int16_t fid;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000345 TType ftype;
Mark Slee4af6ed72006-10-25 19:02:49 +0000346 result += readStructBegin(name);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000347 while (true) {
Mark Slee4af6ed72006-10-25 19:02:49 +0000348 result += readFieldBegin(name, ftype, fid);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000349 if (ftype == T_STOP) {
350 break;
351 }
Mark Slee4af6ed72006-10-25 19:02:49 +0000352 result += skip(ftype);
353 result += readFieldEnd();
Mark Slee8d7e1f62006-06-07 06:48:56 +0000354 }
Mark Slee4af6ed72006-10-25 19:02:49 +0000355 result += readStructEnd();
Mark Slee8d7e1f62006-06-07 06:48:56 +0000356 return result;
357 }
358 case T_MAP:
359 {
360 uint32_t result = 0;
361 TType keyType;
362 TType valType;
Marc Slemkob09f5882006-08-23 22:03:34 +0000363 uint32_t i, size;
Mark Slee4af6ed72006-10-25 19:02:49 +0000364 result += readMapBegin(keyType, valType, size);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000365 for (i = 0; i < size; i++) {
Mark Slee4af6ed72006-10-25 19:02:49 +0000366 result += skip(keyType);
367 result += skip(valType);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000368 }
Mark Slee4af6ed72006-10-25 19:02:49 +0000369 result += readMapEnd();
Mark Slee8d7e1f62006-06-07 06:48:56 +0000370 return result;
371 }
372 case T_SET:
373 {
374 uint32_t result = 0;
375 TType elemType;
Marc Slemkob09f5882006-08-23 22:03:34 +0000376 uint32_t i, size;
Mark Slee4af6ed72006-10-25 19:02:49 +0000377 result += readSetBegin(elemType, size);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000378 for (i = 0; i < size; i++) {
Mark Slee4af6ed72006-10-25 19:02:49 +0000379 result += skip(elemType);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000380 }
Mark Slee4af6ed72006-10-25 19:02:49 +0000381 result += readSetEnd();
Mark Slee8d7e1f62006-06-07 06:48:56 +0000382 return result;
383 }
384 case T_LIST:
385 {
386 uint32_t result = 0;
387 TType elemType;
Marc Slemkob09f5882006-08-23 22:03:34 +0000388 uint32_t i, size;
Mark Slee4af6ed72006-10-25 19:02:49 +0000389 result += readListBegin(elemType, size);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000390 for (i = 0; i < size; i++) {
Mark Slee4af6ed72006-10-25 19:02:49 +0000391 result += skip(elemType);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000392 }
Mark Slee4af6ed72006-10-25 19:02:49 +0000393 result += readListEnd();
Mark Slee8d7e1f62006-06-07 06:48:56 +0000394 return result;
395 }
396 default:
397 return 0;
398 }
399 }
Mark Sleee8540632006-05-30 09:24:40 +0000400
Mark Slee5ea15f92007-03-05 22:55:59 +0000401 inline boost::shared_ptr<TTransport> getTransport() {
Mark Slee43b6c632007-02-07 00:54:17 +0000402 return ptrans_;
Mark Slee4af6ed72006-10-25 19:02:49 +0000403 }
404
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000405 // TODO: remove these two calls, they are for backwards
406 // compatibility
Mark Slee5ea15f92007-03-05 22:55:59 +0000407 inline boost::shared_ptr<TTransport> getInputTransport() {
Mark Slee43b6c632007-02-07 00:54:17 +0000408 return ptrans_;
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000409 }
Mark Slee5ea15f92007-03-05 22:55:59 +0000410 inline boost::shared_ptr<TTransport> getOutputTransport() {
Mark Slee43b6c632007-02-07 00:54:17 +0000411 return ptrans_;
Mark Slee4af6ed72006-10-25 19:02:49 +0000412 }
413
Mark Sleee8540632006-05-30 09:24:40 +0000414 protected:
Mark Slee5ea15f92007-03-05 22:55:59 +0000415 TProtocol(boost::shared_ptr<TTransport> ptrans):
Mark Slee43b6c632007-02-07 00:54:17 +0000416 ptrans_(ptrans) {
417 trans_ = ptrans.get();
418 }
David Reiss0c90f6f2008-02-06 22:18:40 +0000419
Mark Slee5ea15f92007-03-05 22:55:59 +0000420 boost::shared_ptr<TTransport> ptrans_;
Mark Slee43b6c632007-02-07 00:54:17 +0000421 TTransport* trans_;
Mark Slee4af6ed72006-10-25 19:02:49 +0000422
423 private:
Mark Sleee8540632006-05-30 09:24:40 +0000424 TProtocol() {}
425};
426
Mark Slee4af6ed72006-10-25 19:02:49 +0000427/**
428 * Constructs input and output protocol objects given transports.
429 */
430class TProtocolFactory {
431 public:
432 TProtocolFactory() {}
433
434 virtual ~TProtocolFactory() {}
435
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000436 virtual boost::shared_ptr<TProtocol> getProtocol(boost::shared_ptr<TTransport> trans) = 0;
Mark Slee4af6ed72006-10-25 19:02:49 +0000437};
438
T Jake Lucianib5e62212009-01-31 22:36:20 +0000439}}} // apache::thrift::protocol
Marc Slemko6f038a72006-08-03 18:58:09 +0000440
Mark Sleef5f2be42006-09-05 21:05:31 +0000441#endif // #define _THRIFT_PROTOCOL_TPROTOCOL_H_ 1