ipmi_rs/connection/
netfn.rs1macro_rules! netfn {
2 ($($name:ident => [$req:literal | $resp:literal]),*) => {
3 #[derive(Debug, Clone, Copy, PartialEq)]
4 pub enum NetFn {
5 $($name,)*
6 Reserved(u8),
7 }
8
9 impl From<u8> for NetFn {
10 fn from(value: u8) -> Self {
11 match value {
12 $($req | $resp => Self::$name,)*
13 v => Self::Reserved(v),
14 }
15 }
16 }
17
18 impl NetFn {
19 pub fn is_response_value(v: u8) -> bool {
20 v % 2 == 0
21 }
22
23 pub fn is_request_value(v: u8) -> bool {
24 !Self::is_response_value(v)
25 }
26
27 pub fn request_value(&self) -> u8 {
28 match self {
29 $(Self::$name => $req,)*
30 Self::Reserved(v) => {
31 if v % 2 == 1 {
32 v - 1
33 } else {
34 *v
35 }
36 }
37 }
38 }
39
40 pub fn response_value(&self) -> u8 {
41 match self {
42 $(Self::$name => $resp,)*
43 NetFn::Reserved(v) => {
44 if v % 2 == 0 {
45 v + 1
46 } else {
47 *v
48 }
49 }
50 }
51 }
52 }
53 };
54}
55
56netfn!(
57 Chassis => [0x00 | 0x01],
58 Bridge => [0x02 | 0x03],
59 SensorEvent => [0x04 | 0x05],
60 App => [0x06 | 0x07],
61 Firmware => [0x08 | 0x09],
62 Storage => [0x0A | 0x0B],
63 Transport => [0x0C | 0x0D]
64);