Skip to content

Commit

Permalink
Add payload serializer test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Apr 10, 2024
1 parent 2780958 commit 3484fa0
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions zenoh/src/payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(&self) -> PayloadIterator<'_, T>
where
Expand All @@ -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
Expand Down Expand Up @@ -1419,5 +1419,14 @@ mod tests {
println!("Deserialize:\t{:?}\n", p);
let o = HashMap::from_iter(p.iter::<(usize, Vec<u8>)>());
assert_eq!(hm, o);

let mut hm: HashMap<String, String> = 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);
}
}

0 comments on commit 3484fa0

Please sign in to comment.