Skip to content
Mikhail Yakshin edited this page Apr 15, 2016 · 7 revisions

General

Is it fast?

Yes, pretty much. Kaitai Struct is not a runtime interpreter, but a compiler — thus it imposes no additional runtime performance penalty. Code that it generates is about as fast as one can write in a particular language to parse a certain data format.

Is output of KS readable?

Yes, Kaitai Struct compiler generates very human-readable files, which can be examined with naked eye, debugged if needed, etc. For example, reading a two-byte signed little-endian integer is usually translated into something like:

field = _io.readS2Le();

How does it compare to ...

... GNU Bison, Yacc, Lex, Flex, etc?

All these tools actually work on parsing text (most usually, source code) using context-free grammars. The core problem they solve is ambiguity of whatever was read. For example, a single letter a might be part of string literal, part of an identifier, part of a tag name, etc. In most cases, parsers that they generate have a concept of state and a fairly complex ruleset to change states. On the other hand, binary files are usually structured in a non-ambiguous way: there's no need to do complex backtracking, re-interpreting everything in a different fashion just because we've encountered something near the end of the file. There's usually no state beyond the pointer in the stream and pointer the code that does parsing.

All these tools are advanced hex editors with some sort of template language, which is actually pretty close to .ksy language. One major difference is that .ksy files, unlike per-editor templates, can be compiled right into parser source code in any supported language.

... Preon?

  • Both Preon and KS are declarative
  • Preon is Java-only library, KS is a cross-language tool
  • Preon's data structure definitions are done as annotations inside .java source files, KS keeps structure definitions in separate .ksy file
  • Preon interpetes data structure annotations in runtime, KS compiles .ksy into regular .java files first, then they're compiled normally by Java compiler as part of the project
  • Preon supports unaligned bit streams, KS does not (yet)
Clone this wiki locally