Skip to content

Use magic to choose an enum variant without consuming the matched data? #247

Answered by kitlith
briandorsey asked this question in Q&A
Discussion options

You must be logged in to vote

As a general rule of thumb, enum variants attempt to be parsed in order, and any parsing error means that the next one is tried. This means that moving the magic directives from the enum variants to your structs will likely do the trick for you, or asserting on your 'id' field if you want it to be a field on the struct.

(I didn't remember this first though, so was going to suggest things like user defined types as magic (I don't even know if that actually works), a generic wrapper whose only job is to provide the FourCC when you're not using the enum, or passing an argument indicating whether or not to parse the magic >_>)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@briandorsey
Comment options

@kitlith
Comment options

Answer selected by briandorsey
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants