encodeSequences

private fnsize_t encodeSequences(const(Lz4Sequence)[] sequences, const(ubyte)[] src, ubyte[] buf)

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:

  1. 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).

  1. Literal length extension: If high nibble is 15, additional bytes

encode the remaining length (255 means add 255 and continue).

  1. Literal bytes: Raw bytes from the source.
  2. Match offset: 2 bytes little-endian (only if matchLen > 0).
  3. 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

sequencesArray of Lz4Sequence structs from match finding.
srcOriginal source data (for copying literal bytes).
bufPre-allocated output buffer (must be at least lz4MaxCompressedSize(src.length) bytes).

Returns

Number of bytes written to buf.