kaitai_struct icon indicating copy to clipboard operation
kaitai_struct copied to clipboard

Documentation: Validation and `valid` expressions

Open krisutofu opened this issue 3 years ago • 8 comments

In an internet search I found the Github issue that proposed the valid key and looked into the code to ensure it is there.

I used valid to ensure that a file offset is 16-byte aligned. (Btw, if there is a way of doing it in an imperative manner, please tell me.)

Is the lacking documentation intended, because experimental feature, or could people just try to PR addtions to the documentation?

At the moment, there are five specific expression keywords used in ValidationSpec.scala : min, max, eq, any-of, expr.

krisutofu avatar Dec 31 '21 22:12 krisutofu

Is the lacking documentation intended, because experimental feature, or could people just try to PR addtions to the documentation?

Feel free to contribute the docs. I remember I am using this feature for pretty long time.

KOLANICH avatar Dec 31 '21 23:12 KOLANICH

This is awesome. I didn't spend much time looking into the code. Is a "reverse solver" in service for valid-expressions to yield imperative meaning? This would be great! And definitely a useful replacement for an exception throwing mechanism.

If so, I'll adjust the text for my following documentation PR.

krisutofu avatar Jan 02 '22 00:01 krisutofu

Is a "reverse solver" in service for valid-expressions to yield imperative meaning?

I don't fully understand what you mean. Do you mean serialization? Automatic serialization is not yet implemented.

KOLANICH avatar Jan 02 '22 05:01 KOLANICH

Yes, I meant using valid as a logic-programming facility, which generates serialization code which satisfies the formula at runtime or throws an error if impossible. Although it would be a cutting-edge feature, it's probably low priority, if desired at all.

Generally, formula satisfaction is difficult because predicate logic satisfaction complexity is in PSpace but I believe most practical cases are not worst-case complex. All types in Kaitai-Struct are finite at a point of time so that it is decidable at runtime.

krisutofu avatar Jan 02 '22 17:01 krisutofu

It is one of the long-term goals to automatically derive serialization code. See #27 for more info.

KOLANICH avatar Jan 02 '22 18:01 KOLANICH

I forked Kaitai Struct Doc and pushed my branch to it. What do I need to do now?

Here it is: https://github.com/krisutofu/kaitai_struct

New branch name is 944-valid-documentation.

Btw, I didn't succeed in building the doc with Makefile because of missing raw/pygments.css and docson/*

krisutofu avatar Jan 02 '22 19:01 krisutofu

It is one of the long-term goals to automatically derive serialization code. See #27 for more info.

Yes, a complicated topic. But it's possible at the moment to just save the Kaitai struct representation to a file and throwing an exception if it doesn't verify the parsing rules, right?

krisutofu avatar Jan 02 '22 19:01 krisutofu

Currently serialization to some very minor extent is implemented only for Java target (if I remember right - in a separate branch) + python Construct library has something like that, and there is a target for emitting code for Construct. But IDK if dependencies between fields are implemented and I guess they are not, so if you modify an array which length is stored in another field, I guess you have to update the length manually. Not sure though.

KOLANICH avatar Jan 02 '22 19:01 KOLANICH