Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

Module compress

Module compress 

Source
Expand description

A small, self-contained LZSS codec for save payloads (feature compress).

Chosen over LZ4/zlib because it is tiny, no_std, allocation-free, and decodes with only the output buffer as its history window – so a card read can stream compressed frames straight into the caller’s buffer with no scratch. Typical structured save data (sparse tables, repeated records) compresses well; already-dense data falls back to being stored verbatim by crate::Card::write_compressed.

§Bitstream

Groups of up to 8 tokens, each group prefixed by a flag byte (bit i, LSB-first, describes token i): 1 = literal (one byte follows), 0 = match (two bytes follow). A match encodes a 12-bit distance (1..=4096) and a 4-bit length (3..=18) as ((dist-1) << 4) | (len-3), big-endian.

Functions§

compress
Compress src into dst. Returns the compressed length, or None if dst is too small to hold the result.
decompress
Decompress a full compressed slice into dst. Returns the number of bytes produced (should equal the original length). Convenience wrapper over decompress_from.
decompress_from
Streaming decompression: pull compressed bytes from next and write the decoded output into dst, stopping once dst is full. Returns the number of bytes produced, or None on a malformed stream (a back-reference before the start of output, or input exhausted early).