diameter_interface/modeling/message/
command_code.rs1use crate::errors::Error;
2use crate::errors::Error::DecodeError;
3
4#[derive(Debug)]
5pub enum CommandCode {
6 CapabilitiesExchange,
7 ReAuth,
8 Accounting,
9 CreditControl,
10 AbortSession,
11 SessionTermination,
12 DeviceWatchdog,
13 DisconnectPeer,
14}
15
16impl CommandCode {
17 pub fn get_code(&self) -> u32 {
18 match self {
19 CommandCode::CapabilitiesExchange => 257,
20 CommandCode::ReAuth => 258,
21 CommandCode::Accounting => 271,
22 CommandCode::CreditControl => 272,
23 CommandCode::AbortSession => 274,
24 CommandCode::SessionTermination => 275,
25 CommandCode::DeviceWatchdog => 280,
26 CommandCode::DisconnectPeer => 282,
27 }
28 }
29}
30
31impl TryFrom<u32> for CommandCode {
32 type Error = Error;
33
34 fn try_from(value: u32) -> Result<Self, Self::Error> {
35 match value {
36 257 => Ok(CommandCode::CapabilitiesExchange),
37 258 => Ok(CommandCode::ReAuth),
38 271 => Ok(CommandCode::Accounting),
39 272 => Ok(CommandCode::CreditControl),
40 274 => Ok(CommandCode::AbortSession),
41 275 => Ok(CommandCode::SessionTermination),
42 280 => Ok(CommandCode::DeviceWatchdog),
43 282 => Ok(CommandCode::DisconnectPeer),
44 _ => Err(DecodeError("Undefined command code")),
45 }
46 }
47}