binrw icon indicating copy to clipboard operation
binrw copied to clipboard

Writing enums: pre_assert?

Open bilts opened this issue 8 months ago • 3 comments

I have code like this:

#[derive(BinRead, BinWrite, Debug)]
#[brw(import(message_type: u8))]
enum MessageData {
  #[br(pre_assert(message_type ==  0x0u8))] Nil {
  },
  ...
}

bw / brw don't allow pre_assert so they can't serialize this. Is there a way to reverse parsing an enum like this? Is it feasible to implement pre_assert for brw?... I don't think using assert is correct.

bilts avatar Jun 19 '24 21:06 bilts