pub struct PacketEncoder {
pub compression: CompressionHint,
pub reliable: bool,
pub ordered: bool,
}Expand description
Serializes Packet values to a contiguous byte buffer.
The encoder does NOT own any state between calls; call encode for each
packet and write the returned Vec<u8> to your socket.
Fields§
§compression: CompressionHintCompression hint written into the header flags.
reliable: boolWhether the reliable flag should be set on encoded packets.
ordered: boolWhether the ordered flag should be set on encoded packets.
Implementations§
Source§impl PacketEncoder
impl PacketEncoder
pub fn new() -> Self
Sourcepub fn encode(&self, packet: &Packet) -> Result<Vec<u8>, ProtocolError>
pub fn encode(&self, packet: &Packet) -> Result<Vec<u8>, ProtocolError>
Encode a Packet to bytes. Returns Err if payload exceeds limit.
Sourcepub fn encode_batch(&self, packets: &[Packet]) -> Result<Vec<u8>, ProtocolError>
pub fn encode_batch(&self, packets: &[Packet]) -> Result<Vec<u8>, ProtocolError>
Encode a sequence of packets back-to-back (UDP batch / TCP stream).
Sourcepub fn encode_varint(value: u64, out: &mut Vec<u8>)
pub fn encode_varint(value: u64, out: &mut Vec<u8>)
Variable-length encode a u64 (LEB128).
Sourcepub fn encode_position_delta(from: f32, to: f32) -> i16
pub fn encode_position_delta(from: f32, to: f32) -> i16
Delta-encode an f32 position value as a 16-bit fixed-point delta. Returns the quantised delta in centimetres (±327.67 m range at 1 cm precision).
Sourcepub fn pack_bools(flags: &[bool]) -> u8
pub fn pack_bools(flags: &[bool]) -> u8
Bit-pack up to 8 booleans into a single byte.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PacketEncoder
impl RefUnwindSafe for PacketEncoder
impl Send for PacketEncoder
impl Sync for PacketEncoder
impl Unpin for PacketEncoder
impl UnsafeUnpin for PacketEncoder
impl UnwindSafe for PacketEncoder
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.