1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
pub mod client;
mod errors;
pub mod location;
mod msg_id;
#[cfg(not(feature = "client-only"))]
pub mod node;
pub mod section_info;
mod serialisation;
pub use self::{
errors::{Error, Result},
location::{Aggregation, DstLocation, EndUser, Itinerary, SrcLocation},
msg_id::MessageId,
serialisation::WireMsg,
};
use bytes::Bytes;
#[derive(PartialEq, Debug)]
#[allow(clippy::large_enum_variant)]
pub enum MessageType {
Ping,
SectionInfo(section_info::Message),
ClientMessage(client::Message),
#[cfg(not(feature = "client-only"))]
NodeMessage(node::NodeMessage),
}
impl MessageType {
pub fn serialize(&self) -> Result<Bytes> {
match self {
Self::Ping => WireMsg::new_ping_msg().serialize(),
Self::SectionInfo(query) => WireMsg::serialize_sectioninfo_msg(query),
Self::ClientMessage(msg) => WireMsg::serialize_client_msg(msg),
#[cfg(not(feature = "client-only"))]
Self::NodeMessage(msg) => WireMsg::serialize_node_msg(msg),
}
}
}