Browse Source

reorder these

pull/3/head
jake 5 years ago
parent
commit
b8b418a7a0
  1. 24
      src/lib.rs

24
src/lib.rs

@ -38,35 +38,35 @@ impl PSOPacketData for u8 {
}
}
impl PSOPacketData for u32 {
fn from_bytes<R: Read>(cursor: &mut R) -> Result<u32, PacketParseError> {
let mut bytes = [0u8; 4];
impl PSOPacketData for u16 {
fn from_bytes<R: Read>(cursor: &mut R) -> Result<u16, PacketParseError> {
let mut bytes = [0u8; 2];
let len = cursor.read(&mut bytes).map_err(|_| PacketParseError::ReadError)?;
if len == 4 {
Ok(u32::from_le_bytes(bytes))
if len == 2 {
Ok(u16::from_le_bytes(bytes))
}
else {
Err(PacketParseError::NotEnoughBytes)
}
}
fn as_bytes(&self) -> Vec<u8> {
u32::to_le_bytes(*self).to_vec()
u16::to_le_bytes(*self).to_vec()
}
}
impl PSOPacketData for u16 {
fn from_bytes<R: Read>(cursor: &mut R) -> Result<u16, PacketParseError> {
let mut bytes = [0u8; 2];
impl PSOPacketData for u32 {
fn from_bytes<R: Read>(cursor: &mut R) -> Result<u32, PacketParseError> {
let mut bytes = [0u8; 4];
let len = cursor.read(&mut bytes).map_err(|_| PacketParseError::ReadError)?;
if len == 2 {
Ok(u16::from_le_bytes(bytes))
if len == 4 {
Ok(u32::from_le_bytes(bytes))
}
else {
Err(PacketParseError::NotEnoughBytes)
}
}
fn as_bytes(&self) -> Vec<u8> {
u16::to_le_bytes(*self).to_vec()
u32::to_le_bytes(*self).to_vec()
}
}

Loading…
Cancel
Save