~rpadovani/reminders-app/fixForReload

« back to all changes in this revision

Viewing changes to 3rdParty/libthrift/protocol/TProtocol.h

  • Committer: Michael Zanetti
  • Date: 2013-11-21 23:30:15 UTC
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: michael.zanetti@canonical.com-20131121233015-fnbjnzcb6chdtdzm
add libthrift, evernote-sdk and a Evernote qml plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 */
 
19
 
 
20
#ifndef _THRIFT_PROTOCOL_TPROTOCOL_H_
 
21
#define _THRIFT_PROTOCOL_TPROTOCOL_H_ 1
 
22
 
 
23
#include <transport/TTransport.h>
 
24
#include <protocol/TProtocolException.h>
 
25
 
 
26
#include <boost/shared_ptr.hpp>
 
27
#include <boost/static_assert.hpp>
 
28
 
 
29
#ifdef HAVE_NETINET_IN_H
 
30
#include <netinet/in.h>
 
31
#endif
 
32
#include <sys/types.h>
 
33
#include <string>
 
34
#include <map>
 
35
#include <vector>
 
36
 
 
37
 
 
38
// Use this to get around strict aliasing rules.
 
39
// For example, uint64_t i = bitwise_cast<uint64_t>(returns_double());
 
40
// The most obvious implementation is to just cast a pointer,
 
41
// but that doesn't work.
 
42
// For a pretty in-depth explanation of the problem, see
 
43
// http://www.cellperformance.com/mike_acton/2006/06/ (...)
 
44
// understanding_strict_aliasing.html
 
45
template <typename To, typename From>
 
46
static inline To bitwise_cast(From from) {
 
47
  BOOST_STATIC_ASSERT(sizeof(From) == sizeof(To));
 
48
 
 
49
  // BAD!!!  These are all broken with -O2.
 
50
  //return *reinterpret_cast<To*>(&from);  // BAD!!!
 
51
  //return *static_cast<To*>(static_cast<void*>(&from));  // BAD!!!
 
52
  //return *(To*)(void*)&from;  // BAD!!!
 
53
 
 
54
  // Super clean and paritally blessed by section 3.9 of the standard.
 
55
  //unsigned char c[sizeof(from)];
 
56
  //memcpy(c, &from, sizeof(from));
 
57
  //To to;
 
58
  //memcpy(&to, c, sizeof(c));
 
59
  //return to;
 
60
 
 
61
  // Slightly more questionable.
 
62
  // Same code emitted by GCC.
 
63
  //To to;
 
64
  //memcpy(&to, &from, sizeof(from));
 
65
  //return to;
 
66
 
 
67
  // Technically undefined, but almost universally supported,
 
68
  // and the most efficient implementation.
 
69
  union {
 
70
    From f;
 
71
    To t;
 
72
  } u;
 
73
  u.f = from;
 
74
  return u.t;
 
75
}
 
