buf.encodeSequences
Encode a sequence of LZ4 sequences into the LZ4 block format.
This function takes the output of findGreedySequences() and produces a properly formatted LZ4 compressed block. Each sequence is encoded as:
- Token byte: High nibble contains literal length (0-14, or 15 if
extended), low nibble contains match length minus 4 (0-14, or 15 if extended).
- Literal length extension: If high nibble is 15, additional bytes
encode the remaining length (255 means add 255 and continue).
- Literal bytes: Raw bytes from the source.
- Match offset: 2 bytes little-endian (only if matchLen > 0).
- Match length extension: If low nibble is 15, additional bytes
encode the remaining length minus 4 (255 means add 255 and continue).
The final sequence must have matchLen == 0 (literals only, no trailing match) per the LZ4 format specification.
Parameters
sequences | Array of Lz4Sequence structs from match finding. |
src | Original source data (for copying literal bytes). |
buf | Pre-allocated output buffer (must be at least lz4MaxCompressedSize(src.length) bytes). |
Returns
Number of bytes written to