fix: TryFrom will now translate into an Unknown if command group is not known

This commit is contained in:
Strix 2024-02-10 14:38:20 +01:00
parent a69d80f01c
commit 4be6659662
No known key found for this signature in database
GPG key ID: 5F35B3B8537287A7

View file

@ -1,4 +1,5 @@
use std::io; use std::io;
use std::os::linux::raw;
use crate::commands::property_control::PropertyControlCommand; use crate::commands::property_control::PropertyControlCommand;
use crate::commands::node_management::NodeManagementCommand; use crate::commands::node_management::NodeManagementCommand;
use crate::commands::raw_data_transmission::RawDataTransmission; use crate::commands::raw_data_transmission::RawDataTransmission;
@ -40,7 +41,7 @@ impl TryFrom<RawPacket> for PacketData {
0x0 => Ok(PacketData::NodeManagement(NodeManagementCommand::try_from(raw_packet)?)), 0x0 => Ok(PacketData::NodeManagement(NodeManagementCommand::try_from(raw_packet)?)),
0x1 => Ok(PacketData::PropertyControl(PropertyControlCommand::try_from(raw_packet)?)), 0x1 => Ok(PacketData::PropertyControl(PropertyControlCommand::try_from(raw_packet)?)),
0xF => Ok(PacketData::RawDataTransmission(RawDataTransmission::try_from(raw_packet)?)), 0xF => Ok(PacketData::RawDataTransmission(RawDataTransmission::try_from(raw_packet)?)),
_ => Err(io::Error::new(io::ErrorKind::InvalidInput, "command group is unsupported")) _ => Ok(PacketData::Unknown(raw_packet.data))
} }
} }
} }