zenoh_protocol/scouting/
mod.rs1pub mod hello;
15pub mod scout;
16
17pub use hello::HelloProto;
18pub use scout::Scout;
19
20pub mod id {
21 pub const SCOUT: u8 = 0x01;
23 pub const HELLO: u8 = 0x02;
24}
25
26#[derive(Debug, Clone, PartialEq, Eq)]
28pub enum ScoutingBody {
29 Scout(Scout),
30 Hello(HelloProto),
31}
32
33#[derive(Debug, Clone, PartialEq, Eq)]
34pub struct ScoutingMessage {
35 pub body: ScoutingBody,
36 #[cfg(feature = "stats")]
37 pub size: Option<core::num::NonZeroUsize>,
38}
39
40impl ScoutingMessage {
41 #[cfg(feature = "test")]
42 pub fn rand() -> Self {
43 use rand::Rng;
44
45 let mut rng = rand::thread_rng();
46
47 match rng.gen_range(0..2) {
48 0 => ScoutingBody::Scout(Scout::rand()),
49 1 => ScoutingBody::Hello(HelloProto::rand()),
50 _ => unreachable!(),
51 }
52 .into()
53 }
54}
55
56impl From<ScoutingBody> for ScoutingMessage {
57 fn from(body: ScoutingBody) -> Self {
58 Self {
59 body,
60 #[cfg(feature = "stats")]
61 size: None,
62 }
63 }
64}
65
66impl From<Scout> for ScoutingMessage {
67 fn from(scout: Scout) -> Self {
68 ScoutingBody::Scout(scout).into()
69 }
70}
71
72impl From<HelloProto> for ScoutingMessage {
73 fn from(hello: HelloProto) -> Self {
74 ScoutingBody::Hello(hello).into()
75 }
76}