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

Add constant/magic value #86

Open
apbr opened this issue Oct 27, 2023 · 2 comments
Open

Add constant/magic value #86

apbr opened this issue Oct 27, 2023 · 2 comments

Comments

@apbr
Copy link

apbr commented Oct 27, 2023

Add the possibility to define some values as constant/magic values.
Such a value is always the same. It can't be changed in the constructor and also has no setter.

Possible syntax:

#[bitsize(13)]
struct Register {
    header: u4,
    body: u7,
   #[magic(Code::Error)]
    code: Code,
}

#[bitsize(2)]
#[derive(FromBits)]
enum Code { Success, Error, IoError, GoodExample }
@hecatia-elegua
Copy link
Owner

There are various concepts called magic number.
File header magic numbers could be excluded when parsing.
If the number is needed afterwards, like in your example supposedly, it would just need a fixed value for code and read-only values I think.

@apbr
Copy link
Author

apbr commented Dec 7, 2023

If the number is needed afterwards, like in your example supposedly, it would just need a fixed value for code and read-only values I think.

Yes, that's what I am looking for, so is this already possible with bilge?

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