Maybe you have already seen Kaitai Struct. It describes binary formats in .ksy files and generates parsers, similar to RecordFlux, but for a dozen or so languages. Ada was not among them. I have been working on that, and it has reached a state where others might want to try it:
There are two parts.
A runtime library (Alire crate), written in SPARK and proven free of run-time errors. It uses no heap, no exceptions and no secondary stack, and it does not copy input: a parsed value refers to the buffer it was parsed from. It builds against a light run-time library; the test suite runs on a simulated STM32F4 as well as on the host.
A backend for the Kaitai Struct compiler (-t ada). It is kept as an overlay over the upstream compiler at a pinned commit, not as a fork. The generated parsers are SPARK too: every parser in examples/ and every parser generated from the upstream test formats goes through GNATprove at --level=1 --timeout=5 without unproved checks. With --read-write the backend also generates the Write direction.
What works and what does not:
- Of the 334 formats in the Kaitai Struct test suite, the backend generates code for 280. The others are rejected with an error that names the construct; nothing is generated that is known to be wrong. compiler/SURVEY.md lists them.
- The Ada parsers are compared with the Python parsers of the same compiler on mutated inputs. The differences that remain are documented (for example, an integer expression that leaves 64 bits is an error in Ada, while Python computes on).
- Not supported yet:
to_s, string concatenation, division of floats, and a few others. Repetitions are not stored; they are parsed again when you iterate over them. There are no operations to build a value from nothing or to change a parsed one. - The proof says nothing about stack use. Types that contain themselves are limited to a depth of 8 by default for that reason.
The release page has the compiler as a zip that needs Java to run. The crate is not in the Alire community index yet, but an archive is attached to the release as well.
docs/codegen.md describes what the generated code looks like. examples/showcase uses most constructs in one file.
Much of the code was written with the help of Claude Code. That is one reason the project leans on proof and on differential testing rather than on review alone.
How this relates to RecordFlux
RecordFlux is the obvious thing to compare with, and for a new protocol in a SPARK project it is probably the better choice. It has its own specification language, checks the specification itself for contradictions before any code exists, generates code to build messages as well as to parse them, and can model protocol sessions as state machines. None of that is here.
What this project adds is the Kaitai side: the format is described in a .ksy file, which the same compiler turns into parsers for Python, C++, Java and others, and for which a collection of existing descriptions and a visualizer exist. That fits when a format is already described that way, or when the same description has to serve tools in several languages. Kaitai Struct is also aimed more at file formats than at protocols: instances at arbitrary positions, substreams, and processing steps such as zlib or XOR are part of the language.
The price is that a .ksy file says less than a RecordFlux specification. The proof here shows that the generated parser has no run-time errors and stays within its buffer; it does not show that the description is consistent.
I would be glad to hear from anyone who tries it on a real format.