From f51669f55edf12537497f3a2beb48d1f4a985d99 Mon Sep 17 00:00:00 2001 From: Frank Galligan Date: Tue, 3 Oct 2017 09:58:52 -0700 Subject: [PATCH] Replace DecodeVarInt function with LEB128 --- docs/spec/04.00.00.conventions.md | 2 +- docs/spec/core.functions.md | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/docs/spec/04.00.00.conventions.md b/docs/spec/04.00.00.conventions.md index 5af967e..f8d6670 100644 --- a/docs/spec/04.00.00.conventions.md +++ b/docs/spec/04.00.00.conventions.md @@ -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 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 diff --git a/docs/spec/core.functions.md b/docs/spec/core.functions.md index 2d07a66..35061b9 100644 --- a/docs/spec/core.functions.md +++ b/docs/spec/core.functions.md @@ -1,17 +1,20 @@ ## Core Functions -### DecodeVarint +### LEB128 ~~~~~ -void DecodeVarint(out_val) { - in UI8 - if (in & (1 << 7)) { - DecodeVarint(out_val); - out_val = (out_val << 7) | (in & ((1 << 7) - 1)); - } else { - out_val = in; +uint64_t LEB128() { + result = 0; + shift = 0; + while(true) { + in UI8 + result |= (low order 7 bits of in) << shift; + if (high order bit of in == 0) + break; + shift += 7; } + return result; } ~~~~~ {:.draco-syntax }