deku
deku copied to clipboard
`id_pat` with external `id`
Hello, it's me again.
When using an Enum type with external id
(from context) and an id_pat
on any Enum variant, the read
method (::deku::DekuRead
) implement for that variant will incorrectly try to read the id receiver field again.
#[deku_derive(DekuRead, DekuWrite)]
#[derive(Debug)]
#[deku(ctx = "content_id: u16, content_size: u16", id = "content_id")]
pub enum SomeDataTypeEnum {
// #[deku(id = "0x0200")]
// ThisWorks {
// #[deku(bytes_read = "content_size")]
// content: Vec<u8>,
// },
#[deku(id_pat = "0x0201..=0x02FF")]
ThisWontWork {
content_id: u16,
#[deku(bytes_read = "content_size")]
content: Vec<u8>,
},
}
...expands to this:
0x0201..=0x02FF => {
let __deku_id = {
let (__deku_new_rest, __deku_value) = <u16 as ::deku::DekuRead<
'_,
_,
>>::read(__deku_rest, ())?;
let __deku_value: u16 = Result::<
_,
::deku::DekuError,
>::Ok(__deku_value)?;
__deku_rest = __deku_new_rest;
__deku_value
};
let content_id = &__deku_id;
I suggest adding an explicit attribute for specifying the id receiver.
thanks for the report.
In the meantime, can you confirm this is a valid work-around?
#[deku(skip, default = "content_id")]
content_id: u16,
Can you confirm this is a valid work-around?
#[deku(skip, default = "content_id")] content_id: u16,
Yes, it works. :rofl: Pretty strange.