Skip to main content

doip_definitions/doip_payload/
action_code.rs

1use crate::error::{Error, Result};
2
3/// Used in Vehicle Announcement Messages to give next steps.
4///
5/// Used to inform the client of further actions which need to be taken on a
6/// `DoIP` server.
7#[cfg_attr(feature = "python-bindings", pyo3::pyclass(eq, eq_int))]
8#[derive(Clone, Copy, Debug, PartialEq)]
9pub enum ActionCode {
10    /// No Further Action Required
11    NoFurtherActionRequired = 0x00,
12
13    /// Reserved By ISO-13400 for bytes value `01`
14    ReservedByIso13400_01 = 0x01,
15
16    /// Reserved By ISO-13400 for bytes value `02`
17    ReservedByIso13400_02 = 0x02,
18
19    /// Reserved By ISO-13400 for bytes value `03`
20    ReservedByIso13400_03 = 0x03,
21
22    /// Reserved By ISO-13400 for bytes value `04`
23    ReservedByIso13400_04 = 0x04,
24
25    /// Reserved By ISO-13400 for bytes value `05`
26    ReservedByIso13400_05 = 0x05,
27
28    /// Reserved By ISO-13400 for bytes value `06`
29    ReservedByIso13400_06 = 0x06,
30
31    /// Reserved By ISO-13400 for bytes value `07`
32    ReservedByIso13400_07 = 0x07,
33
34    /// Reserved By ISO-13400 for bytes value `08`
35    ReservedByIso13400_08 = 0x08,
36
37    /// Reserved By ISO-13400 for bytes value `09`
38    ReservedByIso13400_09 = 0x09,
39
40    /// Reserved By ISO-13400 for bytes value `0A`
41    ReservedByIso13400_0A = 0x0A,
42
43    /// Reserved By ISO-13400 for bytes value `0B`
44    ReservedByIso13400_0B = 0x0B,
45
46    /// Reserved By ISO-13400 for bytes value `0C`
47    ReservedByIso13400_0C = 0x0C,
48
49    /// Reserved By ISO-13400 for bytes value `0D`
50    ReservedByIso13400_0D = 0x0D,
51
52    /// Reserved By ISO-13400 for bytes value `0E`
53    ReservedByIso13400_0E = 0x0E,
54
55    /// Reserved By ISO-13400 for bytes value `0F`
56    ReservedByIso13400_0F = 0x0F,
57
58    /// Routing Activation Required
59    RoutingActivationRequired = 0x10,
60}
61
62impl TryFrom<&u8> for ActionCode {
63    type Error = Error;
64
65    fn try_from(value: &u8) -> Result<Self> {
66        let val = *value;
67
68        match val {
69            v if v == ActionCode::NoFurtherActionRequired as u8 => {
70                Ok(ActionCode::NoFurtherActionRequired)
71            }
72            v if v == ActionCode::ReservedByIso13400_01 as u8 => {
73                Ok(ActionCode::ReservedByIso13400_01)
74            }
75            v if v == ActionCode::ReservedByIso13400_02 as u8 => {
76                Ok(ActionCode::ReservedByIso13400_02)
77            }
78            v if v == ActionCode::ReservedByIso13400_03 as u8 => {
79                Ok(ActionCode::ReservedByIso13400_03)
80            }
81            v if v == ActionCode::ReservedByIso13400_04 as u8 => {
82                Ok(ActionCode::ReservedByIso13400_04)
83            }
84            v if v == ActionCode::ReservedByIso13400_05 as u8 => {
85                Ok(ActionCode::ReservedByIso13400_05)
86            }
87            v if v == ActionCode::ReservedByIso13400_06 as u8 => {
88                Ok(ActionCode::ReservedByIso13400_06)
89            }
90            v if v == ActionCode::ReservedByIso13400_07 as u8 => {
91                Ok(ActionCode::ReservedByIso13400_07)
92            }
93            v if v == ActionCode::ReservedByIso13400_08 as u8 => {
94                Ok(ActionCode::ReservedByIso13400_08)
95            }
96            v if v == ActionCode::ReservedByIso13400_09 as u8 => {
97                Ok(ActionCode::ReservedByIso13400_09)
98            }
99            v if v == ActionCode::ReservedByIso13400_0A as u8 => {
100                Ok(ActionCode::ReservedByIso13400_0A)
101            }
102            v if v == ActionCode::ReservedByIso13400_0B as u8 => {
103                Ok(ActionCode::ReservedByIso13400_0B)
104            }
105            v if v == ActionCode::ReservedByIso13400_0C as u8 => {
106                Ok(ActionCode::ReservedByIso13400_0C)
107            }
108            v if v == ActionCode::ReservedByIso13400_0D as u8 => {
109                Ok(ActionCode::ReservedByIso13400_0D)
110            }
111            v if v == ActionCode::ReservedByIso13400_0E as u8 => {
112                Ok(ActionCode::ReservedByIso13400_0E)
113            }
114            v if v == ActionCode::ReservedByIso13400_0F as u8 => {
115                Ok(ActionCode::ReservedByIso13400_0F)
116            }
117            v if v == ActionCode::RoutingActivationRequired as u8 => {
118                Ok(ActionCode::RoutingActivationRequired)
119            }
120            v => Err(Error::InvalidActionCode { value: v }),
121        }
122    }
123}
124
125impl From<ActionCode> for u8 {
126    fn from(value: ActionCode) -> Self {
127        value as u8
128    }
129}