From ae3d9c0892678562f2c1ba0c3222454e5760ce89 Mon Sep 17 00:00:00 2001 From: jake Date: Fri, 8 Nov 2019 22:50:42 -0800 Subject: [PATCH] impl PSOPacketData for f32 --- src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index b0388d2..1c957d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,6 +70,22 @@ impl PSOPacketData for u16 { } } +impl PSOPacketData for f32 { + fn from_bytes(cursor: &mut R) -> Result { + let mut bytes = [0u8; 4]; + let len = cursor.read(&mut bytes).map_err(|_| PacketParseError::ReadError)?; + if len == 4 { + Ok(f32::from_le_bytes(bytes)) + } + else { + Err(PacketParseError::NotEnoughBytes) + } + } + fn as_bytes(&self) -> Vec { + f32::to_le_bytes(*self).to_vec() + } +} + impl PSOPacketData for String { fn from_bytes(cursor: &mut R) -> Result { let mut s: Vec = Vec::new();