pub struct PacketDecoder {
pub strict_version: bool,
}Expand description
Deserializes packets from a byte buffer with strict bounds checking.
Fields§
§strict_version: boolWhen true reject packets whose version differs from PROTOCOL_VERSION.
Implementations§
Source§impl PacketDecoder
impl PacketDecoder
pub fn new() -> Self
Sourcepub fn decode(&self, buf: &[u8]) -> Result<(Packet, usize), ProtocolError>
pub fn decode(&self, buf: &[u8]) -> Result<(Packet, usize), ProtocolError>
Decode exactly one packet starting at the beginning of buf.
Returns (packet, bytes_consumed) on success.
Sourcepub fn decode_all(&self, buf: &[u8]) -> Result<Vec<Packet>, ProtocolError>
pub fn decode_all(&self, buf: &[u8]) -> Result<Vec<Packet>, ProtocolError>
Decode all packets packed end-to-end in buf.
Sourcepub fn decode_varint(
buf: &[u8],
offset: usize,
) -> Result<(u64, usize), ProtocolError>
pub fn decode_varint( buf: &[u8], offset: usize, ) -> Result<(u64, usize), ProtocolError>
Decode a variable-length integer (LEB128) from buf at offset.
Returns (value, new_offset).
Sourcepub fn unpack_bools(byte: u8, count: usize) -> [bool; 8]
pub fn unpack_bools(byte: u8, count: usize) -> [bool; 8]
Unpack up to 8 booleans from a flags byte.
Sourcepub fn decode_position_delta(delta: i16) -> f32
pub fn decode_position_delta(delta: i16) -> f32
Decode a 16-bit position delta back to an f32 offset.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PacketDecoder
impl RefUnwindSafe for PacketDecoder
impl Send for PacketDecoder
impl Sync for PacketDecoder
impl Unpin for PacketDecoder
impl UnsafeUnpin for PacketDecoder
impl UnwindSafe for PacketDecoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.