mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Minor style change in leb128.odin
This commit is contained in:
@@ -13,7 +13,7 @@ package varint
|
|||||||
// In theory we should use the bigint package. In practice, varints bigger than this indicate a corrupted file.
|
// 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
|
// 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`.
|
// 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 {
|
Error :: enum {
|
||||||
None = 0,
|
None = 0,
|
||||||
@@ -132,14 +132,12 @@ encode_uleb128 :: proc(buf: []u8, val: u128) -> (size: int, err: Error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@(private)
|
|
||||||
SIGN_MASK :: (i128(1) << 121) // sign extend mask
|
|
||||||
|
|
||||||
// Encode `val` into `buf` as a signed LEB128 encoded series of bytes.
|
// Encode `val` into `buf` as a signed LEB128 encoded series of bytes.
|
||||||
// `buf` must be appropriately sized.
|
// `buf` must be appropriately sized.
|
||||||
encode_ileb128 :: proc(buf: []u8, val: i128) -> (size: int, err: Error) {
|
encode_ileb128 :: proc(buf: []u8, val: i128) -> (size: int, err: Error) {
|
||||||
val := val
|
SIGN_MASK :: i128(1) << 121 // sign extend mask
|
||||||
more := true
|
|
||||||
|
val, more := val, true
|
||||||
|
|
||||||
for more {
|
for more {
|
||||||
size += 1
|
size += 1
|
||||||
|
|||||||
Reference in New Issue
Block a user