Struct smbioslib::UndefinedStruct
source · pub struct UndefinedStruct {
pub header: Header,
pub fields: Vec<u8>,
pub strings: SMBiosStringSet,
}
Expand description
Embodies the three basic parts of an SMBIOS structure
Every SMBIOS structure contains three distinct sections:
- A header
- A formatted structure of fields (offsets and widths)
- String data
A consumer of BIOS data ultimately wants to work with a DefinedStruct. UndefinedStruct provides a set of fields and functions that enables downcasting to a DefinedStruct. Further, the OEM is allowed to define their own structures and in such cases working with UndefinedStruct is necessary. Therefore, UndefinedStruct is public for the case of OEM, as well as when working with structures that are defined in an SMBIOS standard newer than the one this library currently supports.
Fields§
§header: Header
The Header of the structure
fields: Vec<u8>
The raw data for the header and fields
fields
is used by the get_field_*()
functions. fields
does not
include strings; therefore, preventing accidentally retrieving
data from the strings area. This avoids a need to check
header.length()
during field retrieval.
Note: A better design is for this to only hold the fields, however, that will shift field offsets given in code by 4 (the header size). The SMBIOS specification gives offsets relative to the start of the header, and therefore maintaining this library code is easier to keep the header.
An alternative would be to make the get_field_*()
functions adjust
for the header offset though this adds a small cost to every field
retrieval in comparison to just keeping an extra 4 bytes for every
structure.
strings: SMBiosStringSet
The strings of the structure
Implementations§
source§impl<'a> UndefinedStruct
impl<'a> UndefinedStruct
sourcepub fn get_field_byte(&self, offset: usize) -> Option<u8>
pub fn get_field_byte(&self, offset: usize) -> Option<u8>
Retrieve a byte at the given offset from the structure’s data section
sourcepub fn get_field_word(&self, offset: usize) -> Option<u16>
pub fn get_field_word(&self, offset: usize) -> Option<u16>
Retrieve a WORD at the given offset from the structure’s data section
sourcepub fn get_field_handle(&self, offset: usize) -> Option<Handle>
pub fn get_field_handle(&self, offset: usize) -> Option<Handle>
Retrieve a Handle at the given offset from the structure’s data section
sourcepub fn get_field_dword(&self, offset: usize) -> Option<u32>
pub fn get_field_dword(&self, offset: usize) -> Option<u32>
Retrieve a DWORD at the given offset from the structure’s data section
sourcepub fn get_field_qword(&self, offset: usize) -> Option<u64>
pub fn get_field_qword(&self, offset: usize) -> Option<u64>
Retrieve a QWORD at the given offset from the structure’s data section
sourcepub fn get_field_string(&self, offset: usize) -> SMBiosString
pub fn get_field_string(&self, offset: usize) -> SMBiosString
Retrieve a String of the given offset
Retrieval of strings is a two part operation. The given offset contains a byte whose value is a 1 based index into the strings section. The string is thus retrieved from the strings section based on the byte value at the given offset.
sourcepub fn get_field_data(
&self,
start_index: usize,
end_index: usize
) -> Option<&[u8]>
pub fn get_field_data( &self, start_index: usize, end_index: usize ) -> Option<&[u8]>
Retrieve a block of bytes from the structure’s data section
sourcepub fn as_type<T: SMBiosStruct<'a>>(&'a self) -> Option<T>
pub fn as_type<T: SMBiosStruct<'a>>(&'a self) -> Option<T>
Cast to a given structure
When this library does not contain a DefinedStruct variant matching the SMBiosStruct::STRUCT_TYPE, this function affords a cast to the given type. Such would be the case with OEM structure type T (which implements the SMBiosStruct trait).
TODO: This should panic (not be Option) when the STRUCT_TYPE does not match because this would be a logic error in code, not a runtime error.
Make this a “try_into”
sourcepub fn defined_struct(&self) -> DefinedStruct<'_>
pub fn defined_struct(&self) -> DefinedStruct<'_>
Down casts the current structure to its specific defined BIOS structure type