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

Nested Subtypes #35

Closed
hilts-vaughan opened this issue Oct 20, 2016 · 5 comments
Closed

Nested Subtypes #35

hilts-vaughan opened this issue Oct 20, 2016 · 5 comments

Comments

@hilts-vaughan
Copy link

Consider the following YAML type:

    seq:
      - id: frame_entry
        repeat: eos

        # The pages are always 512 byte blocks / pages
        # for some reason... not sure why considering a lot of
        # the data is wasted...
        size: 512

        types:
          junk:
            size: 174
          other:
            size: 338

It'd be nice if we could support the "subtypes", that is types within types. How is this done in Kaistruct today? Is everything top level?

@hilts-vaughan
Copy link
Author

Forget me... I had it intended one level too shallow. :)

DL4PD pushed a commit to DL4PD/kaitai_struct that referenced this issue Mar 13, 2019
spec_ruby_to_go: fix assert equal ordering
@LmpOSX
Copy link

LmpOSX commented Feb 16, 2020

Hi, I wonder if this is already implemented, or I'm using it the wrong way.
I'm trying to consolidate various individual ksy files into one file, and then calling those as subtypes, but I'm not getting the expected results at least under python. However using opaques, It works.
How should I use it, if it is implemented?

Follow is the example

File test1.ksy

meta:
  id: test1
  imports:
    - test2

seq:
  - id: test3
    type: test2::test3

I got the following python, no import test2, and no test2.Test3 neither

class Test1(KaitaiStruct):
    def __init__(self, _io, _parent=None, _root=None):
        self._io = _io
        self._parent = _parent
        self._root = _root if _root else self
        self._read()

    def _read(self):
        self.test3 = self._root.Test3(self._io, self, self._root)

However, if I use opaque-types as follows:

File test1.ksy

meta:
  id: test1
  ks-opaque-types: true

seq:
  - id: test3
    type: test2::test3

Then python code is:

import test2
class Test1(KaitaiStruct):
    def __init__(self, _io, _parent=None, _root=None):
        self._io = _io
        self._parent = _parent
        self._root = _root if _root else self
        self._read()

    def _read(self):
        self.test3 = test2.self._root.Test3(self._io)

@KOLANICH
Copy link

KOLANICH commented Feb 16, 2020

Unfortuantely the addressing scheme is contoversal. Enums and their values names are separated with ::, but types and subtypes are separated with .

@GreyCat
Copy link
Member

GreyCat commented Feb 17, 2020

@LmpOSX This is a new bug report, I've split it into separate issue. Let's continue there.

@KOLANICH Please don't leave misleading comments. type: test2::test3 is perfectly correct and valid.

@KOLANICH
Copy link

I just remembered the discussion in #452.

BTW, #487, #275, are they fixed?

krisutofu pushed a commit to krisutofu/kaitai_struct that referenced this issue Jan 2, 2022
* Fix `_index` examples, add behavior of keys in repetition

* Fix style in the "keys in repetition" section
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants