diff --git a/rust/radixbuf/src/serialize.rs b/rust/radixbuf/src/serialize.rs --- a/rust/radixbuf/src/serialize.rs +++ b/rust/radixbuf/src/serialize.rs @@ -110,6 +110,28 @@ } } +#[derive(Debug, PartialEq, Clone)] +pub struct LinkedNode(T, Offset>); + +impl LinkedNode { + pub fn new(value: T, offset: Offset>) -> Self { LinkedNode(value, offset) } +} + +impl Serialize for LinkedNode { + fn write_to(&self, w: &mut W) -> io::Result<()> { + self.0.write_to(w)?; + self.1.write_to(w) + } + + fn read_from(r: &mut R) -> io::Result { + let value: T = T::read_from(r)?; + let offset = Offset::read_from(r)?; + Ok(LinkedNode::new(value, offset)) + } +} + +impl FixedSizedSerialize for LinkedNode {} + macro_rules! impl_serialize_unsigned { ($T: ty, $S: expr) => { impl Serialize for $T { @@ -182,6 +204,15 @@ fn shrink(&self) -> Box> { unimplemented!() } } + impl Arbitrary for LinkedNode { + fn arbitrary(gen: &mut G) -> Self { + LinkedNode::new(T::arbitrary(gen), unsafe { + Offset::from_raw(u64::arbitrary(gen)) + }) + } + fn shrink(&self) -> Box> { unimplemented!() } + } + fn check_round_trip(keys: Vec) -> bool { let mut buf = Buffer(Rc::new(RefCell::new(Cursor::new(vec![])))); let mut offsets: Vec> = vec![]; @@ -221,6 +252,14 @@ fn test_round_trip_u64(v: Vec) -> bool { check_round_trip(v) } + + fn test_round_trip_linkednode_variantbytes(v: Vec>) -> bool { + check_round_trip(v) + } + + fn test_round_trip_linkednode_u32(v: Vec>) -> bool { + check_round_trip(v) + } } #[test]