跳转到主要内容

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 (1.1 MB 查看哈希值)

上传时间

构建分布

awkward_kaitai-0.1.0-py3-none-any.whl (9.8 kB 查看哈希值)

上传时间 Python 3

由以下赞助

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面