code wiki / (root) / lz4_header.nx

lz4_header.nx

buildroot/runtime/lz4_header.nx

5533 B161 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

lz4_header.nx -- parse LZ4 frame format headers (RFC-less spec: https://github.com/lz4/lz4/blob/dev/doc/lz4_Frame_format.md). Parses and validates the fixed magic + FLG + BD bytes that precede every LZ4-framed stream. Block decompression (the actual LZ4 algorithm) is a much larger port and ships in a future lz4.nx; this module is enough to: - detect whether a blob is an LZ4 frame - read the block-size code + content-checksum flag - know how many header bytes to skip before the first block Magic: 0x184D2294 little-endian (4 bytes). FLG byte: bit 7-6: version (must be 01 for v1) bit 5: block independence (1 = independent, 0 = linked) bit 4: block checksum present bit 3: content size present (if set, 8 bytes follow BD) bit 2: content checksum present (xxHash32 at end of stream) bit 1: reserved (must be 0) bit 0: dictionary ID present (if set, 4 bytes follow) BD byte: bit 7: reserved bit 6-4: block max size (4=64KB, 5=256KB, 6=1MB, 7=4MB) bit 3-0: reserved Then 1 byte HC (header checksum, low-byte of xxHash32 of (FLG, BD, [content_size], [dict_id])). Invariants: L1 Magic match required; otherwise LZ4_ERR_FORMAT. L2 FLG version must be 01. L3 Header length varies (7, 11, 15, or 19 bytes).

dependencies 1 imports · 0 importers

syscalls.nx lz4_header.nx

imports: syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main lz4_parse_header lz4_read_u64 lz4_read_u32 lz4_read_u32 ↻ lz4_block_max_bytes

structs

47struct Lz4Header {

consts

38const LZ4_MAGIC_0: i64 = 0x04
39const LZ4_MAGIC_1: i64 = 0x22
40const LZ4_MAGIC_2: i64 = 0x4D
41const LZ4_MAGIC_3: i64 = 0x18
43const LZ4_ERR_FORMAT: i64 = -1
44const LZ4_ERR_VERSION: i64 = -2
45const LZ4_ERR_SHORT: i64 = -3

functions

65func lz4_read_u32(buf: *u8, off: i64) -> i64 {
74func lz4_read_u64(buf: *u8, off: i64) -> i64 {
called by 1: lz4_parse_header calls 1: lz4_read_u32
83func lz4_parse_header(buf: *u8, n: i64, h: *Lz4Header) -> i64 {
called by 1: main calls 2: lz4_read_u64lz4_read_u32
126func lz4_block_max_bytes(code: i64) -> i64 {
called by 1: main
136func main() -> i64 {