nx_zstd_frame.nx
buildroot/runtime/nx_zstd_frame.nx
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
imports: nx_syscalls.nx
imported by: nx_zstd_frame_gate.nx
structs
| none |
consts
| 32 | const NX_ZSTD_MAGIC: i64 = 0xfd2fb528 |
| 33 | const NX_ZSTD_BLK_RAW: i64 = 0 |
| 34 | const NX_ZSTD_BLK_RLE: i64 = 1 |
| 35 | const NX_ZSTD_BLK_COMP: i64 = 2 |
| 36 | const NX_ZSTD_BLK_RESV: i64 = 3 |
| 39 | const NX_ZF_CONTENTSIZE: i64 = 0 |
| 40 | const NX_ZF_WINDOWSIZE: i64 = 1 |
| 41 | const NX_ZF_DICTID: i64 = 2 |
| 42 | const NX_ZF_CHECKSUM: i64 = 3 |
| 43 | const NX_ZF_SINGLESEG: i64 = 4 |
| 44 | const NX_ZF_HDRLEN: i64 = 5 |
| 47 | const NX_ZB_LAST: i64 = 0 |
| 48 | const NX_ZB_TYPE: i64 = 1 |
| 49 | const NX_ZB_SIZE: i64 = 2 |
| 50 | const NX_ZB_DATAOFF: i64 = 3 |
| 51 | const NX_ZB_NEXT: i64 = 4 |
| 54 | const NX_ZSTD_OK: i64 = 1 |
| 55 | const NX_ZSTD_ERR_MALFORMED: i64 = 0 |
| 56 | const NX_ZSTD_ERR_COMPRESSED: i64 = 0 - 2 |
functions
| 58 | func nx_zstd_at(d: *u8, i: i64) -> i64 { return (d[i] as i64) & 255 } |
| 60 | func nx_zstd_le(d: *u8, off: i64, n: i64) -> i64 |
| 67 | func nx_zstd_le_w(o: *u8, off: i64, v: i64, n: i64) -> i64 |
| 77 | func nx_zstd_fcs_size(flag: i64, single_segment: i64) -> i64 |
| 87 | func nx_zstd_did_size(flag: i64) -> i64 |
| 96 | func nx_zstd_window_size(desc: i64) -> i64 |
| 107 | func nx_zstd_frame_parse(d: *u8, n: i64, fld: *i64) -> i64 called by 2: nx_zstd_decodemain calls 5: nx_zstd_lenx_zstd_atnx_zstd_window_sizenx_zstd_did_sizenx_zstd_fcs_size |
| 160 | func nx_zstd_frame_write(o: *u8, cap: i64, content_size: i64) -> i64 |
| 172 | func nx_zstd_block_parse(d: *u8, n: i64, off: i64, fld: *i64) -> i64 |
| 192 | func nx_zstd_block_write(o: *u8, cap: i64, off: i64, last: i64, btype: i64, |
| 212 | func nx_zstd_decode(d: *u8, n: i64, out: *u8, cap: i64) -> i64 |