Get ImprovPacket directly from bytes

This commit is contained in:
clerie 2025-01-01 15:52:02 +01:00
parent 0288b49319
commit 9a3e034fce

View File

@ -186,7 +186,7 @@ pub struct RawPacket {
} }
impl RawPacket { impl RawPacket {
pub fn try_from_bytes(bytes: &Vec<u8>) -> Result<Self> { pub fn try_from_bytes(bytes: &[u8]) -> Result<Self> {
if bytes.len() < 11 { if bytes.len() < 11 {
bail!("Packet too small"); bail!("Packet too small");
} }
@ -256,6 +256,11 @@ impl ImprovPacket {
_ => Err(anyhow!("Conversion into packet type not implemented")), _ => Err(anyhow!("Conversion into packet type not implemented")),
} }
} }
pub fn try_from_bytes(bytes: &[u8]) -> Result<Self> {
let raw_packet = RawPacket::try_from_bytes(bytes).context("Failed to deserialize bytes into raw packet")?;
ImprovPacket::try_from_raw_packet(&raw_packet).context("Failed to get improv packet from raw packet")
}
} }
pub struct CurrentStatePacket { pub struct CurrentStatePacket {