Fix bug encoding integers larger than 128
This commit is contained in:
parent
10e7e8123d
commit
8bf32c3248
1 changed files with 3 additions and 2 deletions
|
@ -21,7 +21,7 @@ std::size_t varint_length(
|
||||||
T value
|
T value
|
||||||
) {
|
) {
|
||||||
std::size_t result = 1;
|
std::size_t result = 1;
|
||||||
while (value > 128U) {
|
while (value >= 128U) {
|
||||||
++result;
|
++result;
|
||||||
value >>= 7;
|
value >>= 7;
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,9 @@ std::uint8_t * varint_encode(
|
||||||
std::uint8_t * output,
|
std::uint8_t * output,
|
||||||
T value
|
T value
|
||||||
) {
|
) {
|
||||||
while (value > 128U) {
|
while (value >= 128U) {
|
||||||
*(output++) = (0x7F & value) | 0x80;
|
*(output++) = (0x7F & value) | 0x80;
|
||||||
|
value >>= 7;
|
||||||
}
|
}
|
||||||
(*output++) = value;
|
(*output++) = value;
|
||||||
return output;
|
return output;
|
||||||
|
|
Loading…
Reference in a new issue