code wiki / (root) / nx_zstd_lit.nx

nx_zstd_lit.nx

buildroot/runtime/nx_zstd_lit.nx

7023 B199 linesdepth 4pulls 4 transitivereach 3 importersview sourcekind librarytopic zstd
docsdependenciesstructsconstsfunctions

about

nx_zstd_lit.nx -- Zstandard literals section, header and payload. The wiring layer that composes everything below it: nx_zstd_frame (blocks), nx_zstd_bits (the backward reader), nx_zstd_huf (the flat decode table). Raw and RLE literals decode fully here; Huffman-coded literals decode through a table the caller supplies. THE HEADER IS 1 TO 5 BYTES AND THE SIZE FIELDS ARE NOT BYTE-ALIGNED. Two bits of block type and two of size format share byte 0 with the TOP of the regenerated size, so every size read starts at bit 4 of byte 0 and runs into the following bytes little-endian. Reading the size as whole bytes gives a value that is plausible and wrong -- and wrong by a factor of 16, so it usually fails loudly on the first block and silently on a block whose true size happens to be small. SIZE_FORMAT 0 AND 2 MEAN THE SAME THING FOR RAW AND RLE. Both select the one-byte header with a 5-bit size; only the low bit of the format field is consulted. For Compressed and Treeless the same two values mean DIFFERENT things -- 0 is a single stream, 1 is four streams, both with 10-bit sizes. One field, two interpretations, decided by the block type. FOUR STREAMS, NOT ONE. Above the smallest size format, compressed literals are split into four independently-decodable streams so a decoder can run them in parallel. A reader that assumes one stream consumes the first stream's jump table as literal data. genealogy_id: zstandard_rfc8878_literals lineage_id: nx_zstd_lit_v1 license_tier: ORIGINAL

dependencies 3 imports · 3 importers

nx_syscalls.nx nx_zstd_bits.nx nx_zstd_huf.nx nx_zstd_lit.nx nx_zstd_block.nx nx_zstd_block_gate.nx nx_zstd_lit_gate.nx

imports: nx_syscalls.nxnx_zstd_bits.nxnx_zstd_huf.nx

imported by: nx_zstd_block.nxnx_zstd_block_gate.nxnx_zstd_lit_gate.nx

structs

none

consts

35const NX_LIT_RAW: i64 = 0
36const NX_LIT_RLE: i64 = 1
37const NX_LIT_COMP: i64 = 2
38const NX_LIT_TREELESS: i64 = 3
40const NX_LIT_FLD_TYPE: i64 = 0
41const NX_LIT_FLD_FORMAT: i64 = 1
42const NX_LIT_FLD_REGEN: i64 = 2
43const NX_LIT_FLD_COMPSIZE: i64 = 3
44const NX_LIT_FLD_STREAMS: i64 = 4
45const NX_LIT_FLD_HDRLEN: i64 = 5

functions

47func nx_lit_at(d: *u8, i: i64) -> i64 { return (d[i] as i64) & 255 }
called by 1: nx_zstd_lit_header
54func nx_zstd_lit_header(d: *u8, n: i64, off: i64, fld: *i64) -> i64
140func nx_zstd_lit_header_write(o: *u8, cap: i64, off: i64, btype: i64, regen: i64) -> i64
called by 1: main
152func nx_zstd_lit_raw(d: *u8, n: i64, off: i64, count: i64, out: *u8, cap: i64) -> i64
161func nx_zstd_lit_rle(d: *u8, n: i64, off: i64, count: i64, out: *u8, cap: i64) -> i64
178func nx_zstd_lit_huf(t: *NxZstdHuf, d: *u8, n: i64, off: i64, comp_size: i64,