To generate C++ code to store data in Awkward arrays, Kaitai Struct compiler should be invoked with
-t cpp_awk
option:
kaitai-struct-compiler -t cpp_awk my_spec.ksy
This normally generates my_spec.h
and my_spec.cpp
files.
Runtime library API version must match compiler version that you’re using (i.e. if you use ksc v0.8, then you must use compatible v0.8 runtime).
With stable version of Kaitai Struct compiler, one can use use following methods:
-
On Debian / Ubuntu, one can install it from apt repositories:
-
For Python 2.x:
sudo apt-get install python-kaitaistruct
Reference: package info for Debian, package info for Ubuntu
-
For Python 3.x:
sudo apt-get install python3-kaitaistruct
Reference: package info for Debian, package info for Ubuntu
-
-
If your project is using requirements.txt to manage your dependencies, add the following line to it:
kaitaistruct
and then run
pip install -r requirements.txt
to update all your dependencies. -
Otherwise, you can just install the package manually using pip (Python package manager):
pip install kaitaistruct
If you’re using latest (unreleased AKA "unstable" AKA "snapshot") build of Kaitai Struct compiler, that will require latest runtime libraries as well:
-
If your project is using requirements.txt to manage your dependencies, add the following line to it:
kaitaistruct @ git+https://github.com/kaitai-io/kaitai_struct_python_runtime.git
and then run
pip install -r requirements.txt
to update all your dependencies. -
Otherwise, you can just install the package manually using pip (Python package manager):
pip install --upgrade --pre git+https://github.com/kaitai-io/kaitai_struct_python_runtime.git
Enums implementation in Python requires a enum support as described in PEP-0435. This support is available out of the box in standard libraries since Python v3.4, or since v2.4 using enum34 PyPi compatibility layer.
-
On Debian / Ubuntu, this library can be installed with
sudo apt-get install python-enum34
-
Otherwise, one can use just
sudo pip install enum34
Setuptools is the de-facto
standard way of building and installing python packages. This library
allows extension with
plugins.
https://github.com/KOLANICH have developed
an extension to
setuptools, allowing you to automate compilation of *.ksy
files as the
part of python module build process. The library provides a mostly
declarative syntax to facilitate installation: you add a parameter
kaitai
to your setup.py
where you enumerate files that you want
compiled, output directory, compilation flags, and source code
post-compilation transformations. Here are some examples:
1,
2.
Here are the docs in JSON Schema format.
Please remember that this lib is VERY UNSTABLE and very likely to be improved in a way that changes API (but due to API simplicity it’d be easy to fix your code), but I guess it’s much better to use this than to reinvent the wheel. Contributions are welcome!
Please note that this lib is NOT available on
pypi and if you want to install it
automatically, you should add
git+https://github.com/KOLANICH/kaitaiStructCompile.py
into
dependency_links
in the config passed to setuptools.setup
.