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 {