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

switch-on support for enum #781

Closed
smarek opened this issue Jul 21, 2020 · 1 comment
Closed

switch-on support for enum #781

smarek opened this issue Jul 21, 2020 · 1 comment

Comments

@smarek
Copy link

smarek commented Jul 21, 2020

service protocols has strict type-subtype validation, that would be great to be validated by parser/compiler

specially if values do not match, parsing would fail on enum value not found when parsing instead of later manual programmer checks

example

meta:
  id: protocol
enums:
  general_types:
    0xA0: standard
    0xB0: emergency
  standard_subtypes:
    0x01: standard_a
    0x02: standard_b
  emergency_subtypes:
    0x10: emerg_a
    0x12: emerg_b
    0x13: emerg_c
seq:
  - id: type
    enum: general_types
    type: u1
  - id: subtype
    type: u1
    enum:
      switch-on: type
      cases:
        general_types::standard: standard_subtypes
        general_types::emergency: emergency_subtypes

This also expects the process to be strict when matching values, which depends on resolving #778

@KOLANICH
Copy link

KOLANICH commented Jul 22, 2020

Currently it is done via subtypes. And IMHO it should be done this way - you usually want get different types depending on different enums.

The only use case for your proposal is when the enums are not actually used in the spec.

@smarek smarek closed this as completed Jul 22, 2020
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