smbioslib/structs/types/
oem_strings.rs

1use crate::{SMBiosStringSet, SMBiosStruct, UndefinedStruct};
2use serde::{ser::SerializeStruct, Serialize, Serializer};
3use std::fmt;
4
5/// # OEM Strings (Type 11)
6///
7/// This structure contains free-form strings defined by the OEM. Examples of this are
8/// part numbers for system reference documents, contact information for the manufacturer, etc.
9///
10/// Compliant with:
11/// DMTF SMBIOS Reference Specification 3.4.0 (DSP0134)
12/// Document Date: 2020-07-17
13pub struct SMBiosOemStrings<'a> {
14    parts: &'a UndefinedStruct,
15}
16
17impl<'a> SMBiosStruct<'a> for SMBiosOemStrings<'a> {
18    const STRUCT_TYPE: u8 = 11u8;
19
20    fn new(parts: &'a UndefinedStruct) -> Self {
21        Self { parts }
22    }
23
24    fn parts(&self) -> &'a UndefinedStruct {
25        self.parts
26    }
27}
28
29impl<'a> SMBiosOemStrings<'a> {
30    /// Number of strings
31    pub fn count(&self) -> Option<u8> {
32        self.parts.get_field_byte(0x04)
33    }
34
35    /// Iterable collection of OEM strings
36    pub fn oem_strings(&self) -> &SMBiosStringSet {
37        &self.parts.strings
38    }
39}
40
41impl fmt::Debug for SMBiosOemStrings<'_> {
42    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
43        fmt.debug_struct(std::any::type_name::<SMBiosOemStrings<'_>>())
44            .field("header", &self.parts.header)
45            .field("count", &self.count())
46            .field("oem_strings", &self.oem_strings())
47            .finish()
48    }
49}
50
51impl Serialize for SMBiosOemStrings<'_> {
52    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
53    where
54        S: Serializer,
55    {
56        let mut state = serializer.serialize_struct("SMBiosOemStrings", 3)?;
57        state.serialize_field("header", &self.parts.header)?;
58        state.serialize_field("count", &self.count())?;
59        state.serialize_field("oem_strings", &self.oem_strings())?;
60        state.end()
61    }
62}
63
64#[cfg(test)]
65mod tests {
66    use super::*;
67
68    #[test]
69    fn unit_test() {
70        let struct_type6 = vec![
71            0x0B, 0x05, 0x04, 0x00, 0x03, 0x41, 0x42, 0x53, 0x20, 0x37, 0x30, 0x2F, 0x37, 0x31,
72            0x20, 0x36, 0x30, 0x20, 0x36, 0x31, 0x20, 0x36, 0x32, 0x20, 0x36, 0x33, 0x3B, 0x00,
73            0x46, 0x42, 0x59, 0x54, 0x45, 0x23, 0x32, 0x55, 0x33, 0x45, 0x33, 0x58, 0x34, 0x37,
74            0x36, 0x4A, 0x36, 0x53, 0x36, 0x62, 0x37, 0x42, 0x37, 0x48, 0x37, 0x4D, 0x37, 0x51,
75            0x37, 0x54, 0x37, 0x57, 0x37, 0x61, 0x37, 0x6A, 0x37, 0x6D, 0x61, 0x33, 0x61, 0x70,
76            0x61, 0x71, 0x61, 0x75, 0x62, 0x37, 0x2E, 0x51, 0x33, 0x3B, 0x00, 0x42, 0x55, 0x49,
77            0x4C, 0x44, 0x49, 0x44, 0x23, 0x31, 0x33, 0x57, 0x57, 0x43, 0x44, 0x43, 0x38, 0x36,
78            0x30, 0x31, 0x23, 0x53, 0x41, 0x42, 0x41, 0x23, 0x44, 0x41, 0x42, 0x41, 0x3B, 0x00,
79            0x00,
80        ];
81
82        let parts = UndefinedStruct::new(&struct_type6);
83        let test_struct = SMBiosOemStrings::new(&parts);
84
85        assert_eq!(test_struct.count(), Some(0x03));
86
87        let mut iter = test_struct.oem_strings().into_iter();
88        assert_eq!(
89            iter.next().unwrap().ok(),
90            Some("ABS 70/71 60 61 62 63;".to_string())
91        );
92        assert_eq!(
93            iter.next().unwrap().ok(),
94            Some("FBYTE#2U3E3X476J6S6b7B7H7M7Q7T7W7a7j7ma3apaqaub7.Q3;".to_string())
95        );
96        assert_eq!(
97            iter.next().unwrap().ok(),
98            Some("BUILDID#13WWCDC8601#SABA#DABA;".to_string())
99        );
100    }
101}