code wiki / (root) / nx_zstd_frame.nx

nx_zstd_frame.nx

buildroot/runtime/nx_zstd_frame.nx

8565 B248 linesdepth 2pulls 2 transitivereach 1 importersview sourcekind librarytopic zstd
docsdependenciesstructsconstsfunctions

about

nx_zstd_frame.nx -- Zstandard frame and block layer, writer and reader. Sits above nx_zstd_fse.nx (the entropy tables). This layer is what makes a .zst file walkable: magic, a variable-length frame header, then a chain of blocks each with its own 3-byte header. Raw and RLE blocks decode fully here -- a frame built only from those is a completely valid zstd file that any zstd tool will read -- so this is a working decoder for that subset, not a stub. COMPRESSED BLOCKS ARE REFUSED, NOT GUESSED. The literals+sequences layer is not built yet, so a Compressed block returns a distinct refusal code rather than emitting whatever the raw bytes happen to look like. A decoder that silently passes through undecoded data is worse than one that stops. THE HEADER LENGTH IS COMPUTED, NOT ASSUMED. Frame_Content_Size is 0, 1, 2, 4 or 8 bytes, Dictionary_ID is 0, 1, 2 or 4, and the Window_Descriptor is ABSENT when Single_Segment_flag is set. Five independent choices, so the header is anywhere from 2 to 14 bytes. Assuming a length works on files from one encoder and fails on the next. THE 2-BYTE FCS IS BIASED BY 256. A two-byte Frame_Content_Size stores (size - 256), so a naive read reports every such frame 256 bytes short. This only affects frames between 256 and 65791 bytes, which is precisely the range small test files land in. genealogy_id: zstandard_rfc8878_frame lineage_id: nx_zstd_frame_v1 license_tier: ORIGINAL

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_zstd_frame.nx nx_zstd_frame_gate.nx

imports: nx_syscalls.nx

imported by: nx_zstd_frame_gate.nx

structs

none

consts

32const NX_ZSTD_MAGIC: i64 = 0xfd2fb528
33const NX_ZSTD_BLK_RAW: i64 = 0
34const NX_ZSTD_BLK_RLE: i64 = 1
35const NX_ZSTD_BLK_COMP: i64 = 2
36const NX_ZSTD_BLK_RESV: i64 = 3
39const NX_ZF_CONTENTSIZE: i64 = 0
40const NX_ZF_WINDOWSIZE: i64 = 1
41const NX_ZF_DICTID: i64 = 2
42const NX_ZF_CHECKSUM: i64 = 3
43const NX_ZF_SINGLESEG: i64 = 4
44const NX_ZF_HDRLEN: i64 = 5
47const NX_ZB_LAST: i64 = 0
48const NX_ZB_TYPE: i64 = 1
49const NX_ZB_SIZE: i64 = 2
50const NX_ZB_DATAOFF: i64 = 3
51const NX_ZB_NEXT: i64 = 4
54const NX_ZSTD_OK: i64 = 1
55const NX_ZSTD_ERR_MALFORMED: i64 = 0
56const NX_ZSTD_ERR_COMPRESSED: i64 = 0 - 2

functions

58func nx_zstd_at(d: *u8, i: i64) -> i64 { return (d[i] as i64) & 255 }
60func nx_zstd_le(d: *u8, off: i64, n: i64) -> i64
67func nx_zstd_le_w(o: *u8, off: i64, v: i64, n: i64) -> i64
77func nx_zstd_fcs_size(flag: i64, single_segment: i64) -> i64
87func nx_zstd_did_size(flag: i64) -> i64
96func nx_zstd_window_size(desc: i64) -> i64
107func nx_zstd_frame_parse(d: *u8, n: i64, fld: *i64) -> i64
160func nx_zstd_frame_write(o: *u8, cap: i64, content_size: i64) -> i64
called by 1: main calls 1: nx_zstd_le_w
172func nx_zstd_block_parse(d: *u8, n: i64, off: i64, fld: *i64) -> i64
called by 1: nx_zstd_decode calls 1: nx_zstd_le
192func nx_zstd_block_write(o: *u8, cap: i64, off: i64, last: i64, btype: i64,
called by 1: main calls 1: nx_zstd_le_w
212func nx_zstd_decode(d: *u8, n: i64, out: *u8, cap: i64) -> i64