From 3484fa0f7905103f58b25440de84cd5e1e567f60 Mon Sep 17 00:00:00 2001 From: Luca Cominardi Date: Wed, 10 Apr 2024 17:05:22 +0200 Subject: [PATCH] Add payload serializer test --- zenoh/src/payload.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/zenoh/src/payload.rs b/zenoh/src/payload.rs index 39a8ca8932..796ec39328 100644 --- a/zenoh/src/payload.rs +++ b/zenoh/src/payload.rs @@ -91,6 +91,11 @@ impl Payload { Ok(Payload::new(buf)) } + /// Get a [`PayloadWriter`] implementing [`std::io::Write`] trait. + pub fn writer(&mut self) -> PayloadWriter<'_> { + PayloadWriter(self.0.writer()) + } + /// Get a [`PayloadReader`] implementing [`std::io::Read`] trait. pub fn iter(&self) -> PayloadIterator<'_, T> where @@ -104,11 +109,6 @@ impl Payload { } } - /// Get a [`PayloadWriter`] implementing [`std::io::Write`] trait. - pub fn writer(&mut self) -> PayloadWriter<'_> { - PayloadWriter(self.0.writer()) - } - /// Serialize an object of type `T` as a [`Value`] using the [`ZSerde`]. /// /// ```rust @@ -1419,5 +1419,14 @@ mod tests { println!("Deserialize:\t{:?}\n", p); let o = HashMap::from_iter(p.iter::<(usize, Vec)>()); assert_eq!(hm, o); + + let mut hm: HashMap = HashMap::new(); + hm.insert(String::from("0"), String::from("a")); + hm.insert(String::from("1"), String::from("b")); + println!("Serialize:\t{:?}", hm); + let p = Payload::from_iter(hm.iter()); + println!("Deserialize:\t{:?}\n", p); + let o = HashMap::from_iter(p.iter::<(String, String)>()); + assert_eq!(hm, o); } }