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

Accessing multiple fields #215

Open
KOLANICH opened this issue Jul 30, 2017 · 2 comments
Open

Accessing multiple fields #215

KOLANICH opened this issue Jul 30, 2017 · 2 comments

Comments

@KOLANICH
Copy link

KOLANICH commented Jul 30, 2017

Sometimes a one needs to test thet the record is a terminator. Sometimes terminator is the record containing only zeros. How can we implement this?
1 We can test all the fields that they are zeros. For these we need a syntax allowing this. The most flexible way to do this is to match their names against a regex:

- id: test
  type: a
  repeat: until
  repeat-until: _./.+/

2 another way is to have a syntax to match binary representation. For that we need to have an operator to convert a field into binary and some language to create a sequence of zero bytes.

repeat-until: _.to_binary() == [0x00]*sizeof(a)

IMHO it's nice to have both.

@GreyCat
Copy link
Member

GreyCat commented Jul 31, 2017

"Only zeroes" is, unfortunately, a pretty vague definition. I don't really see any major benefits in "matching their names against a regex":

  • I have no idea what _./.+/ is supposed to mean, or why is that supposed to mean "record containing only zeros".
  • We have seq attributes, parse instances, value instances, parameters — why would all of them must be zeroes?
  • How do we match non-integer data types (i.e. booleans, strings, byte buffers) against "zeroes"?
  • I sincerily doubt that any of real-life parsers ever do that. In reality, 100% of manually rolled parsers that I've seen usually only check 1 or 2 significant fields.

another way is to have a syntax to match binary representation

Probably possible in some cases. I suggest that we'd return to this after implementation of #44.

@KOLANICH
Copy link
Author

KOLANICH commented Jul 31, 2017

I have no idea what _./.+/ is supposed to mean, or why is that supposed to mean "record containing only zeros".

_. is a regular access to subproperties of last parsed element
"/.+/" is the regex matching any string without /n. So
_./.+/ means every property with any name (just any property) from the element

And I'm mistaken. The right condition should be

repeat-until: _./.+/ == 0

We have seq attributes, parse instances, value instances, parameters — why would all of them must be zeroes?

It should be configurable. By default is should match only the properties in ``seq```.

How do we match non-integer data types (i.e. booleans, strings, byte buffers) against "zeroes"?

to_binary()

I sincerily doubt that any of real-life parsers ever do that. In reality, 100% of manually rolled parsers that I've seen usually only check 1 or 2 significant fields.

In some reverse-engineered (from source) specs it is written to do so. And the parser in that repo really does so (and in a bit inefficient way, not sure that compilers can optimize that away).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants