From 8d9d187c696d0567a55b3160558c4aa93827ee5a Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Thu, 13 Jun 2024 17:45:01 +0200 Subject: [PATCH] replier_id() returns Option --- zenoh/src/api/query.rs | 7 ++++--- zenoh/src/api/session.rs | 10 +++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/zenoh/src/api/query.rs b/zenoh/src/api/query.rs index d3d4b84bfd..c294839f90 100644 --- a/zenoh/src/api/query.rs +++ b/zenoh/src/api/query.rs @@ -18,6 +18,7 @@ use std::{ time::Duration, }; +use zenoh_config::ZenohId; use zenoh_core::{Resolvable, Wait}; use zenoh_keyexpr::OwnedKeyExpr; use zenoh_protocol::core::{CongestionControl, Parameters, ZenohIdProto}; @@ -117,7 +118,7 @@ impl From for ReplyError { #[derive(Clone, Debug)] pub struct Reply { pub(crate) result: Result, - pub(crate) replier_id: ZenohIdProto, + pub(crate) replier_id: Option, } impl Reply { @@ -137,8 +138,8 @@ impl Reply { } /// Gets the id of the zenoh instance that answered this Reply. - pub fn replier_id(&self) -> ZenohIdProto { - self.replier_id + pub fn replier_id(&self) -> Option { + self.replier_id.map(Into::into) } } diff --git a/zenoh/src/api/session.rs b/zenoh/src/api/session.rs index d6f4b25de6..dc311db1ae 100644 --- a/zenoh/src/api/session.rs +++ b/zenoh/src/api/session.rs @@ -1702,7 +1702,7 @@ impl Session { } (query.callback)(Reply { result: Err(Value::from("Timeout").into()), - replier_id: zid.into(), + replier_id: Some(zid.into()), }); } } @@ -2194,12 +2194,8 @@ impl Primitives for Session { payload: e.payload.into(), encoding: e.encoding.into(), }; - let replier_id = match e.ext_sinfo { - Some(info) => info.id.zid, - None => zenoh_protocol::core::ZenohIdProto::rand(), - }; let new_reply = Reply { - replier_id, + replier_id: e.ext_sinfo.map(|info| info.id.zid), result: Err(value.into()), }; callback(new_reply); @@ -2308,7 +2304,7 @@ impl Primitives for Session { let sample = info.into_sample(key_expr.into_owned(), payload, attachment); let new_reply = Reply { result: Ok(sample), - replier_id: zenoh_protocol::core::ZenohIdProto::rand(), // TODO + replier_id: None, }; let callback = match query.reception_mode {