Replies: 1 comment
-
I think I would just use my own enum: use deku::prelude::*;
use dbg_hex::dbg_hex;
#[derive(Debug, DekuWrite, DekuRead)]
#[deku(type = "u32")]
enum Value {
#[deku(id = 0xffffffff)]
None,
#[deku(id_pat = "_")]
Some(u32)
}
fn main() {
let data = [0xff, 0xff, 0xff, 0xff];
let v = Value::from_bytes((&data, 0)).unwrap().1;
assert_eq!(data, &*v.to_bytes().unwrap());
dbg_hex!(v);
let data = [0x01, 0x02, 0x03, 0x04];
let v = Value::from_bytes((&data, 0)).unwrap().1;
assert_eq!(data, &*v.to_bytes().unwrap());
dbg_hex!(v);
}
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Very similar to a previous question, but not quite answered by it.
I have a field in a binary struct that is a
u32
, but uses0xFFFFFFFF
as a sentinel value to meanNone
. I can deserialize this with themap
attribute toOption<u32>
, but I don't think this will work the other way around (None
should be serialized as0xFFFFFFFF
). Is there any way I can achieve this without writing my own write implementation?Beta Was this translation helpful? Give feedback.
All reactions