|
@@ -13,7 +13,7 @@ package varint
|
|
|
// In theory we should use the bigint package. In practice, varints bigger than this indicate a corrupted file.
|
|
|
// Instead we'll set limits on the values we'll encode/decode
|
|
|
// 18 * 7 bits = 126, which means that a possible 19th byte may at most be `0b0000_0011`.
|
|
|
-LEB128_MAX_BYTES :: 19
|
|
|
+LEB128_MAX_BYTES :: 19
|
|
|
|
|
|
Error :: enum {
|
|
|
None = 0,
|
|
@@ -132,14 +132,12 @@ encode_uleb128 :: proc(buf: []u8, val: u128) -> (size: int, err: Error) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
-@(private)
|
|
|
-SIGN_MASK :: (i128(1) << 121) // sign extend mask
|
|
|
-
|
|
|
// Encode `val` into `buf` as a signed LEB128 encoded series of bytes.
|
|
|
// `buf` must be appropriately sized.
|
|
|
encode_ileb128 :: proc(buf: []u8, val: i128) -> (size: int, err: Error) {
|
|
|
- val := val
|
|
|
- more := true
|
|
|
+ SIGN_MASK :: i128(1) << 121 // sign extend mask
|
|
|
+
|
|
|
+ val, more := val, true
|
|
|
|
|
|
for more {
|
|
|
size += 1
|