Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add empty gravestone values for Sample, Reply, ReplyError, Query and Hello #1571

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions commons/zenoh-config/src/wrappers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<HelloProto> for Hello {
Expand Down
18 changes: 18 additions & 0 deletions zenoh/src/api/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -140,6 +149,15 @@ impl Reply {
pub fn replier_id(&self) -> Option<ZenohId> {
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<Reply> for Result<Sample, ReplyError> {
Expand Down
11 changes: 11 additions & 0 deletions zenoh/src/api/queryable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,17 @@ impl Query {
fn _accepts_any_replies(&self) -> ZResult<bool> {
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 {
Expand Down
16 changes: 16 additions & 0 deletions zenoh/src/api/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Sample> for Value {
Expand Down