diff --git a/commons/zenoh-config/src/wrappers.rs b/commons/zenoh-config/src/wrappers.rs index 31afe358e..44ccfa7a5 100644 --- a/commons/zenoh-config/src/wrappers.rs +++ b/commons/zenoh-config/src/wrappers.rs @@ -119,6 +119,17 @@ impl Hello { pub fn whatami(&self) -> WhatAmI { self.0.whatami } + + /// Constructs an empty Hello message. + #[zenoh_macros::internal] + pub fn empty() -> Self { + Hello(HelloProto { + version: zenoh_protocol::VERSION, + whatami: WhatAmI::default(), + zid: ZenohIdProto::default(), + locators: Vec::default(), + }) + } } impl From for Hello { diff --git a/zenoh/src/api/query.rs b/zenoh/src/api/query.rs index 4633f6d43..8379ac809 100644 --- a/zenoh/src/api/query.rs +++ b/zenoh/src/api/query.rs @@ -84,6 +84,15 @@ impl ReplyError { pub fn encoding(&self) -> &Encoding { &self.encoding } + + /// Constructs an uninitialized empty ReplyError. + #[zenoh_macros::internal] + pub fn empty() -> Self { + ReplyError { + payload: ZBytes::new(), + encoding: Encoding::default(), + } + } } impl Display for ReplyError { @@ -140,6 +149,15 @@ impl Reply { pub fn replier_id(&self) -> Option { self.replier_id.map(Into::into) } + + /// Constructs an uninitialized empty Reply. + #[zenoh_macros::internal] + pub unsafe fn empty() -> Self { + Reply { + result: Ok(Sample::empty()), + replier_id: None, + } + } } impl From for Result { diff --git a/zenoh/src/api/queryable.rs b/zenoh/src/api/queryable.rs index ad8ab59f8..91bc4af2d 100644 --- a/zenoh/src/api/queryable.rs +++ b/zenoh/src/api/queryable.rs @@ -200,6 +200,17 @@ impl Query { fn _accepts_any_replies(&self) -> ZResult { Ok(self.parameters().reply_key_expr_any()) } + + /// Constructs an empty Query without payload, nor attachment referencing the same inner query. + #[zenoh_macros::internal] + pub unsafe fn empty(&self) -> Self { + Query { + inner: self.inner.clone(), + eid: 0, + value: None, + attachment: None, + } + } } impl fmt::Debug for Query { diff --git a/zenoh/src/api/sample.rs b/zenoh/src/api/sample.rs index b3c5e0ede..376cad51e 100644 --- a/zenoh/src/api/sample.rs +++ b/zenoh/src/api/sample.rs @@ -409,6 +409,22 @@ impl Sample { pub fn attachment_mut(&mut self) -> Option<&mut ZBytes> { self.attachment.as_mut() } + + /// Constructs an uninitialized empty Sample. + #[zenoh_macros::internal] + pub unsafe fn empty() -> Self { + Sample { + key_expr: KeyExpr::from_str_unchecked(""), + payload: ZBytes::new(), + kind: SampleKind::Put, + encoding: Encoding::default(), + timestamp: None, + qos: QoS::default(), + reliability: Reliability::default(), + source_info: SourceInfo::empty(), + attachment: None, + } + } } impl From for Value {