22template <
typename Function>
27 if (value < 1 << (kDataBitsPerByte))
goto write_one_byte;
28 if (value < 1 << (2 * kDataBitsPerByte))
goto write_two_bytes;
29 if (value < 1 << (3 * kDataBitsPerByte))
goto write_three_bytes;
30 if (value < 1 << (4 * kDataBitsPerByte))
goto write_four_bytes;
49 DCHECK_NE(value, std::numeric_limits<int32_t>::min());
50 bool is_negative = value < 0;
52 uint32_t bits =
static_cast<uint32_t
>((is_negative ? -
value :
value) << 1) |
53 static_cast<uint32_t
>(is_negative);
59template <
typename Function>
67inline void VLQEncode(std::vector<uint8_t, A>* data, int32_t value) {
68 VLQEncode([data](uint8_t value) { data->push_back(value); },
value);
79template <
typename GetNextFunction>
81 requires std::is_same<decltype(std::declval<GetNextFunction>()()),
84 uint8_t cur_byte = get_next();
91 cur_byte = get_next();
107inline int32_t
VLQDecode(
const uint8_t* data_start,
int* index) {
109 bool is_negative = (bits & 1) == 1;
110 int32_t
result = bits >> 1;
ZoneVector< RpoNumber > & result
static constexpr uint32_t kContinueShift
uint32_t VLQConvertToUnsigned(int32_t value)
void VLQEncode(Function &&process_byte, int32_t value)
static constexpr uint32_t kDataMask
uint32_t VLQDecodeUnsigned(GetNextFunction &&get_next)
static constexpr uint32_t kContinueBit
int32_t VLQDecode(const uint8_t *data_start, int *index)
void VLQEncodeUnsigned(Function &&process_byte, uint32_t value)
#define DCHECK_NE(v1, v2)
std::unique_ptr< ValueMirror > value