Skip to content

Commit

Permalink
refactor: replace extension traits by dedicated types
Browse files Browse the repository at this point in the history
  • Loading branch information
wyfo committed Sep 26, 2024
1 parent 4d238f9 commit 254698d
Show file tree
Hide file tree
Showing 5 changed files with 378 additions and 360 deletions.
19 changes: 9 additions & 10 deletions examples/examples/z_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,33 +72,32 @@ fn main() {

// zenoh-ext serialization
{
// Requires to import zenoh-ext trait
use zenoh_ext::ZBytesExt;
use zenoh_ext::{z_deserialize, z_serialize};

// Numeric types: u8, u16, u32, u128, i8, i16, i32, i128, f32, f64
let input = 1234_u32;
let payload = ZBytes::serialize(&input);
let output: u32 = payload.deserialize().unwrap();
let payload = z_serialize(&input);
let output: u32 = z_deserialize(&payload).unwrap();
assert_eq!(input, output);

// Vec
let input = vec![0.0f32, 1.5, 42.0];
let payload = ZBytes::serialize(&input);
let output: Vec<f32> = payload.deserialize().unwrap();
let payload = z_serialize(&input);
let output: Vec<f32> = z_deserialize(&payload).unwrap();
assert_eq!(input, output);

// HashMap
let mut input: HashMap<u32, String> = HashMap::new();
input.insert(0, String::from("abc"));
input.insert(1, String::from("def"));
let payload = ZBytes::serialize(&input);
let output: HashMap<u32, String> = payload.deserialize().unwrap();
let payload = z_serialize(&input);
let output: HashMap<u32, String> = z_deserialize(&payload).unwrap();
assert_eq!(input, output);

// Tuple
let input = (0.42f64, "string".to_string());
let payload = ZBytes::serialize(&input);
let output: (f64, String) = payload.deserialize().unwrap();
let payload = z_serialize(&input);
let output: (f64, String) = z_deserialize(&payload).unwrap();
assert_eq!(input, output);

// Look at Serialize/Deserialize documentation for the exhaustive
Expand Down
10 changes: 5 additions & 5 deletions zenoh-ext/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ shared-memory = ["zenoh/shared-memory"]

[dependencies]
tokio = { workspace = true, features = [
"rt",
"sync",
"time",
"macros",
"io-std",
"rt",
"sync",
"time",
"macros",
"io-std",
] }
bincode = { workspace = true }
zenoh-util = { workspace = true }
Expand Down
10 changes: 5 additions & 5 deletions zenoh-ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
pub mod group;
mod publication_cache;
mod querying_subscriber;
mod serialization;
mod session_ext;
mod subscriber_ext;
mod zbytes_ext;

pub use publication_cache::{PublicationCache, PublicationCacheBuilder};
pub use querying_subscriber::{
FetchingSubscriber, FetchingSubscriberBuilder, QueryingSubscriberBuilder,
};
pub use serialization::{
z_deserialize, z_serialize, Deserialize, Serialize, ZDeserializeError, ZDeserializer,
ZReadIter, ZSerializer,
};
pub use session_ext::SessionExt;
pub use subscriber_ext::{SubscriberBuilderExt, SubscriberForward};
pub use zbytes_ext::{
Deserialize, Serialize, ZBytesExt, ZBytesReaderExt, ZBytesWriterExt, ZDeserializeError,
ZReadIter,
};
use zenoh::{internal::zerror, query::Reply, sample::Sample, Result as ZResult};

/// The space of keys to use in a [`FetchingSubscriber`].
Expand Down
Loading

0 comments on commit 254698d

Please sign in to comment.