From 9a3e034fce0adc391feb55d35e1f2b7fc3c48bb5 Mon Sep 17 00:00:00 2001 From: clerie Date: Wed, 1 Jan 2025 15:52:02 +0100 Subject: [PATCH] Get ImprovPacket directly from bytes --- src/improv.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/improv.rs b/src/improv.rs index 9a7c448..8bb9fcd 100644 --- a/src/improv.rs +++ b/src/improv.rs @@ -186,7 +186,7 @@ pub struct RawPacket { } impl RawPacket { - pub fn try_from_bytes(bytes: &Vec) -> Result { + pub fn try_from_bytes(bytes: &[u8]) -> Result { if bytes.len() < 11 { bail!("Packet too small"); } @@ -256,6 +256,11 @@ impl ImprovPacket { _ => Err(anyhow!("Conversion into packet type not implemented")), } } + + pub fn try_from_bytes(bytes: &[u8]) -> Result { + 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 {