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

Optional fields #273

Open
KOLANICH opened this issue Sep 27, 2017 · 2 comments
Open

Optional fields #273

KOLANICH opened this issue Sep 27, 2017 · 2 comments

Comments

@KOLANICH
Copy link

KOLANICH commented Sep 27, 2017

Here is pseudocode taking in account templates #135, inlining #88, default values #271 and sizeof #84 proposals

type:
  optional:
    templates:
      - type # the type to be wrapped
    params:
      - id: default_value
        type: type
    seq:
      - id: value
        type: type
        if: should_parse
        inline: true
        default: default_value
    instances:
      should_parse:
        value: lea() + sizeof() <= sizeof(_parent)

This code should parse a field if there is enough space for them in a stream. This kind fields must be in the end of structs. Putting them in the middle is UB.

Usage:

seq:
  - id: a
    type: b
  - id: c
    type: optional<u8>(0) 
@arekbulski
Copy link
Member

Putting them in the middle is UB.

I dont know that slang, what is UB?

@KOLANICH
Copy link
Author

I dont know that slang, what is UB?

Undefined Behavior

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

2 participants