blob: 2645601f48121c8a77fc75464303ca8ee2d15ee4 [file] [log] [blame]
Mark Slee9f0c6512007-02-28 23:58:26 +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
Marc Slemkod42a2c22006-08-10 03:30:18 +00007#include "TBinaryProtocol.h"
8
Mark Slee4f261c52007-04-13 00:33:24 +00009#include <boost/static_assert.hpp>
10
Mark Slee8d7e1f62006-06-07 06:48:56 +000011using std::string;
Mark Sleee8540632006-05-30 09:24:40 +000012
Mark Slee4f261c52007-04-13 00:33:24 +000013// Use this to get around strict aliasing rules.
14// For example, uint64_t i = bitwise_cast<uint64_t>(returns_double());
15// The most obvious implementation is to just cast a pointer,
16// but that doesn't work.
17// For a pretty in-depth explanation of the problem, see
18// http://www.cellperformance.com/mike_acton/2006/06/ (...)
19// understanding_strict_aliasing.html
20template <typename To, typename From>
21static inline To bitwise_cast(From from) {
Mark Slee808454e2007-06-20 21:51:57 +000022 BOOST_STATIC_ASSERT(sizeof(From) == sizeof(To));
Mark Slee4f261c52007-04-13 00:33:24 +000023
Mark Slee808454e2007-06-20 21:51:57 +000024 // BAD!!! These are all broken with -O2.
25 //return *reinterpret_cast<To*>(&from); // BAD!!!
26 //return *static_cast<To*>(static_cast<void*>(&from)); // BAD!!!
27 //return *(To*)(void*)&from; // BAD!!!
28
29 // Super clean and paritally blessed by section 3.9 of the standard.
30 //unsigned char c[sizeof(from)];
31 //memcpy(c, &from, sizeof(from));
32 //To to;
33 //memcpy(&to, c, sizeof(c));
34 //return to;
Mark Slee4f261c52007-04-13 00:33:24 +000035
Mark Slee808454e2007-06-20 21:51:57 +000036 // Slightly more questionable.
37 // Same code emitted by GCC.
38 //To to;
39 //memcpy(&to, &from, sizeof(from));
40 //return to;
Mark Slee4f261c52007-04-13 00:33:24 +000041
Mark Slee808454e2007-06-20 21:51:57 +000042 // Technically undefined, but almost universally supported,
43 // and the most efficient implementation.
44 union {
45 From f;
46 To t;
47 } u;
48 u.f = from;
49 return u.t;
Mark Slee4f261c52007-04-13 00:33:24 +000050}
51
52
Marc Slemko6f038a72006-08-03 18:58:09 +000053namespace facebook { namespace thrift { namespace protocol {
54
Mark Slee82a6c0f2007-04-04 21:08:21 +000055uint32_t TBinaryProtocol::writeMessageBegin(const std::string& name,
56 const TMessageType messageType,
57 const int32_t seqid) {
Mark Slee808454e2007-06-20 21:51:57 +000058 if (strict_write_) {
59 int32_t version = (VERSION_1) | ((int32_t)messageType);
60 return
61 writeI32(version) +
62 writeString(name) +
63 writeI32(seqid);
64 } else {
65 return
66 writeString(name) +
67 writeByte((int8_t)messageType) +
68 writeI32(seqid);
69 }
Marc Slemko16698852006-08-04 03:16:10 +000070}
71
Mark Slee4af6ed72006-10-25 19:02:49 +000072uint32_t TBinaryProtocol::writeMessageEnd() {
Marc Slemko16698852006-08-04 03:16:10 +000073 return 0;
74}
75
Mark Slee4af6ed72006-10-25 19:02:49 +000076uint32_t TBinaryProtocol::writeStructBegin(const string& name) {
Mark Slee8d7e1f62006-06-07 06:48:56 +000077 return 0;
Mark Sleee8540632006-05-30 09:24:40 +000078}
79
Mark Slee4af6ed72006-10-25 19:02:49 +000080uint32_t TBinaryProtocol::writeStructEnd() {
Mark Slee8d7e1f62006-06-07 06:48:56 +000081 return 0;
Mark Sleee8540632006-05-30 09:24:40 +000082}
83
Mark Slee4af6ed72006-10-25 19:02:49 +000084uint32_t TBinaryProtocol::writeFieldBegin(const string& name,
Mark Slee8d7e1f62006-06-07 06:48:56 +000085 const TType fieldType,
Mark Slee4af6ed72006-10-25 19:02:49 +000086 const int16_t fieldId) {
Mark Slee8d7e1f62006-06-07 06:48:56 +000087 return
Mark Slee4af6ed72006-10-25 19:02:49 +000088 writeByte((int8_t)fieldType) +
89 writeI16(fieldId);
Mark Slee8d7e1f62006-06-07 06:48:56 +000090}
91
Mark Slee4af6ed72006-10-25 19:02:49 +000092uint32_t TBinaryProtocol::writeFieldEnd() {
Mark Slee8d7e1f62006-06-07 06:48:56 +000093 return 0;
94}
95
Mark Slee4af6ed72006-10-25 19:02:49 +000096uint32_t TBinaryProtocol::writeFieldStop() {
Mark Slee8d7e1f62006-06-07 06:48:56 +000097 return
Mark Slee4af6ed72006-10-25 19:02:49 +000098 writeByte((int8_t)T_STOP);
Mark Slee8d7e1f62006-06-07 06:48:56 +000099}
100
Mark Slee4af6ed72006-10-25 19:02:49 +0000101uint32_t TBinaryProtocol::writeMapBegin(const TType keyType,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000102 const TType valType,
Mark Slee4af6ed72006-10-25 19:02:49 +0000103 const uint32_t size) {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000104 return
Mark Slee4af6ed72006-10-25 19:02:49 +0000105 writeByte((int8_t)keyType) +
106 writeByte((int8_t)valType) +
107 writeI32((int32_t)size);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000108}
109
Mark Slee4af6ed72006-10-25 19:02:49 +0000110uint32_t TBinaryProtocol::writeMapEnd() {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000111 return 0;
112}
113
Mark Slee4af6ed72006-10-25 19:02:49 +0000114uint32_t TBinaryProtocol::writeListBegin(const TType elemType,
115 const uint32_t size) {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000116 return
Mark Slee4af6ed72006-10-25 19:02:49 +0000117 writeByte((int8_t) elemType) +
118 writeI32((int32_t)size);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000119}
120
Mark Slee4af6ed72006-10-25 19:02:49 +0000121uint32_t TBinaryProtocol::writeListEnd() {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000122 return 0;
123}
124
Mark Slee4af6ed72006-10-25 19:02:49 +0000125uint32_t TBinaryProtocol::writeSetBegin(const TType elemType,
126 const uint32_t size) {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000127 return
Mark Slee4af6ed72006-10-25 19:02:49 +0000128 writeByte((int8_t)elemType) +
129 writeI32((int32_t)size);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000130}
131
Mark Slee4af6ed72006-10-25 19:02:49 +0000132uint32_t TBinaryProtocol::writeSetEnd() {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000133 return 0;
134}
135
Mark Slee4af6ed72006-10-25 19:02:49 +0000136uint32_t TBinaryProtocol::writeBool(const bool value) {
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000137 uint8_t tmp = value ? 1 : 0;
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000138 trans_->write(&tmp, 1);
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000139 return 1;
140}
141
Mark Slee4af6ed72006-10-25 19:02:49 +0000142uint32_t TBinaryProtocol::writeByte(const int8_t byte) {
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000143 trans_->write((uint8_t*)&byte, 1);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000144 return 1;
145}
146
Mark Slee4af6ed72006-10-25 19:02:49 +0000147uint32_t TBinaryProtocol::writeI16(const int16_t i16) {
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000148 int16_t net = (int16_t)htons(i16);
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000149 trans_->write((uint8_t*)&net, 2);
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000150 return 2;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000151}
152
Mark Slee4af6ed72006-10-25 19:02:49 +0000153uint32_t TBinaryProtocol::writeI32(const int32_t i32) {
Marc Slemkoe6889de2006-08-12 00:32:53 +0000154 int32_t net = (int32_t)htonl(i32);
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000155 trans_->write((uint8_t*)&net, 4);
Marc Slemkoe6889de2006-08-12 00:32:53 +0000156 return 4;
157}
158
Mark Slee4af6ed72006-10-25 19:02:49 +0000159uint32_t TBinaryProtocol::writeI64(const int64_t i64) {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000160 int64_t net = (int64_t)htonll(i64);
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000161 trans_->write((uint8_t*)&net, 8);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000162 return 8;
163}
Mark Sleec98d0502006-09-06 02:42:25 +0000164
Mark Slee4af6ed72006-10-25 19:02:49 +0000165uint32_t TBinaryProtocol::writeDouble(const double dub) {
Mark Slee4f261c52007-04-13 00:33:24 +0000166 BOOST_STATIC_ASSERT(sizeof(double) == sizeof(uint64_t));
167 BOOST_STATIC_ASSERT(std::numeric_limits<double>::is_iec559);
168
169 uint64_t bits = bitwise_cast<uint64_t>(dub);
170 bits = htonll(bits);
171 trans_->write((uint8_t*)&bits, 8);
Mark Sleec98d0502006-09-06 02:42:25 +0000172 return 8;
173}
Mark Slee8d7e1f62006-06-07 06:48:56 +0000174
Mark Sleec98d0502006-09-06 02:42:25 +0000175
Mark Slee4af6ed72006-10-25 19:02:49 +0000176uint32_t TBinaryProtocol::writeString(const string& str) {
Mark Sleef9831082007-02-20 20:59:21 +0000177 uint32_t size = str.size();
178 uint32_t result = writeI32((int32_t)size);
179 if (size > 0) {
180 trans_->write((uint8_t*)str.data(), size);
181 }
182 return result + size;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000183}
184
185/**
186 * Reading functions
187 */
188
Mark Slee4af6ed72006-10-25 19:02:49 +0000189uint32_t TBinaryProtocol::readMessageBegin(std::string& name,
Marc Slemkoe6889de2006-08-12 00:32:53 +0000190 TMessageType& messageType,
Mark Slee4af6ed72006-10-25 19:02:49 +0000191 int32_t& seqid) {
Marc Slemko16698852006-08-04 03:16:10 +0000192 uint32_t result = 0;
Mark Slee808454e2007-06-20 21:51:57 +0000193 int32_t sz;
194 result += readI32(sz);
195
196 if (sz < 0) {
197 // Check for correct version number
198 int32_t version = sz & VERSION_MASK;
199 if (version != VERSION_1) {
200 throw TProtocolException(TProtocolException::BAD_VERSION, "Bad version identifier");
201 }
202 messageType = (TMessageType)(sz & 0x000000ff);
203 result += readString(name);
204 result += readI32(seqid);
205 } else {
206 if (strict_read_) {
207 throw TProtocolException(TProtocolException::BAD_VERSION, "No version identifier... old protocol client in strict mode?");
208 } else {
209 // Handle pre-versioned input
210 int8_t type;
211 result += readStringBody(name, sz);
212 result += readByte(type);
213 messageType = (TMessageType)type;
214 result += readI32(seqid);
215 }
216 }
Marc Slemko16698852006-08-04 03:16:10 +0000217 return result;
218}
219
Mark Slee4af6ed72006-10-25 19:02:49 +0000220uint32_t TBinaryProtocol::readMessageEnd() {
Marc Slemko16698852006-08-04 03:16:10 +0000221 return 0;
222}
223
Mark Slee4af6ed72006-10-25 19:02:49 +0000224uint32_t TBinaryProtocol::readStructBegin(string& name) {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000225 name = "";
226 return 0;
227}
228
Mark Slee4af6ed72006-10-25 19:02:49 +0000229uint32_t TBinaryProtocol::readStructEnd() {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000230 return 0;
231}
232
Mark Slee4af6ed72006-10-25 19:02:49 +0000233uint32_t TBinaryProtocol::readFieldBegin(string& name,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000234 TType& fieldType,
Mark Slee4af6ed72006-10-25 19:02:49 +0000235 int16_t& fieldId) {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000236 uint32_t result = 0;
Mark Sleecfc01932006-09-01 22:18:16 +0000237 int8_t type;
Mark Slee4af6ed72006-10-25 19:02:49 +0000238 result += readByte(type);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000239 fieldType = (TType)type;
240 if (fieldType == T_STOP) {
241 fieldId = 0;
242 return result;
243 }
Mark Slee4af6ed72006-10-25 19:02:49 +0000244 result += readI16(fieldId);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000245 return result;
246}
Mark Sleee8540632006-05-30 09:24:40 +0000247
Mark Slee4af6ed72006-10-25 19:02:49 +0000248uint32_t TBinaryProtocol::readFieldEnd() {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000249 return 0;
Mark Sleee8540632006-05-30 09:24:40 +0000250}
Mark Slee8d7e1f62006-06-07 06:48:56 +0000251
Mark Slee4af6ed72006-10-25 19:02:49 +0000252uint32_t TBinaryProtocol::readMapBegin(TType& keyType,
Mark Slee8d7e1f62006-06-07 06:48:56 +0000253 TType& valType,
Mark Slee4af6ed72006-10-25 19:02:49 +0000254 uint32_t& size) {
Mark Sleecfc01932006-09-01 22:18:16 +0000255 int8_t k, v;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000256 uint32_t result = 0;
Mark Sleecfc01932006-09-01 22:18:16 +0000257 int32_t sizei;
Mark Slee4af6ed72006-10-25 19:02:49 +0000258 result += readByte(k);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000259 keyType = (TType)k;
Mark Slee4af6ed72006-10-25 19:02:49 +0000260 result += readByte(v);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000261 valType = (TType)v;
Mark Slee4af6ed72006-10-25 19:02:49 +0000262 result += readI32(sizei);
Mark Sleef9831082007-02-20 20:59:21 +0000263 if (sizei < 0) {
264 throw TProtocolException(TProtocolException::NEGATIVE_SIZE);
265 } else if (container_limit_ && sizei > container_limit_) {
266 throw TProtocolException(TProtocolException::SIZE_LIMIT);
267 }
Mark Sleecfc01932006-09-01 22:18:16 +0000268 size = (uint32_t)sizei;
Mark Sleee8540632006-05-30 09:24:40 +0000269 return result;
270}
271
Mark Slee4af6ed72006-10-25 19:02:49 +0000272uint32_t TBinaryProtocol::readMapEnd() {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000273 return 0;
274}
275
Mark Slee4af6ed72006-10-25 19:02:49 +0000276uint32_t TBinaryProtocol::readListBegin(TType& elemType,
277 uint32_t& size) {
Mark Sleecfc01932006-09-01 22:18:16 +0000278 int8_t e;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000279 uint32_t result = 0;
Mark Sleecfc01932006-09-01 22:18:16 +0000280 int32_t sizei;
Mark Slee4af6ed72006-10-25 19:02:49 +0000281 result += readByte(e);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000282 elemType = (TType)e;
Mark Slee4af6ed72006-10-25 19:02:49 +0000283 result += readI32(sizei);
Mark Sleef9831082007-02-20 20:59:21 +0000284 if (sizei < 0) {
285 throw TProtocolException(TProtocolException::NEGATIVE_SIZE);
286 } else if (container_limit_ && sizei > container_limit_) {
287 throw TProtocolException(TProtocolException::SIZE_LIMIT);
288 }
Mark Sleecfc01932006-09-01 22:18:16 +0000289 size = (uint32_t)sizei;
Mark Sleee8540632006-05-30 09:24:40 +0000290 return result;
291}
292
Mark Slee4af6ed72006-10-25 19:02:49 +0000293uint32_t TBinaryProtocol::readListEnd() {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000294 return 0;
295}
296
Mark Slee4af6ed72006-10-25 19:02:49 +0000297uint32_t TBinaryProtocol::readSetBegin(TType& elemType,
298 uint32_t& size) {
Mark Sleecfc01932006-09-01 22:18:16 +0000299 int8_t e;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000300 uint32_t result = 0;
Mark Sleecfc01932006-09-01 22:18:16 +0000301 int32_t sizei;
Mark Slee4af6ed72006-10-25 19:02:49 +0000302 result += readByte(e);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000303 elemType = (TType)e;
Mark Slee4af6ed72006-10-25 19:02:49 +0000304 result += readI32(sizei);
Mark Sleef9831082007-02-20 20:59:21 +0000305 if (sizei < 0) {
306 throw TProtocolException(TProtocolException::NEGATIVE_SIZE);
307 } else if (container_limit_ && sizei > container_limit_) {
308 throw TProtocolException(TProtocolException::SIZE_LIMIT);
309 }
Mark Sleecfc01932006-09-01 22:18:16 +0000310 size = (uint32_t)sizei;
Mark Sleee8540632006-05-30 09:24:40 +0000311 return result;
312}
313
Mark Slee4af6ed72006-10-25 19:02:49 +0000314uint32_t TBinaryProtocol::readSetEnd() {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000315 return 0;
Mark Sleee8540632006-05-30 09:24:40 +0000316}
317
Mark Slee4af6ed72006-10-25 19:02:49 +0000318uint32_t TBinaryProtocol::readBool(bool& value) {
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000319 uint8_t b[1];
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000320 trans_->readAll(b, 1);
Mark Sleecfc01932006-09-01 22:18:16 +0000321 value = *(int8_t*)b != 0;
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000322 return 1;
323}
324
Mark Slee4af6ed72006-10-25 19:02:49 +0000325uint32_t TBinaryProtocol::readByte(int8_t& byte) {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000326 uint8_t b[1];
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000327 trans_->readAll(b, 1);
Mark Sleecfc01932006-09-01 22:18:16 +0000328 byte = *(int8_t*)b;
Mark Slee8d7e1f62006-06-07 06:48:56 +0000329 return 1;
Mark Sleee8540632006-05-30 09:24:40 +0000330}
331
Mark Slee4af6ed72006-10-25 19:02:49 +0000332uint32_t TBinaryProtocol::readI16(int16_t& i16) {
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000333 uint8_t b[2];
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000334 trans_->readAll(b, 2);
Marc Slemko0b4ffa92006-08-11 02:49:29 +0000335 i16 = *(int16_t*)b;
336 i16 = (int16_t)ntohs(i16);
337 return 2;
338}
339
Mark Slee4af6ed72006-10-25 19:02:49 +0000340uint32_t TBinaryProtocol::readI32(int32_t& i32) {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000341 uint8_t b[4];
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000342 trans_->readAll(b, 4);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000343 i32 = *(int32_t*)b;
344 i32 = (int32_t)ntohl(i32);
345 return 4;
Mark Sleee8540632006-05-30 09:24:40 +0000346}
347
Mark Slee4af6ed72006-10-25 19:02:49 +0000348uint32_t TBinaryProtocol::readI64(int64_t& i64) {
Mark Slee8d7e1f62006-06-07 06:48:56 +0000349 uint8_t b[8];
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000350 trans_->readAll(b, 8);
Mark Slee8d7e1f62006-06-07 06:48:56 +0000351 i64 = *(int64_t*)b;
352 i64 = (int64_t)ntohll(i64);
353 return 8;
Mark Sleee8540632006-05-30 09:24:40 +0000354}
355
Mark Slee4af6ed72006-10-25 19:02:49 +0000356uint32_t TBinaryProtocol::readDouble(double& dub) {
Mark Slee4f261c52007-04-13 00:33:24 +0000357 BOOST_STATIC_ASSERT(sizeof(double) == sizeof(uint64_t));
358 BOOST_STATIC_ASSERT(std::numeric_limits<double>::is_iec559);
359
360 uint64_t bits;
Mark Sleec98d0502006-09-06 02:42:25 +0000361 uint8_t b[8];
Aditya Agarwal9abb0d62007-01-24 22:53:54 +0000362 trans_->readAll(b, 8);
Mark Slee4f261c52007-04-13 00:33:24 +0000363 bits = *(uint64_t*)b;
364 bits = ntohll(bits);
365 dub = bitwise_cast<double>(bits);
Mark Sleec98d0502006-09-06 02:42:25 +0000366 return 8;
367}
368
Mark Slee4af6ed72006-10-25 19:02:49 +0000369uint32_t TBinaryProtocol::readString(string& str) {
Mark Sleef3c322b2006-06-26 23:52:22 +0000370 uint32_t result;
Mark Sleecfc01932006-09-01 22:18:16 +0000371 int32_t size;
Mark Slee4af6ed72006-10-25 19:02:49 +0000372 result = readI32(size);
Mark Slee808454e2007-06-20 21:51:57 +0000373 return result + readStringBody(str, size);
374}
375
376uint32_t TBinaryProtocol::readStringBody(string& str, int32_t size) {
377 uint32_t result = 0;
Mark Sleecfc01932006-09-01 22:18:16 +0000378
Mark Sleef9831082007-02-20 20:59:21 +0000379 // Catch error cases
380 if (size < 0) {
381 throw TProtocolException(TProtocolException::NEGATIVE_SIZE);
382 }
383 if (string_limit_ > 0 && size > string_limit_) {
384 throw TProtocolException(TProtocolException::SIZE_LIMIT);
385 }
386
387 // Catch empty string case
388 if (size == 0) {
389 str = "";
390 return result;
391 }
Mark Slee6e536442006-06-30 18:28:50 +0000392
393 // Use the heap here to prevent stack overflow for v. large strings
Mark Sleef9831082007-02-20 20:59:21 +0000394 if (size > string_buf_size_ || string_buf_ == NULL) {
395 string_buf_ = (uint8_t*)realloc(string_buf_, (uint32_t)size);
396 if (string_buf_ == NULL) {
397 string_buf_size_ = 0;
398 throw TProtocolException(TProtocolException::UNKNOWN, "Out of memory in TBinaryProtocol::readString");
399 }
400 string_buf_size_ = size;
401 }
402 trans_->readAll(string_buf_, size);
403 str = string((char*)string_buf_, size);
Mark Slee808454e2007-06-20 21:51:57 +0000404 return (uint32_t)size;
Mark Sleee8540632006-05-30 09:24:40 +0000405}
Mark Sleecfc01932006-09-01 22:18:16 +0000406
Marc Slemko6f038a72006-08-03 18:58:09 +0000407}}} // facebook::thrift::protocol