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

hello wrapped, getters added #1109

Merged
merged 2 commits into from
Jun 10, 2024
Merged
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: 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
Loading