-
Notifications
You must be signed in to change notification settings - Fork 202
Kaitai Struct stream API
Mikhail Yakshin edited this page Mar 10, 2016
·
6 revisions
All source files in supported languages generated by a Kaitai Struct compiler have a goal to be human-readable, thus they utilize an extra layer of stream API. This API is followed by Kaitai Struct runtime libraries:
- kaitai_struct_java_runtime - for Java
- kaitai_struct_javascript_runtime - for JavaScript
- kaitai_struct_python_runtime - for Python
- kaitai_struct_ruby_runtime - for Ruby
Obviously, languages differ and thus API has slight differences, but in the nutshell, the general idea is the same. All generated code uses the same set of operations to parse primitive types one-by-one.
One can read integers using one of read_$S$L$E operations, where:
-
$Sis eitheruif we want to read unsigned integer orsif we want signed one; -
$Lis length of integer type in bytes. 1, 2, 4 and 8 bytes are supported; -
$Eis endianness (order of bytes):lfor little-endian orbfor big-endian;
A few examples:
-
read_u8le- reads 8-byte (64-bit) unsigned integer, little-endian (AKA Intel, AKA VAX, etc) -
read_s2be- reads 2-byte (16-bit) signed integer, big-endian (AKA "network byte order", AKA Power, AKA Motorola, etc) -
read_u1- reads 1-byte unsigned integer - no endianness is given as it's pointless to do so
Basically, it's the same designation as used in the type clause in .ksy format.