Kaitai Struct运行时库,用于awkward数组
项目描述
Kaitai Struct:awkward的运行时库
此库使用C++/STL通过Kaitai Struct API构建awkward数组。
步骤
1. 为您的自定义文件格式编写一个 .ksy 文件。有关详细信息,请参阅Kaitai 用户指南。
这里,我们以 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. 克隆 kaitai_struct_awkward_runtime
仓库。
git clone --recursive https://github.com/ManasviGoyal/kaitai_struct_awkward_runtime.git
cd kaitai_struct_awkward_runtime
git checkout ManasviGoyal/test
3. 更新子模块并编译 Scala 代码(仅第一次)。
git submodule update --init
cd kaitai_struct_compiler
sbt package
cd ../
4. 为 Awkward 目标生成源文件和头文件。
./kaitai-struct-compiler -t awkward --outdir src-animal example_data/schemas/animal.ksy
5. 安装库。
pip install .
6. 通过传递生成代码中的主 .cpp
文件的路径来构建 awkward_kaitai
。
awkward-kaitai-build src-animal/animal.cpp -b build
注意
awkward-kaitai-build [-h] [-d 目标] [-b 构建位置] 文件
选项
-h, --help
:显示帮助信息-d 目标, --dest 目标
:显式指定构建共享库的目标位置。-b 构建位置, --build 构建位置
:显式指定构建位置。
7. 在 Python 中打开并打印返回的 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())
输出
[{'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}]}]
项目详情
关闭
awkward_kaitai-0.1.0.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 617b3538b7eb5f94ac1ce5e636d60976b30548efc6d09fd6c39733c2ca2bb481 |
|
MD5 | f43160ff8a81ee03028b4af2ec8f146f |
|
BLAKE2b-256 | d62e24d8b73d4ad0d8ea8c04831bf1688e8f778928d0083375e6ae373abcda59 |
关闭
awkward_kaitai-0.1.0-py3-none-any.whl 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ff2a41e917f49b1009c949df67295b92abcfa7ffcff081ceef1c9e6d873a253a |
|
MD5 | e925e76293b3722bce04280d31f9705b |
|
BLAKE2b-256 | d0460a97256c71027f33063f026c02bdceac2293166706e68d0557e0b7f03754 |