mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-23 12:09:52 +00:00
83b59c557c
This gives us more control than what serde provides. This PR also moves to use `Bytes` where possible to allow zero-copy parsing of network messages.
35 lines
527 B
Rust
35 lines
527 B
Rust
use epee_encoding::{epee_object, from_bytes, to_bytes};
|
|
|
|
struct AltName {
|
|
val: u8,
|
|
d: u64,
|
|
}
|
|
|
|
epee_object!(
|
|
AltName,
|
|
val("val2"): u8,
|
|
d: u64,
|
|
);
|
|
|
|
struct AltName2 {
|
|
val2: u8,
|
|
d: u64,
|
|
}
|
|
|
|
epee_object!(
|
|
AltName2,
|
|
val2: u8,
|
|
d: u64,
|
|
);
|
|
|
|
#[test]
|
|
fn epee_alt_name() {
|
|
let val2 = AltName2 { val2: 40, d: 30 };
|
|
let bytes = to_bytes(val2).unwrap();
|
|
|
|
let val: AltName = from_bytes(&mut bytes.clone()).unwrap();
|
|
|
|
let bytes2 = to_bytes(val).unwrap();
|
|
|
|
assert_eq!(bytes, bytes2);
|
|
}
|