diff --git a/examples/examples/z_pub.rs b/examples/examples/z_pub.rs index aebca309ad..097b686de9 100644 --- a/examples/examples/z_pub.rs +++ b/examples/examples/z_pub.rs @@ -23,7 +23,7 @@ async fn main() { // Initiate logging env_logger::init(); - let (config, key_expr, value) = parse_args(); + let (config, key_expr, value, attachment) = parse_args(); println!("Opening session..."); let session = zenoh::open(config).res().await.unwrap(); @@ -35,7 +35,16 @@ async fn main() { sleep(Duration::from_secs(1)).await; let buf = format!("[{idx:4}] {value}"); println!("Putting Data ('{}': '{}')...", &key_expr, buf); - publisher.put(buf).res().await.unwrap(); + let mut put = publisher.put(buf); + if let Some(attachment) = &attachment { + put = put.with_attachment( + attachment + .split('&') + .map(|pair| pair.as_bytes().split_at(pair.find('=').unwrap_or(0))) + .collect(), + ) + } + put.res().await.unwrap(); } } @@ -47,11 +56,16 @@ struct Args { #[arg(short, long, default_value = "Pub from Rust!")] /// The value to write. value: String, + #[arg(short, long)] + /// The attachments to add to each put. + /// + /// The key-value pairs are &-separated, and = serves as the separator between key and value. + attach: Option, #[command(flatten)] common: CommonArgs, } -fn parse_args() -> (Config, KeyExpr<'static>, String) { +fn parse_args() -> (Config, KeyExpr<'static>, String, Option) { let args = Args::parse(); - (args.common.into(), args.key, args.value) + (args.common.into(), args.key, args.value, args.attach) } diff --git a/examples/examples/z_pub_thr.rs b/examples/examples/z_pub_thr.rs index a44aed9edd..618115e6f4 100644 --- a/examples/examples/z_pub_thr.rs +++ b/examples/examples/z_pub_thr.rs @@ -16,7 +16,6 @@ use clap::Parser; use std::convert::TryInto; use zenoh::prelude::sync::*; use zenoh::publication::CongestionControl; -use zenoh::sample::AttachmentBuilder; use zenoh_examples::CommonArgs; fn main() { @@ -29,12 +28,7 @@ fn main() { prio = p.try_into().unwrap(); } - let mut payload_size = args.payload_size; - if args.attachments_number != 0 { - let mut att_size = 2 * args.attachments_number; - att_size += 2 + (core::mem::size_of::() * 8 - att_size.leading_zeros() as usize) / 7; - payload_size -= dbg!(att_size); - } + let payload_size = args.payload_size; let data: Value = (0usize..dbg!(payload_size)) .map(|i| (i % 10) as u8) @@ -53,25 +47,7 @@ fn main() { let mut count: usize = 0; let mut start = std::time::Instant::now(); loop { - let attachments = (args.attachments_number != 0).then(|| { - if args.attach_with_insert { - let mut attachments = AttachmentBuilder::new(); - for _ in 0..args.attachments_number { - attachments.insert(b"", b""); - } - attachments.into() - } else { - std::iter::repeat((b"".as_slice(), b"".as_slice())) - .take(args.attachments_number) - .collect() - } - }); - - let mut put = publisher.put(data.clone()); - if let Some(att) = attachments { - put = put.with_attachment(att) - } - put.res().unwrap(); + publisher.put(data.clone()).res().unwrap(); if args.print { if count < args.number { @@ -97,14 +73,6 @@ struct Args { /// Number of messages in each throughput measurements #[arg(short, long, default_value = "100000")] number: usize, - /// The number of attachments in the message. - /// - /// The attachments will be sized such that the attachments replace the payload. - #[arg(long, default_value = "0")] - attachments_number: usize, - /// Attach through insert rather than FromIterator - #[arg(long)] - attach_with_insert: bool, /// Sets the size of the payload to publish payload_size: usize, #[command(flatten)] diff --git a/zenoh/src/publication.rs b/zenoh/src/publication.rs index 1c0f030386..8a84e49566 100644 --- a/zenoh/src/publication.rs +++ b/zenoh/src/publication.rs @@ -122,16 +122,6 @@ impl PutBuilder<'_, '_> { self } - #[zenoh_macros::unstable] - pub fn attachment(&self) -> Option<&Attachment> { - self.attachment.as_ref() - } - - #[zenoh_macros::unstable] - pub fn attachment_mut(&mut self) -> &mut Option { - &mut self.attachment - } - #[zenoh_macros::unstable] pub fn with_attachment(mut self, attachment: Attachment) -> Self { self.attachment = Some(attachment); @@ -674,16 +664,6 @@ pub struct Publication<'a> { } impl<'a> Publication<'a> { - #[zenoh_macros::unstable] - pub fn attachment(&self) -> Option<&Attachment> { - self.attachment.as_ref() - } - - #[zenoh_macros::unstable] - pub fn attachment_mut(&mut self) -> &mut Option { - &mut self.attachment - } - #[zenoh_macros::unstable] pub fn with_attachment(mut self, attachment: Attachment) -> Self { self.attachment = Some(attachment); diff --git a/zenoh/src/query.rs b/zenoh/src/query.rs index 8c62daa882..c4f3fb35e9 100644 --- a/zenoh/src/query.rs +++ b/zenoh/src/query.rs @@ -306,16 +306,6 @@ impl<'a, 'b, Handler> GetBuilder<'a, 'b, Handler> { self } - #[zenoh_macros::unstable] - pub fn attachment(&self) -> Option<&Attachment> { - self.attachment.as_ref() - } - - #[zenoh_macros::unstable] - pub fn attachment_mut(&mut self) -> &mut Option { - &mut self.attachment - } - #[zenoh_macros::unstable] pub fn with_attachment(mut self, attachment: Attachment) -> Self { self.attachment = Some(attachment); diff --git a/zenoh/src/queryable.rs b/zenoh/src/queryable.rs index 6102d6b002..914684f76f 100644 --- a/zenoh/src/queryable.rs +++ b/zenoh/src/queryable.rs @@ -161,22 +161,6 @@ pub struct ReplyBuilder<'a> { } impl<'a> ReplyBuilder<'a> { - #[zenoh_macros::unstable] - pub fn attachment(&self) -> Option<&Attachment> { - match &self.result { - Ok(sample) => sample.attachment.as_ref(), - Err(_) => None, - } - } - - #[zenoh_macros::unstable] - pub fn attachment_mut(&mut self) -> Option<&mut Option> { - match &mut self.result { - Ok(sample) => Some(&mut sample.attachment), - Err(_) => None, - } - } - #[allow(clippy::result_large_err)] #[zenoh_macros::unstable] pub fn with_attachment(mut self, attachment: Attachment) -> Result {