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}
37
38impl ScoutingMessage {
39 #[cfg(feature = "test")]
40 pub fn rand() -> Self {
41 use rand::Rng;
42
43 let mut rng = rand::thread_rng();
44
45 match rng.gen_range(0..2) {
46 0 => ScoutingBody::Scout(Scout::rand()),
47 1 => ScoutingBody::Hello(HelloProto::rand()),
48 _ => unreachable!(),
49 }
50 .into()
51 }
52}
53
54impl From<ScoutingBody> for ScoutingMessage {
55 fn from(body: ScoutingBody) -> Self {
56 Self { body }
57 }
58}
59
60impl From<Scout> for ScoutingMessage {
61 fn from(scout: Scout) -> Self {
62 ScoutingBody::Scout(scout).into()
63 }
64}
65
66impl From<HelloProto> for ScoutingMessage {
67 fn from(hello: HelloProto) -> Self {
68 ScoutingBody::Hello(hello).into()
69 }
70}