Skip to content

Commit

Permalink
hello wrapped, getters added (#1109)
Browse files Browse the repository at this point in the history
* hello wrapped, getters added

* cargo fmt
  • Loading branch information
milyin authored Jun 10, 2024
1 parent dfd789f commit ad6c414
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
11 changes: 0 additions & 11 deletions commons/zenoh-protocol/src/scouting/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// ZettaScale Zenoh Team, <[email protected]>
//
use alloc::vec::Vec;
use core::fmt;

use crate::core::{Locator, WhatAmI, ZenohId};

Expand Down Expand Up @@ -107,16 +106,6 @@ pub struct Hello {
pub locators: Vec<Locator>,
}

impl fmt::Display for Hello {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Hello")
.field("zid", &self.zid)
.field("whatami", &self.whatami)
.field("locators", &self.locators)
.finish()
}
}

impl Hello {
#[cfg(feature = "test")]
pub fn rand() -> Self {
Expand Down
34 changes: 32 additions & 2 deletions zenoh/src/api/scouting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{

use tokio::net::UdpSocket;
use zenoh_core::{Resolvable, Wait};
use zenoh_protocol::{core::WhatAmIMatcher, scouting::Hello};
use zenoh_protocol::core::WhatAmIMatcher;
use zenoh_result::ZResult;
use zenoh_task::TerminatableTask;

Expand All @@ -30,6 +30,36 @@ use crate::{
net::runtime::{orchestrator::Loop, Runtime},
};

/// A zenoh Hello message.
pub struct Hello(zenoh_protocol::scouting::Hello);

impl Hello {
/// Get the locators of this Hello message.
pub fn locators(&self) -> &[zenoh_protocol::core::Locator] {
&self.0.locators
}

/// Get the zenoh id of this Hello message.
pub fn zid(&self) -> zenoh_protocol::core::ZenohId {
self.0.zid
}

/// Get the whatami of this Hello message.
pub fn whatami(&self) -> zenoh_protocol::core::WhatAmI {
self.0.whatami
}
}

impl fmt::Display for Hello {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Hello")
.field("zid", &self.zid())
.field("whatami", &self.whatami())
.field("locators", &self.locators())
.finish()
}
}

/// A builder for initializing a [`Scout`].
///
/// # Examples
Expand Down Expand Up @@ -324,7 +354,7 @@ fn _scout(
let scout = Runtime::scout(&sockets, what, &addr, move |hello| {
let callback = callback.clone();
async move {
callback(hello);
callback(Hello(hello));
Loop::Continue
}
});
Expand Down
5 changes: 1 addition & 4 deletions zenoh/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,10 +324,7 @@ pub mod handlers {

/// Scouting primitives
pub mod scouting {
/// A zenoh Hello message.
pub use zenoh_protocol::scouting::Hello;

pub use crate::api::scouting::{scout, Scout, ScoutBuilder};
pub use crate::api::scouting::{scout, Hello, Scout, ScoutBuilder};
}

/// Liveliness primitives
Expand Down

0 comments on commit ad6c414

Please sign in to comment.