in lib/src/vlq.dart [66:101]
int decodeVlq(Iterator<String> chars) {
var result = 0;
var stop = false;
var shift = 0;
while (!stop) {
if (!chars.moveNext()) throw StateError('incomplete VLQ value');
var char = chars.current;
var digit = _digits[char];
if (digit == null) {
throw FormatException('invalid character in VLQ encoding: $char');
}
stop = (digit & vlqContinuationBit) == 0;
digit &= vlqBaseMask;
result += (digit << shift);
shift += vlqBaseShift;
}
// Result uses the least significant bit as a sign bit. We convert it into a
// two-complement value. For example,
// 2 (10 binary) becomes 1
// 3 (11 binary) becomes -1
// 4 (100 binary) becomes 2
// 5 (101 binary) becomes -2
// 6 (110 binary) becomes 3
// 7 (111 binary) becomes -3
var negate = (result & 1) == 1;
result = result >> 1;
result = negate ? -result : result;
// TODO(sigmund): can we detect this earlier?
if (result < minInt32 || result > maxInt32) {
throw FormatException(
'expected an encoded 32 bit int, but we got: $result');
}
return result;
}