Closed markcorbinuk closed 2 months ago
Have you tried using the pad_bytes_after
attribute?
https://docs.rs/deku/latest/deku/attributes/index.html#pad_bytes_after
Got it working - thanks.
I'd previously been trying the following which didn't work:
#[deku(update = "self.data.len()")]
count: u16,
#[deku(count = "count", pad_after_bytes = "4 - (self.data.len() % 4)")]
data: Vec<u8>,
...but this works:
#[deku(update = "self.data.len()")]
count: u16,
#[deku(count = "count", pad_after_bytes = "4 - (count % 4)")]
data: Vec<u8>,
:+1:
Closing for now.
Is there a way to add a variable amount of padding so that a data block can always be a multiple of N bytes?
For example, to pad the end of the data block with between 0 and 3 bytes so that 'data + padding' is always a multiple of 4 bytes: