# recipes/codec

A validator for a stored commit log, built on the encoding package alone.

The job is a real one: something wrote a log of commits to disk or to a socket, and before trusting it you want to know that every frame in it is a commit this format could have produced, that reading it back gives exactly what was written, and that a log which has been damaged says so rather than decoding into a plausible lie.

The last part is the point. Section 6 of the format says a decoder must refuse any input an encoder would not have produced. That is a claim about every byte string, not only the ones a test happens to think of, so this walks a real log byte by byte, flips each one, and holds the decoder to it: refuse the frame, or accept it and re-encode to exactly the bytes it was handed. Anything else is a second spelling for one value, and byte equality is how two implementations of this format agree at all.

## Files

- [`main.ts`](/docs/recipes/codec/files/main.ts)
