Skip to content

Commit 1c8ee0e

Browse files
authored
[ZEN-587] Make Reply::replier_id() return an EntityGlobalId (#2052)
* Make replied_id an EntityGlobalId * Use EntityGlobalIdProto internally * Change replier_id of timeout errors to None
1 parent 4499d0b commit 1c8ee0e

File tree

3 files changed

+22
-14
lines changed

3 files changed

+22
-14
lines changed

zenoh/src/api/query.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ use std::{collections::HashMap, error::Error, fmt::Display};
1717
#[cfg(feature = "unstable")]
1818
use serde::Deserialize;
1919
#[cfg(feature = "unstable")]
20-
use zenoh_config::ZenohId;
20+
use zenoh_config::wrappers::EntityGlobalId;
2121
use zenoh_keyexpr::OwnedKeyExpr;
22-
use zenoh_protocol::core::Parameters;
2322
#[cfg(feature = "unstable")]
24-
use zenoh_protocol::core::ZenohIdProto;
23+
use zenoh_protocol::core::EntityGlobalIdProto;
24+
use zenoh_protocol::core::Parameters;
2525
/// The [`Queryable`](crate::query::Queryable)s that should be target of a [`get`](crate::Session::get).
2626
pub use zenoh_protocol::network::request::ext::QueryTarget;
2727
#[doc(inline)]
@@ -129,7 +129,7 @@ impl Error for ReplyError {}
129129
pub struct Reply {
130130
pub(crate) result: Result<Sample, ReplyError>,
131131
#[cfg(feature = "unstable")]
132-
pub(crate) replier_id: Option<ZenohIdProto>,
132+
pub(crate) replier_id: Option<EntityGlobalIdProto>,
133133
}
134134

135135
impl Reply {
@@ -149,10 +149,8 @@ impl Reply {
149149
}
150150

151151
#[zenoh_macros::unstable]
152-
// @TODO: maybe return an `Option<EntityGlobalId>`?
153-
//
154152
/// Gets the id of the zenoh instance that answered this Reply.
155-
pub fn replier_id(&self) -> Option<ZenohId> {
153+
pub fn replier_id(&self) -> Option<EntityGlobalId> {
156154
self.replier_id.map(Into::into)
157155
}
158156

zenoh/src/api/session.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2275,7 +2275,7 @@ impl SessionInner {
22752275
query.callback.call(Reply {
22762276
result: Err(ReplyError::new("Timeout", Encoding::ZENOH_STRING)),
22772277
#[cfg(feature = "unstable")]
2278-
replier_id: Some(session.zid().into()),
2278+
replier_id: None
22792279
});
22802280
}
22812281
}
@@ -2374,7 +2374,7 @@ impl SessionInner {
23742374
query.callback.call(Reply {
23752375
result: Err(ReplyError::new("Timeout", Encoding::ZENOH_STRING)),
23762376
#[cfg(feature = "unstable")]
2377-
replier_id: Some(session.zid().into()),
2377+
replier_id: None
23782378
});
23792379
}
23802380
}
@@ -2814,7 +2814,12 @@ impl Primitives for WeakSession {
28142814
encoding: mem::take(&mut e.encoding).into(),
28152815
}),
28162816
#[cfg(feature = "unstable")]
2817-
replier_id: mem::take(&mut msg.ext_respid).map(|rid| rid.zid),
2817+
replier_id: mem::take(&mut msg.ext_respid).map(|rid| {
2818+
zenoh_protocol::core::EntityGlobalIdProto {
2819+
zid: rid.zid,
2820+
eid: rid.eid,
2821+
}
2822+
}),
28182823
};
28192824
callback.call(new_reply);
28202825
}
@@ -2906,7 +2911,12 @@ impl Primitives for WeakSession {
29062911
let new_reply = Reply {
29072912
result: Ok(sample),
29082913
#[cfg(feature = "unstable")]
2909-
replier_id: mem::take(&mut msg.ext_respid).map(|rid| rid.zid),
2914+
replier_id: mem::take(&mut msg.ext_respid).map(|rid| {
2915+
zenoh_protocol::core::EntityGlobalIdProto {
2916+
zid: rid.zid,
2917+
eid: rid.eid,
2918+
}
2919+
}),
29102920
};
29112921
let callback =
29122922
match query.reception_mode {

zenoh/tests/session.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ async fn test_session_query_reply_internal<Getter: HasGet>(
249249
let rs = getter.get("ok_put").await;
250250
while let Ok(s) = ztimeout!(rs.recv_async()) {
251251
#[cfg(feature = "unstable")]
252-
assert_eq!(s.replier_id(), Some(qbl.id().zid()));
252+
assert_eq!(s.replier_id(), Some(qbl.id()));
253253
let s = s.result().unwrap();
254254
assert_eq!(s.kind(), SampleKind::Put);
255255
assert_eq!(s.payload().len(), size);
@@ -268,7 +268,7 @@ async fn test_session_query_reply_internal<Getter: HasGet>(
268268
let rs = getter.get("ok_del").await;
269269
while let Ok(s) = ztimeout!(rs.recv_async()) {
270270
#[cfg(feature = "unstable")]
271-
assert_eq!(s.replier_id(), Some(qbl.id().zid()));
271+
assert_eq!(s.replier_id(), Some(qbl.id()));
272272
let s = s.result().unwrap();
273273
assert_eq!(s.kind(), SampleKind::Delete);
274274
assert_eq!(s.payload().len(), 0);
@@ -287,7 +287,7 @@ async fn test_session_query_reply_internal<Getter: HasGet>(
287287
let rs = getter.get("err").await;
288288
while let Ok(s) = ztimeout!(rs.recv_async()) {
289289
#[cfg(feature = "unstable")]
290-
assert_eq!(s.replier_id(), Some(qbl.id().zid()));
290+
assert_eq!(s.replier_id(), Some(qbl.id()));
291291
let e = s.result().unwrap_err();
292292
assert_eq!(e.payload().len(), size);
293293
cnt += 1;

0 commit comments

Comments
 (0)