Replace DecodeVarInt function with LEB128

This commit is contained in:
Frank Galligan 2017-10-03 09:58:52 -07:00
parent 60b3928e56
commit f51669f55e
2 changed files with 12 additions and 9 deletions

View File

@ -47,7 +47,7 @@ section is the header. The second section contains the metadata. This section is
* When bit reading is finished it will always pad the read to the current * When bit reading is finished it will always pad the read to the current
byte. byte.
* varUI32 and varUI64 types must be decoded by the DecodeVarint() function. * varUI32 and varUI64 types must be decoded by the LEB128() function.
### General Conventions ### General Conventions

View File

@ -1,17 +1,20 @@
## Core Functions ## Core Functions
### DecodeVarint ### LEB128
~~~~~ ~~~~~
void DecodeVarint(out_val) { uint64_t LEB128() {
in UI8 result = 0;
if (in & (1 << 7)) { shift = 0;
DecodeVarint(out_val); while(true) {
out_val = (out_val << 7) | (in & ((1 << 7) - 1)); in UI8
} else { result |= (low order 7 bits of in) << shift;
out_val = in; if (high order bit of in == 0)
break;
shift += 7;
} }
return result;
} }
~~~~~ ~~~~~
{:.draco-syntax } {:.draco-syntax }