Decode a value from a ByteSource, and advance the ByteSource.
| 214 | |
| 215 | // Decode a value from a ByteSource, and advance the ByteSource. |
| 216 | static uint64_t decodeFromByteSource(strings::ByteSource* src) { |
| 217 | uint64_t val = 0; |
| 218 | int32_t shift = 0; |
| 219 | int32_t max_size = kMaxSize64; |
| 220 | folly::StringPiece chunk; |
| 221 | int32_t remaining = 0; |
| 222 | const char* p = nullptr; |
| 223 | for (;;) { |
| 224 | if (remaining == 0) { |
| 225 | CHECK(src->next(&chunk)); |
| 226 | p = chunk.start(); |
| 227 | remaining = chunk.size(); |
| 228 | DCHECK_GT(remaining, 0); |
| 229 | } |
| 230 | --remaining; |
| 231 | if (*p & 0x80) { |
| 232 | CHECK_GT(max_size, 1); // We must have room for the last byte, too |
| 233 | --max_size; |
| 234 | val |= static_cast<uint64_t>(*p++ & 0x7f) << shift; |
| 235 | shift += 7; |
| 236 | } else { |
| 237 | val |= static_cast<uint64_t>(*p++) << shift; |
| 238 | break; |
| 239 | } |
| 240 | } |
| 241 | if (remaining) { |
| 242 | src->backUp(remaining); |
| 243 | } |
| 244 | return val; |
| 245 | } |
| 246 | static UInt128 decode128FromByteSource(strings::ByteSource* src) { |
| 247 | UInt128 val = 0; |
| 248 | int32_t shift = 0; |