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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use crate::{SMBiosStruct, UndefinedStruct};
use serde::{ser::SerializeStruct, Serialize, Serializer};
use std::{fmt, ops::Deref};
pub struct SMBiosOutOfBandRemoteAccess<'a> {
parts: &'a UndefinedStruct,
}
impl<'a> SMBiosStruct<'a> for SMBiosOutOfBandRemoteAccess<'a> {
const STRUCT_TYPE: u8 = 30u8;
fn new(parts: &'a UndefinedStruct) -> Self {
Self { parts }
}
fn parts(&self) -> &'a UndefinedStruct {
self.parts
}
}
impl<'a> SMBiosOutOfBandRemoteAccess<'a> {
pub fn manufacturer_name(&self) -> Option<String> {
self.parts.get_field_string(0x04)
}
pub fn connections(&self) -> Option<Connections> {
self.parts
.get_field_byte(0x05)
.map(|raw| Connections::from(raw))
}
}
#[derive(PartialEq, Eq)]
pub struct Connections {
pub raw: u8,
}
impl Deref for Connections {
type Target = u8;
fn deref(&self) -> &Self::Target {
&self.raw
}
}
impl From<u8> for Connections {
fn from(raw: u8) -> Self {
Connections { raw }
}
}
impl Connections {
pub fn inbound_connection_enabled(&self) -> bool {
self.raw & 0x01 == 0x01
}
pub fn outbound_connection_enabled(&self) -> bool {
self.raw & 0x02 == 0x02
}
}
impl fmt::Debug for Connections {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct(std::any::type_name::<Connections>())
.field("raw", &self.raw)
.field(
"inbound_connection_enabled",
&self.inbound_connection_enabled(),
)
.field(
"outbound_connection_enabled",
&self.outbound_connection_enabled(),
)
.finish()
}
}
impl Serialize for Connections {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut state = serializer.serialize_struct("Connections", 3)?;
state.serialize_field("raw", &self.raw)?;
state.serialize_field(
"inbound_connection_enabled",
&self.inbound_connection_enabled(),
)?;
state.serialize_field(
"outbound_connection_enabled",
&self.outbound_connection_enabled(),
)?;
state.end()
}
}
impl fmt::Debug for SMBiosOutOfBandRemoteAccess<'_> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct(std::any::type_name::<SMBiosOutOfBandRemoteAccess<'_>>())
.field("header", &self.parts.header)
.field("manufacturer_name", &self.manufacturer_name())
.field("connections", &self.connections())
.finish()
}
}
impl Serialize for SMBiosOutOfBandRemoteAccess<'_> {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
let mut state = serializer.serialize_struct("SMBiosOutOfBandRemoteAccess", 3)?;
state.serialize_field("header", &self.parts.header)?;
state.serialize_field("manufacturer_name", &self.manufacturer_name())?;
state.serialize_field("connections", &self.connections())?;
state.end()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn unit_test() {
let struct_type41 = vec![
30, 0x06, 0x3B, 0x00, 0x01, 0x03, 0x69, 0x6A, 0x6B, 0x6C, 0x00, 0x00,
];
let parts = UndefinedStruct::new(&struct_type41);
let test_struct = SMBiosOutOfBandRemoteAccess::new(&parts);
assert_eq!(test_struct.manufacturer_name(), Some("ijkl".to_string()));
let connections = test_struct.connections().unwrap();
assert!(connections.inbound_connection_enabled());
assert!(connections.outbound_connection_enabled());
assert_eq!(connections.raw, 0x03);
}
}