Kaitai Struct is a formal language for binary format specification that can be compiled into parser code

Reading and writing binary formats is hard, especially if
its an interchange format that should work across a multitude of
platforms and languages.
Have you ever found yourself writing repetitive,
error-prone and hard-to-debug code that reads binary data structures
from files or network streams and somehow represents them in memory for
easier access?
Kaitai Struct tries to make this job easier you only have to
describe the binary format once and then everybody can use it from their
programming languages cross-language, cross-platform.
Kaitai Struct is a declarative language used to describe various
binary data structures, laid out in files or in memory: i.e. binary
file formats, network stream packet formats, etc.
The main idea is that a particular format is described in Kaitai
Struct language (.ksy file) and then can be compiled with
ksc into source files in one of the supported programming
languages. These modules will include a generated code for a parser
that can read the described data structure from a file or stream and give
access to it in a nice, easy-to-comprehend API.
Typically, using formats described in KS in your project involves the
following steps:

  • Describe the format i.e. create a .ksy file
  • Use a visualizer to debug the format and ensure that it parses data properly
  • Compile the .ksy file into a target language source file and include
    that file into your project
  • Add the KS runtime library for your particular language into your
    project (dont worry, its small and its there mostly to ensure
    readability of generated code)
  • Use the generated class(es) to parse your binary file or stream and
    access its components

Check out the documentation for more information.