lz4_header.nx
buildroot/runtime/lz4_header.nx
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
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 47 | struct Lz4Header { |
consts
| 38 | const LZ4_MAGIC_0: i64 = 0x04 |
| 39 | const LZ4_MAGIC_1: i64 = 0x22 |
| 40 | const LZ4_MAGIC_2: i64 = 0x4D |
| 41 | const LZ4_MAGIC_3: i64 = 0x18 |
| 43 | const LZ4_ERR_FORMAT: i64 = -1 |
| 44 | const LZ4_ERR_VERSION: i64 = -2 |
| 45 | const LZ4_ERR_SHORT: i64 = -3 |
functions
| 65 | func lz4_read_u32(buf: *u8, off: i64) -> i64 { |
| 74 | func lz4_read_u64(buf: *u8, off: i64) -> i64 { |
| 83 | func lz4_parse_header(buf: *u8, n: i64, h: *Lz4Header) -> i64 { |
| 126 | func lz4_block_max_bytes(code: i64) -> i64 {
called by 1: main |
| 136 | func main() -> i64 { |