code wiki / (root) / leb128.nx

leb128.nx

buildroot/runtime/leb128.nx

4801 B153 linesdepth 3pulls 3 transitivereach 5 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

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

syscalls.nx leb128.nx nx_wasm_emit2.nx nx_wasm_emit_seed.nx nx_wat_compiler.nx

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

main uleb128_encode uleb128_decode sleb128_encode sleb128_decode

structs

none

consts

23const LEB128_ERR_TRUNCATED: i64 = -1
24const LEB128_ERR_OVERFLOW: i64 = -2

functions

28func uleb128_encode(v: i64, out: *u8, pos: i64) -> i64 {
45func uleb128_decode(in_bytes: *u8, n: i64, pos: i64,
called by 1: main
68func sleb128_encode(v: i64, out: *u8, pos: i64) -> i64 {
97func sleb128_decode(in_bytes: *u8, n: i64, pos: i64,
called by 1: main
130func main() -> i64 {