Marc Slemko | d42a2c2 | 2006-08-10 03:30:18 +0000 | [diff] [blame] | 1 | #include "TBinaryProtocol.h" |
| 2 | |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 3 | using std::string; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 4 | |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 5 | namespace facebook { namespace thrift { namespace protocol { |
| 6 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 7 | uint32_t TBinaryProtocol::writeMessageBegin(shared_ptr<TTransport> out, |
| 8 | const TMessageType messageType, |
| 9 | const uint32_t seqid) const { |
| 10 | return |
| 11 | writeByte(out, (uint8_t)messageType) + |
| 12 | writeU32(out, seqid); |
| 13 | } |
| 14 | |
| 15 | uint32_t TBinaryProtocol::writeMessageEnd(shared_ptr<TTransport> out) const { |
| 16 | return 0; |
| 17 | } |
| 18 | |
| 19 | uint32_t TBinaryProtocol::writeStructBegin(shared_ptr<TTransport> out, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 20 | const string& name) const { |
| 21 | return 0; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 24 | uint32_t TBinaryProtocol::writeStructEnd(shared_ptr<TTransport> out) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 25 | return 0; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 26 | } |
| 27 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 28 | uint32_t TBinaryProtocol::writeFieldBegin(shared_ptr<TTransport> out, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 29 | const string& name, |
| 30 | const TType fieldType, |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame^] | 31 | const int16_t fieldId) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 32 | return |
| 33 | writeByte(out, (uint8_t)fieldType) + |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame^] | 34 | writeI16(out, fieldId); |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 37 | uint32_t TBinaryProtocol::writeFieldEnd(shared_ptr<TTransport> out) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 38 | return 0; |
| 39 | } |
| 40 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 41 | uint32_t TBinaryProtocol::writeFieldStop(shared_ptr<TTransport> out) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 42 | return |
| 43 | writeByte(out, (uint8_t)T_STOP); |
| 44 | } |
| 45 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 46 | uint32_t TBinaryProtocol::writeMapBegin(shared_ptr<TTransport> out, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 47 | const TType keyType, |
| 48 | const TType valType, |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 49 | const int32_t size) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 50 | return |
| 51 | writeByte(out, (uint8_t)keyType) + |
| 52 | writeByte(out, (uint8_t)valType) + |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 53 | writeI32(out, (int32_t)size); |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 56 | uint32_t TBinaryProtocol::writeMapEnd(shared_ptr<TTransport> out) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 57 | return 0; |
| 58 | } |
| 59 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 60 | uint32_t TBinaryProtocol::writeListBegin(shared_ptr<TTransport> out, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 61 | const TType elemType, |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 62 | const int32_t size) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 63 | return |
| 64 | writeByte(out, (uint8_t) elemType) + |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 65 | writeI32(out, (int32_t)size); |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 68 | uint32_t TBinaryProtocol::writeListEnd(shared_ptr<TTransport> out) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 69 | return 0; |
| 70 | } |
| 71 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 72 | uint32_t TBinaryProtocol::writeSetBegin(shared_ptr<TTransport> out, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 73 | const TType elemType, |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 74 | const int32_t size) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 75 | return |
| 76 | writeByte(out, (uint8_t)elemType) + |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 77 | writeI32(out, (int32_t)size); |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 80 | uint32_t TBinaryProtocol::writeSetEnd(shared_ptr<TTransport> out) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 81 | return 0; |
| 82 | } |
| 83 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame^] | 84 | uint32_t TBinaryProtocol::writeBool(shared_ptr<TTransport> out, |
| 85 | const bool value) const { |
| 86 | uint8_t tmp = value ? 1 : 0; |
| 87 | out->write(&tmp, 1); |
| 88 | return 1; |
| 89 | } |
| 90 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 91 | uint32_t TBinaryProtocol::writeByte(shared_ptr<TTransport> out, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 92 | const uint8_t byte) const { |
| 93 | out->write(&byte, 1); |
| 94 | return 1; |
| 95 | } |
| 96 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame^] | 97 | uint32_t TBinaryProtocol::writeU16(shared_ptr<TTransport> out, |
| 98 | const uint16_t u16) const { |
| 99 | uint16_t net = (uint16_t)htons(u16); |
| 100 | out->write((uint8_t*)&net, 2); |
| 101 | return 2; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame^] | 104 | uint32_t TBinaryProtocol::writeI16(shared_ptr<TTransport> out, |
| 105 | const int16_t i16) const { |
| 106 | int16_t net = (int16_t)htons(i16); |
| 107 | out->write((uint8_t*)&net, 2); |
| 108 | return 2; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 109 | } |
| 110 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 111 | uint32_t TBinaryProtocol::writeU64(shared_ptr<TTransport> out, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 112 | const uint64_t u64) const { |
| 113 | uint64_t net = (uint64_t)htonll(u64); |
| 114 | out->write((uint8_t*)&net, 8); |
| 115 | return 8; |
| 116 | } |
| 117 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 118 | uint32_t TBinaryProtocol::writeI64(shared_ptr<TTransport> out, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 119 | const int64_t i64) const { |
| 120 | int64_t net = (int64_t)htonll(i64); |
| 121 | out->write((uint8_t*)&net, 8); |
| 122 | return 8; |
| 123 | } |
| 124 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 125 | uint32_t TBinaryProtocol::writeString(shared_ptr<TTransport> out, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 126 | const string& str) const { |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 127 | uint32_t result = writeI32(out, str.size()); |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 128 | out->write((uint8_t*)str.data(), str.size()); |
| 129 | return result + str.size(); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Reading functions |
| 134 | */ |
| 135 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 136 | uint32_t TBinaryProtocol::readMessasgeBegin(shared_ptr<TTransport> in, |
| 137 | TMessageType& messageType, |
| 138 | uint32_t& seqid) const { |
| 139 | |
| 140 | uint32_t result = 0; |
| 141 | uint8_t type; |
| 142 | result+= readByte(in, type); |
| 143 | messageType = (TMessageType)type; |
| 144 | result+= readU32(in, seqid); |
| 145 | return result; |
| 146 | } |
| 147 | |
| 148 | uint32_t TBinaryProtocol::readMessageEnd(shared_ptr<TTransport> in) const{ |
| 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | uint32_t TBinaryProtocol::readStructBegin(shared_ptr<TTransport> in, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 153 | string& name) const { |
| 154 | name = ""; |
| 155 | return 0; |
| 156 | } |
| 157 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 158 | uint32_t TBinaryProtocol::readStructEnd(shared_ptr<TTransport> in) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 159 | return 0; |
| 160 | } |
| 161 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 162 | uint32_t TBinaryProtocol::readFieldBegin(shared_ptr<TTransport> in, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 163 | string& name, |
| 164 | TType& fieldType, |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame^] | 165 | int16_t& fieldId) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 166 | uint32_t result = 0; |
| 167 | uint8_t type; |
| 168 | result += readByte(in, type); |
| 169 | fieldType = (TType)type; |
| 170 | if (fieldType == T_STOP) { |
| 171 | fieldId = 0; |
| 172 | return result; |
| 173 | } |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame^] | 174 | result += readI16(in, fieldId); |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 175 | return result; |
| 176 | } |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 177 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 178 | uint32_t TBinaryProtocol::readFieldEnd(shared_ptr<TTransport> in) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 179 | return 0; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 180 | } |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 181 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 182 | uint32_t TBinaryProtocol::readMapBegin(shared_ptr<TTransport> in, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 183 | TType& keyType, |
| 184 | TType& valType, |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 185 | int32_t& size) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 186 | uint8_t k, v; |
| 187 | uint32_t result = 0; |
| 188 | result += readByte(in, k); |
| 189 | keyType = (TType)k; |
| 190 | result += readByte(in, v); |
| 191 | valType = (TType)v; |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 192 | result += readI32(in, size); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 193 | return result; |
| 194 | } |
| 195 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 196 | uint32_t TBinaryProtocol::readMapEnd(shared_ptr<TTransport> in) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 197 | return 0; |
| 198 | } |
| 199 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 200 | uint32_t TBinaryProtocol::readListBegin(shared_ptr<TTransport> in, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 201 | TType& elemType, |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 202 | int32_t& size) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 203 | uint8_t e; |
| 204 | uint32_t result = 0; |
| 205 | result += readByte(in, e); |
| 206 | elemType = (TType)e; |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 207 | result += readI32(in, size); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 208 | return result; |
| 209 | } |
| 210 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 211 | uint32_t TBinaryProtocol::readListEnd(shared_ptr<TTransport> in) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 215 | uint32_t TBinaryProtocol::readSetBegin(shared_ptr<TTransport> in, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 216 | TType& elemType, |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 217 | int32_t& size) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 218 | uint8_t e; |
| 219 | uint32_t result = 0; |
| 220 | result += readByte(in, e); |
| 221 | elemType = (TType)e; |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 222 | result += readI32(in, size); |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 223 | return result; |
| 224 | } |
| 225 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 226 | uint32_t TBinaryProtocol::readSetEnd(shared_ptr<TTransport> in) const { |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 227 | return 0; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 228 | } |
| 229 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame^] | 230 | uint32_t TBinaryProtocol::readBool(shared_ptr<TTransport> in, |
| 231 | bool& value) const { |
| 232 | uint8_t b[1]; |
| 233 | in->readAll(b, 1); |
| 234 | value = *(uint8_t*)b != 0; |
| 235 | return 1; |
| 236 | } |
| 237 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 238 | uint32_t TBinaryProtocol::readByte(shared_ptr<TTransport> in, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 239 | uint8_t& byte) const { |
| 240 | uint8_t b[1]; |
| 241 | in->readAll(b, 1); |
| 242 | byte = *(uint8_t*)b; |
| 243 | return 1; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Marc Slemko | 0b4ffa9 | 2006-08-11 02:49:29 +0000 | [diff] [blame^] | 246 | uint32_t TBinaryProtocol::readU16(shared_ptr<TTransport> in, |
| 247 | uint16_t& u16) const { |
| 248 | uint8_t b[2]; |
| 249 | in->readAll(b, 2); |
| 250 | u16 = *(uint16_t*)b; |
| 251 | u16 = (uint16_t)ntohs(u16); |
| 252 | return 2; |
| 253 | } |
| 254 | |
| 255 | uint32_t TBinaryProtocol::readI16(shared_ptr<TTransport> in, |
| 256 | int16_t& i16) const { |
| 257 | uint8_t b[2]; |
| 258 | in->readAll(b, 2); |
| 259 | i16 = *(int16_t*)b; |
| 260 | i16 = (int16_t)ntohs(i16); |
| 261 | return 2; |
| 262 | } |
| 263 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 264 | uint32_t TBinaryProtocol::readU32(shared_ptr<TTransport> in, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 265 | uint32_t& u32) const { |
| 266 | uint8_t b[4]; |
| 267 | in->readAll(b, 4); |
| 268 | u32 = *(uint32_t*)b; |
| 269 | u32 = (uint32_t)ntohl(u32); |
| 270 | return 4; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 271 | } |
| 272 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 273 | uint32_t TBinaryProtocol::readI32(shared_ptr<TTransport> in, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 274 | int32_t& i32) const { |
| 275 | uint8_t b[4]; |
| 276 | in->readAll(b, 4); |
| 277 | i32 = *(int32_t*)b; |
| 278 | i32 = (int32_t)ntohl(i32); |
| 279 | return 4; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 282 | uint32_t TBinaryProtocol::readU64(shared_ptr<TTransport> in, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 283 | uint64_t& u64) const { |
| 284 | uint8_t b[8]; |
| 285 | in->readAll(b, 8); |
| 286 | u64 = *(uint64_t*)b; |
| 287 | u64 = (uint64_t)ntohll(u64); |
| 288 | return 8; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 291 | uint32_t TBinaryProtocol::readI64(shared_ptr<TTransport> in, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 292 | int64_t& i64) const { |
| 293 | uint8_t b[8]; |
| 294 | in->readAll(b, 8); |
| 295 | i64 = *(int64_t*)b; |
| 296 | i64 = (int64_t)ntohll(i64); |
| 297 | return 8; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Marc Slemko | 1669885 | 2006-08-04 03:16:10 +0000 | [diff] [blame] | 300 | uint32_t TBinaryProtocol::readString(shared_ptr<TTransport> in, |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 301 | string& str) const { |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 302 | uint32_t result; |
| 303 | int32_t size; |
| 304 | result = readI32(in, size); |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 305 | |
| 306 | // Use the heap here to prevent stack overflow for v. large strings |
| 307 | uint8_t *b = new uint8_t[size]; |
Mark Slee | 8d7e1f6 | 2006-06-07 06:48:56 +0000 | [diff] [blame] | 308 | in->readAll(b, size); |
| 309 | str = string((char*)b, size); |
Mark Slee | 6e53644 | 2006-06-30 18:28:50 +0000 | [diff] [blame] | 310 | delete [] b; |
| 311 | |
Mark Slee | f3c322b | 2006-06-26 23:52:22 +0000 | [diff] [blame] | 312 | return result + (uint32_t)size; |
Mark Slee | e854063 | 2006-05-30 09:24:40 +0000 | [diff] [blame] | 313 | } |
Marc Slemko | 6f038a7 | 2006-08-03 18:58:09 +0000 | [diff] [blame] | 314 | }}} // facebook::thrift::protocol |