zenoh_protocol/scouting/
mod.rspub mod hello;
pub mod scout;
pub use hello::HelloProto;
pub use scout::Scout;
pub mod id {
pub const SCOUT: u8 = 0x01;
pub const HELLO: u8 = 0x02;
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ScoutingBody {
Scout(Scout),
Hello(HelloProto),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ScoutingMessage {
pub body: ScoutingBody,
#[cfg(feature = "stats")]
pub size: Option<core::num::NonZeroUsize>,
}
impl ScoutingMessage {
#[cfg(feature = "test")]
pub fn rand() -> Self {
use rand::Rng;
let mut rng = rand::thread_rng();
match rng.gen_range(0..2) {
0 => ScoutingBody::Scout(Scout::rand()),
1 => ScoutingBody::Hello(HelloProto::rand()),
_ => unreachable!(),
}
.into()
}
}
impl From<ScoutingBody> for ScoutingMessage {
fn from(body: ScoutingBody) -> Self {
Self {
body,
#[cfg(feature = "stats")]
size: None,
}
}
}
impl From<Scout> for ScoutingMessage {
fn from(scout: Scout) -> Self {
ScoutingBody::Scout(scout).into()
}
}
impl From<HelloProto> for ScoutingMessage {
fn from(hello: HelloProto) -> Self {
ScoutingBody::Hello(hello).into()
}
}