Kaitai Struct runtime for Awkward Arrays
Project description
Kaitai Struct: runtime library for Awkward
This library building Awkward Arrays using Kaitai Struct API for Awkward using C++/STL.
Steps
1. Write a .ksy file for your custom file format. Refer to the Kaitai User Guide for more details.
Here, we take an example of animal.ksy
meta:
id: animal
endian: le
license: CC0-1.0
ks-version: 0.8
seq:
- id: entry
type: animal_entry
repeat: eos
types:
animal_entry:
seq:
- id: str_len
type: u1
- id: species
type: str
size: str_len
encoding: UTF-8
- id: age
type: u1
- id: weight
type: u2
2. Clone kaitai_struct_awkward_runtime repository:
git clone --recursive https://github.com/ManasviGoyal/kaitai_struct_awkward_runtime.git
cd kaitai_struct_awkward_runtime
git checkout ManasviGoyal/test
3. Update submodule and compile scala code (only the first time)
git submodule update --init
cd kaitai_struct_compiler
sbt package
cd ../
4. Generate the source and header files for Awkward target
./kaitai-struct-compiler -t awkward --outdir src-animal example_data/schemas/animal.ksy
5. Install the library
pip install .
6. Build awkward_kaitai by passing the path of the main .cpp from the generated code.
awkward-kaitai-build src-animal/animal.cpp -b build
Note:
awkward-kaitai-build [-h] [-d DEST] [-b BUILD] fileoptions:
-h, --help: shows help message-d DEST, --dest DEST: explicitly specify a destination for the build shared library.-b BUILD, --build BUILD: explicitly specify a build location.
7. Open python and print the returned ak.Array:
python
import awkward_kaitai
animal = awkward_kaitai.Reader("./src-animal/libanimal.so") # pass the path of the shared file
awkward_array = animal.load("example_data/data/animal.raw")
print(awkward_array.to_list())
Output
[{'animalA__Zentry': [{'animal_entryA__Zstr_len': 3, 'animal_entryA__Zspecies': 'cat', 'animal_entryA__Zage': 5, 'animal_entryA__Zweight': 12}, {'animal_entryA__Zstr_len': 3, 'animal_entryA__Zspecies': 'dog', 'animal_entryA__Zage': 3, 'animal_entryA__Zweight': 43}, {'animal_entryA__Zstr_len': 6, 'animal_entryA__Zspecies': 'turtle', 'animal_entryA__Zage': 10, 'animal_entryA__Zweight': 5}]}]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
awkward_kaitai-0.1.dev1.tar.gz
(22.5 MB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file awkward_kaitai-0.1.dev1.tar.gz.
File metadata
- Download URL: awkward_kaitai-0.1.dev1.tar.gz
- Upload date:
- Size: 22.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c03fe57758933f81dede71b2ef351ef328311c763c575b83a7d936a5078f5c01
|
|
| MD5 |
597fd811f407c1eeb58316ffc96257c7
|
|
| BLAKE2b-256 |
cd1f1d25564a918ffadd8d30c8bca060f37631cc4c40ec653135745074329a14
|
File details
Details for the file awkward_kaitai-0.1.dev1-py3-none-any.whl.
File metadata
- Download URL: awkward_kaitai-0.1.dev1-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52021cc32ae084325289602d30a272a70d720217efcb04bc4e801eb9fa938f74
|
|
| MD5 |
44c5142cf061bc127b06cd3114b63004
|
|
| BLAKE2b-256 |
987c8ae6877cf03ff41ff271a0cd18e407ebbf4b73aff3701c3e5f2dcc707b95
|