Skip to content

Using magic attribute in struct field #306

Answered by csnover
yeongjet asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, thanks for your question! The magic directive always consumes the matched value. From the docs:

When a magic number is matched, parsing begins with the first byte after the magic number in the data.

Since the magic value must be a constant, storing what is matched is a waste of memory. However, if you really want to store a value and then assert that it matches some thing, you can do that using the assert directive instead.

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@yeongjet
Comment options

@yeongjet
Comment options

@csnover
Comment options

csnover Dec 20, 2024
Collaborator

@yeongjet
Comment options

@yeongjet
Comment options

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

This discussion was converted from issue #305 on December 18, 2024 17:54.