76
 
 
77
 
 
78
namespace apache { namespace thrift { namespace protocol {
 
79
 
 
80
using apache::thrift::transport::TTransport;
 
81
 
 
82
#ifdef HAVE_SYS_PARAM_H
 
83
#include <sys/param.h>
 
84
#endif
 
85
 
 
86
#ifndef __THRIFT_BYTE_ORDER
 
87
# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
 
88
#  define __THRIFT_BYTE_ORDER BYTE_ORDER
 
89
#  define __THRIFT_LITTLE_ENDIAN LITTLE_ENDIAN
 
90
#  define __THRIFT_BIG_ENDIAN BIG_ENDIAN
 
91
# else
 
92
#  include <boost/config.hpp>
 
93
#  include <boost/detail/endian.hpp>
 
94
#  define __THRIFT_BYTE_ORDER BOOST_BYTE_ORDER
 
95
#  ifdef BOOST_LITTLE_ENDIAN
 
96
#   define __THRIFT_LITTLE_ENDIAN __THRIFT_BYTE_ORDER
 
97
#   define __THRIFT_BIG_ENDIAN 0
 
98
#  else
 
99
#   define __THRIFT_LITTLE_ENDIAN 0
 
100
#   define __THRIFT_BIG_ENDIAN __THRIFT_BYTE_ORDER
 
101
#  endif
 
102
# endif
 
103
#endif
 
104
 
 
105
#if __THRIFT_BYTE_ORDER == __THRIFT_BIG_ENDIAN
 
106
#  define ntohll(n) (n)
 
107
#  define htonll(n) (n)
 
108
# if defined(__GNUC__) && defined(__GLIBC__)
 
109
#  include <byteswap.h>
 
110
#  define htolell(n) bswap_64(n)
 
111
#  define letohll(n) bswap_64(n)
 
112
# else /* GNUC & GLIBC */
 
113
#  define bswap_64(n) \
 
114
      ( (((n) & 0xff00000000000000ull) >> 56) \
 
115
      | (((n) & 0x00ff000000000000ull) >> 40) \
 
116
      | (((n) & 0x0000ff0000000000ull) >> 24) \
 
117
      | (((n) & 0x000000ff00000000ull) >> 8)  \
 
118
      | (((n) & 0x00000000ff000000ull) << 8)  \
 
119
      | (((n) & 0x0000000000ff0000ull) << 24) \
 
120
      | (((n) & 0x000000000000ff00ull) << 40) \
 
121
      | (((n) & 0x00000000000000ffull) << 56) )
 
122
#  define htolell(n) bswap_64(n)
 
123
#  define letohll(n) bswap_64(n)
 
124
# endif /* GNUC & GLIBC */
 
125
#elif __THRIFT_BYTE_ORDER == __THRIFT_LITTLE_ENDIAN
 
126
#  define htolell(n) (n)
 
127
#  define letohll(n) (n)
 
128
# if defined(__GNUC__) && defined(__GLIBC__)
 
129
#  include <byteswap.h>
 
130
#  define ntohll(n) bswap_64(n)
 
131
#  define htonll(n) bswap_64(n)
 
132
# else /* GNUC & GLIBC */
 
133
#  define ntohll(n) ( (((uint64_t)ntohl(n)) << 32) + ntohl(n >> 32) )
 
134
#  define htonll(n) ( (((uint64_t)htonl(n)) << 32) + htonl(n >> 32) )
 
135
# endif /* GNUC & GLIBC */
 
136
#else /* __THRIFT_BYTE_ORDER */
 
137
# error "Can't define htonll or ntohll!"
 
138
#endif
 
139
 
 
140
/**
 
141
 * Enumerated definition of the types that the Thrift protocol supports.
 
142
 * Take special note of the T_END type which is used specifically to mark
 
143
 * the end of a sequence of fields.
 
144
 */
 
145
enum TType {
 
146
  T_STOP       = 0,
 
147
  T_VOID       = 1,
 
148
  T_BOOL       = 2,
 
149
  T_BYTE       = 3,
 
150
  T_I08        = 3,
 
151
  T_I16        = 6,
 
152
  T_I32        = 8,
 
153
  T_U64        = 9,
 
154
  T_I64        = 10,
 
155
  T_DOUBLE     = 4,
 
156
  T_STRING     = 11,
 
157
  T_UTF7       = 11,
 
158
  T_STRUCT     = 12,
 
159
  T_MAP        = 13,
 
160
  T_SET        = 14,
 
161
  T_LIST       = 15,
 
162
  T_UTF8       = 16,
 
163
  T_UTF16      = 17
 
164
};
 
165
 
 
166
/**
 
167
 * Enumerated definition of the message types that the Thrift protocol
 
168
 * supports.
 
169
 */
 
170
enum TMessageType {
 
171
  T_CALL       = 1,
 
172
  T_REPLY      = 2,
 
173
  T_EXCEPTION  = 3,
 
174
  T_ONEWAY     = 4
 
175
};
 
176
 
 
177
 
 
178
/**
 
179
 * Helper template for implementing TProtocol::skip().
 
180
 *
 
181
 * Templatized to avoid having to make virtual function calls.
 
182
 */
 
183
template <class Protocol_>
 
184
uint32_t skip(Protocol_& prot, TType type) {
 
185
  switch (type) {
 
186
  case T_BOOL:
 
187
    {
 
188
      bool boolv;
 
189
      return prot.readBool(boolv);
 
190
    }
 
191
  case T_BYTE:
 
192
    {
 
193
      int8_t bytev;
 
194
      return prot.readByte(bytev);
 
195
    }
 
196
  case T_I16:
 
197
    {
 
198
      int16_t i16;
 
199
      return prot.readI16(i16);
 
200
    }
 
201
  case T_I32:
 
202
    {
 
203
      int32_t i32;
 
204
      return prot.readI32(i32);
 
205
    }
 
206
  case T_I64:
 
207
    {
 
208
      int64_t i64;
 
209
      return prot.readI64(i64);
 
210
    }
 
211
  case T_DOUBLE:
 
212
    {
 
213
      double dub;
 
214
      return prot.readDouble(dub);
 
215
    }
 
216
  case T_STRING:
 
217
    {
 
218
      std::string str;
 
219
      return prot.readBinary(str);
 
220
    }
 
221
  case T_STRUCT:
 
222
    {
 
223
      uint32_t result = 0;
 
224
      std::string name;
 
225
      int16_t fid;
 
226
      TType ftype;
 
227
      result += prot.readStructBegin(name);
 
228
      while (true) {
 
229
        result += prot.readFieldBegin(name, ftype, fid);
 
230
        if (ftype == T_STOP) {
 
231
          break;
 
232
        }
 
233
        result += skip(prot, ftype);
 
234
        result += prot.readFieldEnd();
 
235
      }
 
236
      result += prot.readStructEnd();
 
237
      return result;
 
238
    }
 
239
  case T_MAP:
 
240
    {
 
241
      uint32_t result = 0;
 
242
      TType keyType;
 
243
      TType valType;
 
244
      uint32_t i, size;
 
245
      result += prot.readMapBegin(keyType, valType, size);
 
246
      for (i = 0; i < size; i++) {
 
247
        result += skip(prot, keyType);
 
248
        result += skip(prot, valType);
 
249
      }
 
250
      result += prot.readMapEnd();
 
251
      return result;
 
252
    }
 
253
  case T_SET:
 
254
    {
 
255
      uint32_t result = 0;
 
256
      TType elemType;
 
257
      uint32_t i, size;
 
258
      result += prot.readSetBegin(elemType, size);
 
259
      for (i = 0; i < size; i++) {
 
260
        result += skip(prot, elemType);
 
261
      }
 
262
      result += prot.readSetEnd();
 
263
      return result;
 
264
    }
 
265
  case T_LIST:
 
266
    {
 
267
      uint32_t result = 0;
 
268
      TType elemType;
 
269
      uint32_t i, size;
 
270
      result += prot.readListBegin(elemType, size);
 
271
      for (i = 0; i < size; i++) {
 
272
        result += skip(prot, elemType);
 
273
      }
 
274
      result += prot.readListEnd();
 
275
      return result;
 
276
    }
 
277
  case T_STOP: case T_VOID: case T_U64: case T_UTF8: case T_UTF16:
 
278
    break;
 
279
  }
 
280
  return 0;
 
281
}
 
282
 
 
283
/**
 
284
 * Abstract class for a thrift protocol driver. These are all the methods that
 
285
 * a protocol must implement. Essentially, there must be some way of reading
 
286
 * and writing all the base types, plus a mechanism for writing out structs
 
287
 * with indexed fields.
 
288
 *
 
289
 * TProtocol objects should not be shared across multiple encoding contexts,
 
290
 * as they may need to maintain internal state in some protocols (i.e. XML).
 
291
 * Note that is is acceptable for the TProtocol module to do its own internal
 
292
 * buffered reads/writes to the underlying TTransport where appropriate (i.e.
 
293
 * when parsing an input XML stream, reading should be batched rather than
 
294
 * looking ahead character by character for a close tag).
 
295
 *
 
296
 */
 
297
class TProtocol {
 
298
 public:
 
299
  virtual ~TProtocol() {}
 
300
 
 
301
  /**
 
302
   * Writing functions.
 
303
   */
 
304
 
 
305
  virtual uint32_t writeMessageBegin_virt(const std::string& name,
 
306
                                          const TMessageType messageType,
 
307
                                          const int32_t seqid) = 0;
 
308
 
 
309
  virtual uint32_t writeMessageEnd_virt() = 0;
 
310
 
 
311
 
 
312
  virtual uint32_t writeStructBegin_virt(const char* name) = 0;
 
313
 
 
314
  virtual uint32_t writeStructEnd_virt() = 0;
 
315
 
 
316
  virtual uint32_t writeFieldBegin_virt(const char* name,
 
317
                                        const TType fieldType,
 
318
                                        const int16_t fieldId) = 0;
 
319
 
 
320
  virtual uint32_t writeFieldEnd_virt() = 0;
 
321
 
 
322
  virtual uint32_t writeFieldStop_virt() = 0;
 
323
 
 
324
  virtual uint32_t writeMapBegin_virt(const TType keyType,
 
325
                                      const TType valType,
 
326
                                      const uint32_t size) = 0;
 
327
 
 
328
  virtual uint32_t writeMapEnd_virt() = 0;
 
329
 
 
330
  virtual uint32_t writeListBegin_virt(const TType elemType,
 
331
                                       const uint32_t size) = 0;
 
332
 
 
333
  virtual uint32_t writeListEnd_virt() = 0;
 
334
 
 
335
  virtual uint32_t writeSetBegin_virt(const TType elemType,
 
336
                                      const uint32_t size) = 0;
 
337
 
 
338
  virtual uint32_t writeSetEnd_virt() = 0;
 
339
 
 
340
  virtual uint32_t writeBool_virt(const bool value) = 0;
 
341
 
 
342
  virtual uint32_t writeByte_virt(const int8_t byte) = 0;
 
343
 
 
344
  virtual uint32_t writeI16_virt(const int16_t i16) = 0;
 
345
 
 
346
  virtual uint32_t writeI32_virt(const int32_t i32) = 0;
 
347
 
 
348
  virtual uint32_t writeI64_virt(const int64_t i64) = 0;
 
349
 
 
350
  virtual uint32_t writeDouble_virt(const double dub) = 0;
 
351
 
 
352
  virtual uint32_t writeString_virt(const std::string& str) = 0;
 
353
 
 
354
  virtual uint32_t writeBinary_virt(const std::string& str) = 0;
 
355
 
 
356
  uint32_t writeMessageBegin(const std::string& name,
 
357
                             const TMessageType messageType,
 
358
                             const int32_t seqid) {
 
359
    T_VIRTUAL_CALL();
 
360
    return writeMessageBegin_virt(name, messageType, seqid);
 
361
  }
 
362
 
 
363
  uint32_t writeMessageEnd() {
 
364
    T_VIRTUAL_CALL();
 
365
    return writeMessageEnd_virt();
 
366
  }
 
367
 
 
368
 
 
369
  uint32_t writeStructBegin(const char* name) {
 
370
    T_VIRTUAL_CALL();
 
371
    return writeStructBegin_virt(name);
 
372
  }
 
373
 
 
374
  uint32_t writeStructEnd() {
 
375
    T_VIRTUAL_CALL();
 
376
    return writeStructEnd_virt();
 
377
  }
 
378
 
 
379
  uint32_t writeFieldBegin(const char* name,
 
380
                           const TType fieldType,
 
381
                           const int16_t fieldId) {
 
382
    T_VIRTUAL_CALL();
 
383
    return writeFieldBegin_virt(name, fieldType, fieldId);
 
384
  }
 
385
 
 
386
  uint32_t writeFieldEnd() {
 
387
    T_VIRTUAL_CALL();
 
388
    return writeFieldEnd_virt();
 
389
  }
 
390
 
 
391
  uint32_t writeFieldStop() {
 
392
    T_VIRTUAL_CALL();
 
393
    return writeFieldStop_virt();
 
394
  }
 
395
 
 
396
  uint32_t writeMapBegin(const TType keyType,
 
397
                         const TType valType,
 
398
                         const uint32_t size) {
 
399
    T_VIRTUAL_CALL();
 
400
    return writeMapBegin_virt(keyType, valType, size);
 
401
  }
 
402
 
 
403
  uint32_t writeMapEnd() {
 
404
    T_VIRTUAL_CALL();
 
405
    return writeMapEnd_virt();
 
406
  }
 
407
 
 
408
  uint32_t writeListBegin(const TType elemType, const uint32_t size) {
 
409
    T_VIRTUAL_CALL();
 
410
    return writeListBegin_virt(elemType, size);
 
411
  }
 
412
 
 
413
  uint32_t writeListEnd() {
 
414
    T_VIRTUAL_CALL();
 
415
    return writeListEnd_virt();
 
416
  }
 
417
 
 
418
  uint32_t writeSetBegin(const TType elemType, const uint32_t size) {
 
419
    T_VIRTUAL_CALL();
 
420
    return writeSetBegin_virt(elemType, size);
 
421
  }
 
422
 
 
423
  uint32_t writeSetEnd() {
 
424
    T_VIRTUAL_CALL();
 
425
    return writeSetEnd_virt();
 
426
  }
 
427
 
 
428
  uint32_t writeBool(const bool value) {
 
429
    T_VIRTUAL_CALL();
 
430
    return writeBool_virt(value);
 
431
  }
 
432
 
 
433
  uint32_t writeByte(const int8_t byte) {
 
434
    T_VIRTUAL_CALL();
 
435
    return writeByte_virt(byte);
 
436
  }
 
437
 
 
438
  uint32_t writeI16(const int16_t i16) {
 
439
    T_VIRTUAL_CALL();
 
440
    return writeI16_virt(i16);
 
441
  }
 
442
 
 
443
  uint32_t writeI32(const int32_t i32) {
 
444
    T_VIRTUAL_CALL();
 
445
    return writeI32_virt(i32);
 
446
  }
 
447
 
 
448
  uint32_t writeI64(const int64_t i64) {
 
449
    T_VIRTUAL_CALL();
 
450
    return writeI64_virt(i64);
 
451
  }
 
452
 
 
453
  uint32_t writeDouble(const double dub) {
 
454
    T_VIRTUAL_CALL();
 
455
    return writeDouble_virt(dub);
 
456
  }
 
457
 
 
458
  uint32_t writeString(const std::string& str) {
 
459
    T_VIRTUAL_CALL();
 
460
    return writeString_virt(str);
 
461
  }
 
462
 
 
463
  uint32_t writeBinary(const std::string& str) {
 
464
    T_VIRTUAL_CALL();
 
465
    return writeBinary_virt(str);
 
466
  }
 
467
 
 
468
  /**
 
469
   * Reading functions
 
470
   */
 
471
 
 
472
  virtual uint32_t readMessageBegin_virt(std::string& name,
 
473
                                         TMessageType& messageType,
 
474
                                         int32_t& seqid) = 0;
 
475
 
 
476
  virtual uint32_t readMessageEnd_virt() = 0;
 
477
 
 
478
  virtual uint32_t readStructBegin_virt(std::string& name) = 0;
 
479
 
 
480
  virtual uint32_t readStructEnd_virt() = 0;
 
481
 
 
482
  virtual uint32_t readFieldBegin_virt(std::string& name,
 
483
                                       TType& fieldType,
 
484
                                       int16_t& fieldId) = 0;
 
485
 
 
486
  virtual uint32_t readFieldEnd_virt() = 0;
 
487
 
 
488
  virtual uint32_t readMapBegin_virt(TType& keyType,
 
489
                                     TType& valType,
 
490
                                     uint32_t& size) = 0;
 
491
 
 
492
  virtual uint32_t readMapEnd_virt() = 0;
 
493
 
 
494
  virtual uint32_t readListBegin_virt(TType& elemType,
 
495
                                      uint32_t& size) = 0;
 
496
 
 
497
  virtual uint32_t readListEnd_virt() = 0;
 
498
 
 
499
  virtual uint32_t readSetBegin_virt(TType& elemType,
 
500
                                     uint32_t& size) = 0;
 
501
 
 
502
  virtual uint32_t readSetEnd_virt() = 0;
 
503
 
 
504
  virtual uint32_t readBool_virt(bool& value) = 0;
 
505
 
 
506
  virtual uint32_t readBool_virt(std::vector<bool>::reference value) = 0;
 
507
 
 
508
  virtual uint32_t readByte_virt(int8_t& byte) = 0;
 
509
 
 
510
  virtual uint32_t readI16_virt(int16_t& i16) = 0;
 
511
 
 
512
  virtual uint32_t readI32_virt(int32_t& i32) = 0;
 
513
 
 
514
  virtual uint32_t readI64_virt(int64_t& i64) = 0;
 
515
 
 
516
  virtual uint32_t readDouble_virt(double& dub) = 0;
 
517
 
 
518
  virtual uint32_t readString_virt(std::string& str) = 0;
 
519
 
 
520
  virtual uint32_t readBinary_virt(std::string& str) = 0;
 
521
 
 
522
  uint32_t readMessageBegin(std::string& name,
 
523
                            TMessageType& messageType,
 
524
                            int32_t& seqid) {
 
525
    T_VIRTUAL_CALL();
 
526
    return readMessageBegin_virt(name, messageType, seqid);
 
527
  }
 
528
 
 
529
  uint32_t readMessageEnd() {
 
530
    T_VIRTUAL_CALL();
 
531
    return readMessageEnd_virt();
 
532
  }
 
533
 
 
534
  uint32_t readStructBegin(std::string& name) {
 
535
    T_VIRTUAL_CALL();
 
536
    return readStructBegin_virt(name);
 
537
  }
 
538
 
 
539
  uint32_t readStructEnd() {
 
540
    T_VIRTUAL_CALL();
 
541
    return readStructEnd_virt();
 
542
  }
 
543
 
 
544
  uint32_t readFieldBegin(std::string& name,
 
545
                          TType& fieldType,
 
546
                          int16_t& fieldId) {
 
547
    T_VIRTUAL_CALL();
 
548
    return readFieldBegin_virt(name, fieldType, fieldId);
 
549
  }
 
550
 
 
551
  uint32_t readFieldEnd() {
 
552
    T_VIRTUAL_CALL();
 
553
    return readFieldEnd_virt();
 
554
  }
 
555
 
 
556
  uint32_t readMapBegin(TType& keyType, TType& valType, uint32_t& size) {
 
557
    T_VIRTUAL_CALL();
 
558
    return readMapBegin_virt(keyType, valType, size);
 
559
  }
 
560
 
 
561
  uint32_t readMapEnd() {
 
562
    T_VIRTUAL_CALL();
 
563
    return readMapEnd_virt();
 
564
  }
 
565
 
 
566
  uint32_t readListBegin(TType& elemType, uint32_t& size) {
 
567
    T_VIRTUAL_CALL();
 
568
    return readListBegin_virt(elemType, size);
 
569
  }
 
570
 
 
571
  uint32_t readListEnd() {
 
572
    T_VIRTUAL_CALL();
 
573
    return readListEnd_virt();
 
574
  }
 
575
 
 
576
  uint32_t readSetBegin(TType& elemType, uint32_t& size) {
 
577
    T_VIRTUAL_CALL();
 
578
    return readSetBegin_virt(elemType, size);
 
579
  }
 
580
 
 
581
  uint32_t readSetEnd() {
 
582
    T_VIRTUAL_CALL();
 
583
    return readSetEnd_virt();
 
584
  }
 
585
 
 
586
  uint32_t readBool(bool& value) {
 
587
    T_VIRTUAL_CALL();
 
588
    return readBool_virt(value);
 
589
  }
 
590
 
 
591
  uint32_t readByte(int8_t& byte) {
 
592
    T_VIRTUAL_CALL();
 
593
    return readByte_virt(byte);
 
594
  }
 
595
 
 
596
  uint32_t readI16(int16_t& i16) {
 
597
    T_VIRTUAL_CALL();
 
598
    return readI16_virt(i16);
 
599
  }
 
600
 
 
601
  uint32_t readI32(int32_t& i32) {
 
602
    T_VIRTUAL_CALL();
 
603
    return readI32_virt(i32);
 
604
  }
 
605
 
 
606
  uint32_t readI64(int64_t& i64) {
 
607
    T_VIRTUAL_CALL();
 
608
    return readI64_virt(i64);
 
609
  }
 
610
 
 
611
  uint32_t readDouble(double& dub) {
 
612
    T_VIRTUAL_CALL();
 
613
    return readDouble_virt(dub);
 
614
  }
 
615
 
 
616
  uint32_t readString(std::string& str) {
 
617
    T_VIRTUAL_CALL();
 
618
    return readString_virt(str);
 
619
  }
 
620
 
 
621
  uint32_t readBinary(std::string& str) {
 
622
    T_VIRTUAL_CALL();
 
623
    return readBinary_virt(str);
 
624
  }
 
625
 
 
626
  /*
 
627
   * std::vector is specialized for bool, and its elements are individual bits
 
628
   * rather than bools.   We need to define a different version of readBool()
 
629
   * to work with std::vector<bool>.
 
630
   */
 
631
  uint32_t readBool(std::vector<bool>::reference value) {
 
632
    T_VIRTUAL_CALL();
 
633
    return readBool_virt(value);
 
634
  }
 
635
 
 
636
  /**
 
637
   * Method to arbitrarily skip over data.
 
638
   */
 
639
  uint32_t skip(TType type) {
 
640
    T_VIRTUAL_CALL();
 
641
    return skip_virt(type);
 
642
  }
 
643
  virtual uint32_t skip_virt(TType type) {
 
644
    return ::apache::thrift::protocol::skip(*this, type);
 
645
  }
 
646
 
 
647
  inline boost::shared_ptr<TTransport> getTransport() {
 
648
    return ptrans_;
 
649
  }
 
650
 
 
651
  // TODO: remove these two calls, they are for backwards
 
652
  // compatibility
 
653
  inline boost::shared_ptr<TTransport> getInputTransport() {
 
654
    return ptrans_;
 
655
  }
 
656
  inline boost::shared_ptr<TTransport> getOutputTransport() {
 
657
    return ptrans_;
 
658
  }
 
659
 
 
660
 protected:
 
661
  TProtocol(boost::shared_ptr<TTransport> ptrans):
 
662
    ptrans_(ptrans) {
 
663
  }
 
664
 
 
665
  boost::shared_ptr<TTransport> ptrans_;
 
666
 
 
667
 private:
 
668
  TProtocol() {}
 
669
};
 
670
 
 
671
/**
 
672
 * Constructs input and output protocol objects given transports.
 
673
 */
 
674
class TProtocolFactory {
 
675
 public:
 
676
  TProtocolFactory() {}
 
677
 
 
678
  virtual ~TProtocolFactory() {}
 
679
 
 
680
  virtual boost::shared_ptr<TProtocol> getProtocol(boost::shared_ptr<TTransport> trans) = 0;
 
681
};
 
682
 
 
683
/**
 
684
 * Dummy protocol class.
 
685
 *
 
686
 * This class does nothing, and should never be instantiated.
 
687
 * It is used only by the generator code.
 
688
 */
 
689
class TDummyProtocol : public TProtocol {
 
690
};
 
691
 
 
692
}}} // apache::thrift::protocol
 
693
 
 
694
#endif // #define _THRIFT_PROTOCOL_TPROTOCOL_H_ 1