| 92 | : data(data), offset(0), context(context) {} |
| 93 | |
| 94 | LogicalResult readVarInt(uint64_t &result, uint64_t max = 0) { |
| 95 | if (offset >= data.size()) |
| 96 | return failure(); |
| 97 | result = 0; |
| 98 | uint64_t shift = 0; |
| 99 | uint8_t byte; |
| 100 | do { |
| 101 | if (offset >= data.size() || shift > 63) |
| 102 | return failure(); |
| 103 | byte = data[offset++]; |
| 104 | uint64_t value = byte & 0x7F; |
| 105 | result |= (value << shift); |
| 106 | shift += 7; |
| 107 | } while (byte & 0x80); |
| 108 | if (max && result > max) |
| 109 | return emitError() << "varint value exceeds maximum supported" |
| 110 | << " capacity. (expected value less than " << max |
| 111 | << ", got " << result << ")."; |
| 112 | return success(); |
| 113 | } |
| 114 | |
| 115 | /// Parse a signed variable length encoded integer from the byte stream. A |
| 116 | /// signed varint is encoded as a normal varint with zigzag encoding applied, |
no test coverage detected