leb128.nx
buildroot/runtime/leb128.nx
about
leb128.nx -- LEB128 (Little-Endian Base 128) integer encoding.
Used by WASM (every length, every offset, every section header
is LEB128), DWARF debug info, Android dex files.
Distinct from varint.nx (protobuf):
- Same 7-bit-per-byte continuation pattern
- LEB128 has a SIGNED variant (sleb128) that uses 2's complement
sign-extension across the final byte's high bit -- different
from protobuf's ZigZag mapping
- sleb128's 1-byte encoding covers -64..63; ZigZag's covers
-1..1. Choose by ecosystem interop need.
Invariants:
LB1 Encoders write at most 10 bytes (covers full i64 range).
LB2 Decoders bound-check; sequences > 10 bytes return overflow.
LB3 ULEB128 round-trips any unsigned i64 exactly.
LB4 SLEB128 round-trips any signed i64 exactly via sign
extension on the final byte.
dependencies 1 imports · 3 importers
imports: syscalls.nx
imported by: nx_wasm_emit2.nxnx_wasm_emit_seed.nxnx_wat_compiler.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 23 | const LEB128_ERR_TRUNCATED: i64 = -1 |
| 24 | const LEB128_ERR_OVERFLOW: i64 = -2 |
functions
| 28 | func uleb128_encode(v: i64, out: *u8, pos: i64) -> i64 { |
| 45 | func uleb128_decode(in_bytes: *u8, n: i64, pos: i64,
called by 1: main |
| 68 | func sleb128_encode(v: i64, out: *u8, pos: i64) -> i64 { |
| 97 | func sleb128_decode(in_bytes: *u8, n: i64, pos: i64,
called by 1: main |
| 130 | func main() -> i64 { |