Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally extract all the types in the specification(s) #8

Open
tins2831 opened this issue Oct 26, 2021 · 1 comment
Open

Optionally extract all the types in the specification(s) #8

tins2831 opened this issue Oct 26, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@tins2831
Copy link
Owner

tins2831 commented Oct 26, 2021

There exist many ksy file specifications that have a mess of nested types. It gets ugly real fast:

meta:
  id: food
types:
  potato:
    types:
      bun:
        types:
          steak:
            types:
              chicken:
                enums:
                  cook_method:
                    1: fried
                    2: roasted
                types:
                  cereal:
                    seq:
                      - id: flakes
                        type: u1
                        enum: cook_method
  rice:
    types:
      corn:
        seq:
          - id: kernel
            type: u1
  cabbage:
    seq:
      - id: leaf
        type: u1
from kaitai_local import food

...
if mycereal.flakes.value == food.potato.bun.steak.chicken.cook_method.fried.value:
    # annoyed

I'm positive anyone would be annoyed by that. Users should be allowed to toggle a flag at the command-line interface to tell ksy-dl to extract all the types into a hierarchical structure of files:

└── kaitai_local
    └── food
        ├── cabbage
        │   └── cabbage.ksy
        ├── food.ksy
        ├── potato
        │   └── bun
        │       └── steak
        │           └── chicken
        │               ├── cereal
        │               │   └── cereal.ksy
        │               └── chicken.ksy
        └── rice
            └── corn
                └── corn.ksy

Not only does this make a specification more easier to sift through and use in code, it also becomes modular now:

from kaitai_local.food import food
from kaitai_local.food.potato.bun.steak.chicken.cereal import cereal
from kaitai_local.food.potato.bun.steak.chicken import chicken
from kaitai_local.food.rice.corn import corn
# from kaitai_local.food.cabbage import cabbage <- can omit this now instead of importing it

...
if mycereal.flakes.value == chicken.cook_method.roasted.value:
    # not annoyed

For this to work though, I'd have to:

  • Adjust the imports for each type
  • Correct the references to subtypes
  • (possibly more)
@tins2831 tins2831 added the enhancement New feature or request label Oct 26, 2021
@tins2831 tins2831 self-assigned this Oct 26, 2021
@tins2831
Copy link
Owner Author

tins2831 commented Oct 26, 2021

The same should apply to the dependencies of the initial specification and to enums.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant