Reference
Reference Codec
Look up syntax, contracts, layouts, algorithms, and exact behavior.
The v0 loop is intentionally direct. The encoder writes the seed, asks the predictor for each next unit, writes a hit bit when the argmax matches, and writes a miss bit plus the actual unit otherwise. The decoder reads the same seed, runs the same predictor, and reconstructs the stream by choosing either the predictor output or the stored literal.
A crucial implementation detail is that both encoder and decoder feed the actual decoded unit back into the predictor state. They do not let an incorrect prediction become the next context item, so one miss cannot cascade into a permanently divergent decode.