You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently trying to implement a Tag-Type-Length-Value structure (TTLV). This is very similar to the TLV structure though it allows you to represent nested structures.
For example let's say I'm trying to represent the structure:
Note this structure could itself be within another structure.
I'm able to implement this in KSY as I can represent each structure tag as it's own Type with it's own Type body. I then say how only certain tag types are allowed within that body. This is what I've come up with so far:
It is very verbose (every structure and structure body requires its own Type) -- not a big issue
I can't ensure that a structure has the required sub tags (e.g. ResponsePayload may not have the required date attribute)
I can't ensure that each sub tag can only have one of a certain amount of types. (I.E. Date can only be a LongInteger or Integer). At least not without implementing types for every sub tag. (Update: I realise that the valid attribute may help with this from Validation of parsed data with assertions #435 but would require more complex conditionals being implemented)
Ideally I'd love a solution that allows me to have optional and required sub tags (E.g. date is required but iv_data is optional).
I'm currently looking at applying a secondary parsing with my own parser to ensure the correct attributes are available for each type. However, I would prefer to do it all in kaitai.
Apologies for the long question though any help would be appreciated :)
P.S. I had a look through many of the questions already asked on the repo and didn't seem to come up with anything that was close to my question. I'm really sorry if someones already asked something similar and I've missed it!
The text was updated successfully, but these errors were encountered:
Thanks for the replies. It's really annoying as I'd love to use kaitai to represent my entire binary structure. It's hard because I'm not sure how much of this is within the scope of kaitai.
However, because kaitai has no way of implementing this currently it means I need to run an additional parser on top, making it no longer language agnostic. 😢
Looking at past issues it seems there is a drag about what to implement as to not make it a full on programming language. I agree this should be something which slows you down, but when it is stopping the language from parsing any complex TLV / TTLV structures... perhaps it needs to be reconsidered?
I'll leave this issues open for a few more days in the hope that something's been missed or a new feature is about to drop! 🤞
generalmimon
changed the title
[Question] What is the best way to implement a TTLV structure?
What is the best way to implement a TTLV structure?
Aug 31, 2020
I'm currently trying to implement a Tag-Type-Length-Value structure (TTLV). This is very similar to the TLV structure though it allows you to represent nested structures.
For example let's say I'm trying to represent the structure:
In TTLV format it looks like this:
Note this structure could itself be within another structure.
I'm able to implement this in KSY as I can represent each structure tag as it's own Type with it's own Type body. I then say how only certain tag types are allowed within that body. This is what I've come up with so far:
The problem with this is:
Ideally I'd love a solution that allows me to have optional and required sub tags (E.g. date is required but iv_data is optional).
I'm currently looking at applying a secondary parsing with my own parser to ensure the correct attributes are available for each type. However, I would prefer to do it all in kaitai.
Apologies for the long question though any help would be appreciated :)
P.S. I had a look through many of the questions already asked on the repo and didn't seem to come up with anything that was close to my question. I'm really sorry if someones already asked something similar and I've missed it!
The text was updated successfully, but these errors were encountered: