Closed shirok1 closed 6 hours ago
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.
This appears to be fixed:
use deku::prelude::*;
#[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 {
#[deku(bytes_read = "content_size")]
content: Vec<u8>,
},
}
fn main() {
let bytes = &[0x01, 0x02];
let mut c = std::io::Cursor::new(bytes);
let mut r = Reader::new(&mut c);
let s = SomeDataTypeEnum::from_reader_with_ctx(&mut r, (0x0201, 2));
println!("{s:02x?}")
}
> cargo run --example 305
Ok(ThisWontWork { content: [01, 02] })
re-open if you disagree!
Hello, it's me again.
When using an Enum type with external
id
(from context) and anid_pat
on any Enum variant, theread
method (::deku::DekuRead
) implement for that variant will incorrectly try to read the id receiver field again....expands to this:
I suggest adding an explicit attribute for specifying the id receiver.