sharksforarms / deku

Declarative binary reading and writing: bit-level, symmetric, serialization/deserialization
Apache License 2.0
1.05k stars 54 forks source link

Reader and Writer should modify value of Option. #327

Open Frostie314159 opened 1 year ago

Frostie314159 commented 1 year ago

When using a conditional field, the reader and writer functions should operate on the value of the option. And not the option itself.

wcampbell0x2a commented 1 year ago

Do you have an example of your expected behavior?

Frostie314159 commented 1 year ago

Currently I'm trying to parse radiotap headers with deku. Radiotap has a fixed header and the rest of the fields are only present, if their specific bit has been set in the header. Some of these fields are bitflags, for which I've written parser functions. In my struct they are defined as Options: ``` struct header { //...

[deku(

    cond="present_fields.contains(IEEE80211RadiotapFields::Flags)",  
    reader = "read_bitflags(deku::rest)",
    writer = "write_bitflags(deku::output, &self.present_fields)")]
flags: Option\<IEEE80211RadiotapFlags\>,

//... }

sharksforarms commented 1 year ago

I'm not sure I fully understand the question and expected behavior. Can you provide a minimal running example w/ comments which would hilight the issue?