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