Files
Pumpkin/pumpkin-protocol/src/codec/u24.rs
unschlagbar 5dac015dd9 Fixed gamepacket parsing (#987)
* grg

* ef

* gg

* refwd

---------

Co-authored-by: unschlagbar <adrian@kuhlmann@gmx.de>
2025-07-01 21:33:45 +02:00

24 lines
639 B
Rust

use std::io::{Read, Write};
use crate::ser::{NetworkReadExt, NetworkWriteExt, ReadingError, WritingError};
#[derive(Clone, Copy)]
pub struct U24(pub u32);
impl U24 {
pub fn decode(read: &mut impl Read) -> Result<Self, ReadingError> {
let a = read.get_u8()?;
let b = read.get_u8()?;
let c = read.get_u8()?;
Ok(U24(u32::from_le_bytes([a, b, c, 0])))
}
pub fn encode(&self, write: &mut impl Write) -> Result<(), WritingError> {
let data = self.0.to_le_bytes();
write.write_u8(data[0])?;
write.write_u8(data[1])?;
write.write_u8(data[2])?;
Ok(())
}
}