impl PSOPacketData for f32
This commit is contained in:
parent
efb952d4a8
commit
ae3d9c0892
16
src/lib.rs
16
src/lib.rs
@ -70,6 +70,22 @@ impl PSOPacketData for u16 {
|
||||
}
|
||||
}
|
||||
|
||||
impl PSOPacketData for f32 {
|
||||
fn from_bytes<R: Read>(cursor: &mut R) -> Result<f32, PacketParseError> {
|
||||
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<u8> {
|
||||
f32::to_le_bytes(*self).to_vec()
|
||||
}
|
||||
}
|
||||
|
||||
impl PSOPacketData for String {
|
||||
fn from_bytes<R: Read>(cursor: &mut R) -> Result<String, PacketParseError> {
|
||||
let mut s: Vec<u8> = Vec::new();
|
||||
|
Loading…
x
Reference in New Issue
Block a user