use serde::Serialize;
use std::iter::FromIterator;
use crate::core::UndefinedStruct;
use super::*;
#[derive(Serialize, Debug)]
pub enum DefinedStruct<'a> {
Information(SMBiosInformation<'a>),
SystemInformation(SMBiosSystemInformation<'a>),
BaseBoardInformation(SMBiosBaseboardInformation<'a>),
SystemChassisInformation(SMBiosSystemChassisInformation<'a>),
ProcessorInformation(SMBiosProcessorInformation<'a>),
MemoryControllerInformation(SMBiosMemoryControllerInformation<'a>),
MemoryModuleInformation(SMBiosMemoryModuleInformation<'a>),
CacheInformation(SMBiosCacheInformation<'a>),
PortConnectorInformation(SMBiosPortConnectorInformation<'a>),
SystemSlot(SMBiosSystemSlot<'a>),
OnBoardDeviceInformation(SMBiosOnBoardDeviceInformation<'a>),
OemStrings(SMBiosOemStrings<'a>),
SystemConfigurationOptions(SMBiosSystemConfigurationOptions<'a>),
LanguageInformation(SMBiosBiosLanguageInformation<'a>),
GroupAssociations(SMBiosGroupAssociations<'a>),
EventLog(SMBiosSystemEventLog<'a>),
PhysicalMemoryArray(SMBiosPhysicalMemoryArray<'a>),
MemoryDevice(SMBiosMemoryDevice<'a>),
MemoryErrorInformation32Bit(SMBiosMemoryErrorInformation32<'a>),
MemoryArrayMappedAddress(SMBiosMemoryArrayMappedAddress<'a>),
MemoryDeviceMappedAddress(SMBiosMemoryDeviceMappedAddress<'a>),
BuiltInPointingDevice(SMBiosBuiltInPointingDevice<'a>),
PortableBattery(SMBiosPortableBattery<'a>),
SystemReset(SMBiosSystemReset<'a>),
HardwareSecurity(SMBiosHardwareSecurity<'a>),
SystemPowerControls(SMBiosSystemPowerControls<'a>),
VoltageProbe(SMBiosVoltageProbe<'a>),
CoolingDevice(SMBiosCoolingDevice<'a>),
TemperatureProbe(SMBiosTemperatureProbe<'a>),
ElectricalCurrentProbe(SMBiosElectricalCurrentProbe<'a>),
OutOfBandRemoteAccess(SMBiosOutOfBandRemoteAccess<'a>),
BisEntryPoint(SMBiosBisEntryPoint<'a>),
SystemBootInformation(SMBiosSystemBootInformation<'a>),
MemoryErrorInformation64Bit(SMBiosMemoryErrorInformation64<'a>),
ManagementDevice(SMBiosManagementDevice<'a>),
ManagementDeviceComponent(SMBiosManagementDeviceComponent<'a>),
ManagementDeviceThresholdData(SMBiosManagementDeviceThresholdData<'a>),
MemoryChannel(SMBiosMemoryChannel<'a>),
IpmiDeviceInformation(SMBiosIpmiDeviceInformation<'a>),
SystemPowerSupply(SMBiosSystemPowerSupply<'a>),
AdditionalInformation(SMBiosAdditionalInformation<'a>),
OnboardDevicesExtendedInformation(SMBiosOnboardDevicesExtendedInformation<'a>),
ManagementControllerHostInterface(SMBiosManagementControllerHostInterface<'a>),
TpmDevice(SMBiosTpmDevice<'a>),
ProcessorAdditionalInformation(SMBiosProcessorAdditionalInformation<'a>),
FirmwareInventoryInformation(SMBiosFirmwareInventoryInformation<'a>),
StringProperty(SMBiosStringProperty<'a>),
Inactive(SMBiosInactive<'a>),
EndOfTable(SMBiosEndOfTable<'a>),
Undefined(SMBiosUnknown<'a>),
}
impl<'a> From<&'a UndefinedStruct> for DefinedStruct<'a> {
fn from(undefined_struct: &'a UndefinedStruct) -> Self {
match undefined_struct.header.struct_type() {
SMBiosInformation::STRUCT_TYPE => {
DefinedStruct::Information(SMBiosInformation::new(undefined_struct))
}
SMBiosSystemInformation::STRUCT_TYPE => {
DefinedStruct::SystemInformation(SMBiosSystemInformation::new(undefined_struct))
}
SMBiosBaseboardInformation::STRUCT_TYPE => DefinedStruct::BaseBoardInformation(
SMBiosBaseboardInformation::new(undefined_struct),
),
SMBiosSystemChassisInformation::STRUCT_TYPE => DefinedStruct::SystemChassisInformation(
SMBiosSystemChassisInformation::new(undefined_struct),
),
SMBiosProcessorInformation::STRUCT_TYPE => DefinedStruct::ProcessorInformation(
SMBiosProcessorInformation::new(undefined_struct),
),
SMBiosMemoryControllerInformation::STRUCT_TYPE => {
DefinedStruct::MemoryControllerInformation(SMBiosMemoryControllerInformation::new(
undefined_struct,
))
}
SMBiosMemoryModuleInformation::STRUCT_TYPE => DefinedStruct::MemoryModuleInformation(
SMBiosMemoryModuleInformation::new(undefined_struct),
),
SMBiosCacheInformation::STRUCT_TYPE => {
DefinedStruct::CacheInformation(SMBiosCacheInformation::new(undefined_struct))
}
SMBiosPortConnectorInformation::STRUCT_TYPE => DefinedStruct::PortConnectorInformation(
SMBiosPortConnectorInformation::new(undefined_struct),
),
SMBiosSystemSlot::STRUCT_TYPE => {
DefinedStruct::SystemSlot(SMBiosSystemSlot::new(undefined_struct))
}
SMBiosOnBoardDeviceInformation::STRUCT_TYPE => DefinedStruct::OnBoardDeviceInformation(
SMBiosOnBoardDeviceInformation::new(undefined_struct),
),
SMBiosOemStrings::STRUCT_TYPE => {
DefinedStruct::OemStrings(SMBiosOemStrings::new(undefined_struct))
}
SMBiosSystemConfigurationOptions::STRUCT_TYPE => {
DefinedStruct::SystemConfigurationOptions(SMBiosSystemConfigurationOptions::new(
undefined_struct,
))
}
SMBiosBiosLanguageInformation::STRUCT_TYPE => DefinedStruct::LanguageInformation(
SMBiosBiosLanguageInformation::new(undefined_struct),
),
SMBiosGroupAssociations::STRUCT_TYPE => {
DefinedStruct::GroupAssociations(SMBiosGroupAssociations::new(undefined_struct))
}
SMBiosSystemEventLog::STRUCT_TYPE => {
DefinedStruct::EventLog(SMBiosSystemEventLog::new(undefined_struct))
}
SMBiosPhysicalMemoryArray::STRUCT_TYPE => {
DefinedStruct::PhysicalMemoryArray(SMBiosPhysicalMemoryArray::new(undefined_struct))
}
SMBiosMemoryDevice::STRUCT_TYPE => {
DefinedStruct::MemoryDevice(SMBiosMemoryDevice::new(undefined_struct))
}
SMBiosMemoryErrorInformation32::STRUCT_TYPE => {
DefinedStruct::MemoryErrorInformation32Bit(SMBiosMemoryErrorInformation32::new(
undefined_struct,
))
}
SMBiosMemoryArrayMappedAddress::STRUCT_TYPE => DefinedStruct::MemoryArrayMappedAddress(
SMBiosMemoryArrayMappedAddress::new(undefined_struct),
),
SMBiosMemoryDeviceMappedAddress::STRUCT_TYPE => {
DefinedStruct::MemoryDeviceMappedAddress(SMBiosMemoryDeviceMappedAddress::new(
undefined_struct,
))
}
SMBiosBuiltInPointingDevice::STRUCT_TYPE => DefinedStruct::BuiltInPointingDevice(
SMBiosBuiltInPointingDevice::new(undefined_struct),
),
SMBiosPortableBattery::STRUCT_TYPE => {
DefinedStruct::PortableBattery(SMBiosPortableBattery::new(undefined_struct))
}
SMBiosSystemReset::STRUCT_TYPE => {
DefinedStruct::SystemReset(SMBiosSystemReset::new(undefined_struct))
}
SMBiosHardwareSecurity::STRUCT_TYPE => {
DefinedStruct::HardwareSecurity(SMBiosHardwareSecurity::new(undefined_struct))
}
SMBiosSystemPowerControls::STRUCT_TYPE => {
DefinedStruct::SystemPowerControls(SMBiosSystemPowerControls::new(undefined_struct))
}
SMBiosVoltageProbe::STRUCT_TYPE => {
DefinedStruct::VoltageProbe(SMBiosVoltageProbe::new(undefined_struct))
}
SMBiosCoolingDevice::STRUCT_TYPE => {
DefinedStruct::CoolingDevice(SMBiosCoolingDevice::new(undefined_struct))
}
SMBiosTemperatureProbe::STRUCT_TYPE => {
DefinedStruct::TemperatureProbe(SMBiosTemperatureProbe::new(undefined_struct))
}
SMBiosElectricalCurrentProbe::STRUCT_TYPE => DefinedStruct::ElectricalCurrentProbe(
SMBiosElectricalCurrentProbe::new(undefined_struct),
),
SMBiosOutOfBandRemoteAccess::STRUCT_TYPE => DefinedStruct::OutOfBandRemoteAccess(
SMBiosOutOfBandRemoteAccess::new(undefined_struct),
),
SMBiosBisEntryPoint::STRUCT_TYPE => {
DefinedStruct::BisEntryPoint(SMBiosBisEntryPoint::new(undefined_struct))
}
SMBiosSystemBootInformation::STRUCT_TYPE => DefinedStruct::SystemBootInformation(
SMBiosSystemBootInformation::new(undefined_struct),
),
SMBiosMemoryErrorInformation64::STRUCT_TYPE => {
DefinedStruct::MemoryErrorInformation64Bit(SMBiosMemoryErrorInformation64::new(
undefined_struct,
))
}
SMBiosManagementDevice::STRUCT_TYPE => {
DefinedStruct::ManagementDevice(SMBiosManagementDevice::new(undefined_struct))
}
SMBiosManagementDeviceComponent::STRUCT_TYPE => {
DefinedStruct::ManagementDeviceComponent(SMBiosManagementDeviceComponent::new(
undefined_struct,
))
}
SMBiosManagementDeviceThresholdData::STRUCT_TYPE => {
DefinedStruct::ManagementDeviceThresholdData(
SMBiosManagementDeviceThresholdData::new(undefined_struct),
)
}
SMBiosMemoryChannel::STRUCT_TYPE => {
DefinedStruct::MemoryChannel(SMBiosMemoryChannel::new(undefined_struct))
}
SMBiosIpmiDeviceInformation::STRUCT_TYPE => DefinedStruct::IpmiDeviceInformation(
SMBiosIpmiDeviceInformation::new(undefined_struct),
),
SMBiosSystemPowerSupply::STRUCT_TYPE => {
DefinedStruct::SystemPowerSupply(SMBiosSystemPowerSupply::new(undefined_struct))
}
SMBiosAdditionalInformation::STRUCT_TYPE => DefinedStruct::AdditionalInformation(
SMBiosAdditionalInformation::new(undefined_struct),
),
SMBiosOnboardDevicesExtendedInformation::STRUCT_TYPE => {
DefinedStruct::OnboardDevicesExtendedInformation(
SMBiosOnboardDevicesExtendedInformation::new(undefined_struct),
)
}
SMBiosManagementControllerHostInterface::STRUCT_TYPE => {
DefinedStruct::ManagementControllerHostInterface(
SMBiosManagementControllerHostInterface::new(undefined_struct),
)
}
SMBiosTpmDevice::STRUCT_TYPE => {
DefinedStruct::TpmDevice(SMBiosTpmDevice::new(undefined_struct))
}
SMBiosProcessorAdditionalInformation::STRUCT_TYPE => {
DefinedStruct::ProcessorAdditionalInformation(
SMBiosProcessorAdditionalInformation::new(undefined_struct),
)
}
SMBiosFirmwareInventoryInformation::STRUCT_TYPE => {
DefinedStruct::FirmwareInventoryInformation(
SMBiosFirmwareInventoryInformation::new(undefined_struct),
)
}
SMBiosStringProperty::STRUCT_TYPE => {
DefinedStruct::StringProperty(SMBiosStringProperty::new(undefined_struct))
}
SMBiosInactive::STRUCT_TYPE => {
DefinedStruct::Inactive(SMBiosInactive::new(undefined_struct))
}
SMBiosEndOfTable::STRUCT_TYPE => {
DefinedStruct::EndOfTable(SMBiosEndOfTable::new(undefined_struct))
}
_ => DefinedStruct::Undefined(SMBiosUnknown::new(undefined_struct)),
}
}
}
#[derive(Serialize, Debug)]
pub struct DefinedStructTable<'a>(Vec<DefinedStruct<'a>>);
impl<'a> DefinedStructTable<'a> {
fn new() -> DefinedStructTable<'a> {
DefinedStructTable(Vec::new())
}
fn add(&mut self, elem: DefinedStruct<'a>) {
self.0.push(elem);
}
}
impl<'a> IntoIterator for DefinedStructTable<'a> {
type Item = DefinedStruct<'a>;
type IntoIter = std::vec::IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl<'a> FromIterator<&'a UndefinedStruct> for DefinedStructTable<'a> {
fn from_iter<I: IntoIterator<Item = &'a UndefinedStruct>>(iter: I) -> Self {
let mut defined_struct_table = DefinedStructTable::new();
for undefined_struct in iter {
defined_struct_table.add(undefined_struct.into());
}
defined_struct_table
}
}