MCPcopy Create free account
hub / github.com/bytedance/bolt / decodeFromByteSource

Method decodeFromByteSource

bolt/common/encode/Coding.h:216–245  ·  view source on GitHub ↗

Decode a value from a ByteSource, and advance the ByteSource.

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 4

backUpMethod · 0.80
nextMethod · 0.45
startMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected