From c763e2a0fd903b1579bf08d68f0c930bd3ed9e64 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Tue, 29 Oct 2024 15:02:48 +0100 Subject: [PATCH 1/2] add empty gravestone values for Sample, Reply, Query and Hello --- commons/zenoh-config/src/wrappers.rs | 11 +++++++++++ zenoh/src/api/query.rs | 9 +++++++++ zenoh/src/api/queryable.rs | 11 +++++++++++ zenoh/src/api/sample.rs | 16 ++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/commons/zenoh-config/src/wrappers.rs b/commons/zenoh-config/src/wrappers.rs index 31afe358e7..44ccfa7a52 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 4633f6d437..f3f0c1abcd 100644 --- a/zenoh/src/api/query.rs +++ b/zenoh/src/api/query.rs @@ -140,6 +140,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 ad8ab59f85..91bc4af2de 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 b3c5e0ede5..376cad51ef 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 { From 9dea4c149d555d9b7b6184931d2036cce0b377f8 Mon Sep 17 00:00:00 2001 From: Denis Biryukov Date: Wed, 30 Oct 2024 10:31:59 +0100 Subject: [PATCH 2/2] add empty gravestone value for ReplyErr --- zenoh/src/api/query.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/zenoh/src/api/query.rs b/zenoh/src/api/query.rs index f3f0c1abcd..8379ac8097 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 {