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

Enum Structs #97

Open
nicholascioli opened this issue Feb 27, 2023 · 1 comment
Open

Enum Structs #97

nicholascioli opened this issue Feb 27, 2023 · 1 comment

Comments

@nicholascioli
Copy link

I've used this library for a while and it has been great, but I was wondering if something like packed enum variants would be something that could be potentially in scope for this project.

I have a packed message that, depending on the tag (the first two bytes), has a different layout per message type. Would this library be able to do handle something like the following?

enum Message {
  // When the first two bytes are 0x16
  Variant1 { field1: String, field2: u64 },
  
  // When the first two bytes are 0x01
  Variant2 { other_field1: u8 }
}

Or is this better handled as a separate library? I don't mind contributing, if this seems within scope.

@rudib
Copy link
Member

rudib commented Feb 27, 2023

For now, I wouldn't add this to the codegen/attribute part of the library. But you can easily implement this manually by writing your own logic into a PackedStruct trait implementation and offloading the work on the inner parts of the variants to the codegen'd packing.

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