Closed inflation closed 2 years ago
Unfortunately, I don't think there's a good way of doing this at the moment.
At the moment the input bits is relative to the current position, there's not currently a way to look back
#[derive(Clone, Debug, Default, DekuRead, DekuWrite)]
#[deku(endian = "big")]
pub struct DnsPacket {
// ...
#[deku(reader = "dns_record_reader(deku::input_bits, deku::bit_offset, header.resource_entries)")]
pub resources: Vec<DnsRecord>,
}
fn dns_record_reader(
input: &BitSlice<Msb0, u8>,
bit_offset: usize,
count: usize,
) -> Result<(&BitSlice<Msb0, u8>, String), DekuError> {
// read `count` DnsRecord from `input`, while passing `input` to the reader fn of DnsRecord
}
Closing for now
Hi, I'm experimenting some DNS packet parsing. It's great so far, but one of the name resolving field uses an offset of the whole packet, which is not available in a sub structure. I tried to pass it through context, but
ctx
does not acceptdeku::input
or other internal variables. So, how could I achieve that?Here is the code, but
deku::input_bits
only referencing to the remaining bits: