FSST
FSST replaces common substrings of up to 8 bytes with one-byte codes taken from a small symbol table. It is codec id 3 in BytesCol.
Writers produce it only from columnar block revision 3 on, see columnar revision 3. A revision 1 or 2 block never contains it.
Layout
Section titled “Layout”| Field | Encoding | Meaning |
|---|---|---|
| codec | u8 | 3 |
| n | u8 | number of symbols, at most 255 |
| len | n x u8 | length of each symbol, 1 to 8 |
| symbols | n x 8 bytes | one little-endian 64-bit word per symbol |
| encoded | Plain | the encoded values, laid out as in Bytes PLAIN without its codec byte |
Each byte of an encoded value is a code.
| Code | Meaning |
|---|---|
c < n |
emit len[c] bytes of symbol c, the low bytes of its little-endian word first |
| 255 | escape: the next byte is one literal byte, emitted as is |
| any other | Corrupt |
Because n is at most 255, code 255 is never a symbol.
How to decode
Section titled “How to decode”- Read the codec byte (3), then
n, thenlengths and then8-byte words. - Read the encoded values as a
Plain. - For each encoded value, walk its bytes. Replace a code below
nby its symbol and an escape pair by its literal byte. Any other code isCorrupt.
Illustration
Section titled “Illustration”Derived by hand, not from a real file. Two symbols: 0 is ab and 1 is c. The values abcab and z.
03 codec FSST02 n = 202 01 symbol lengths 2, 161 62 00 00 00 00 00 00 symbol 0, word holds "ab"63 00 00 00 00 00 00 00 symbol 1, word holds "c"02 01 04 01 01 encoded lens: IntCol, count 2, FOR, min 2, width 1, lengths 3 201 00 00 offset samples: Flat, count 1, CONST 005 total 500 01 00 FF 7A codes 0 1 0 = "ab" "c" "ab"; escape FF then literal 7A = "z"Decoded: abcab, z.
Checks
Section titled “Checks”nis at most 255 and every symbol length is 1 to 8.- A code that is neither below
nnor 255 isCorrupt. - The encoded
Plainpasses the checks of Bytes PLAIN.
When writers pick it
Section titled “When writers pick it”See How writers choose a codec.