pub struct Packet {
length: usize,
id: VarInt,
data: BytesMut,
payload: BytesMut,
name: Option<String>,
}
Expand description
An abstraction for a Minecraft packet.
Structure of a normal uncompressed Packet:
Length (VarInt): Length of Packet ID + Data P): An ID each packet has Data (Byte Aacket ID (VarIntrray): Actual data bytes
Fields§
§length: usize
Length of id
+ data
id: VarInt
An ID that each Packet has, varint-decoded.
data: BytesMut
The raw bytes making the packet. (so it contains ALL the packet, Length, Packet ID and the data bytes)
payload: BytesMut
The raw bytes making the PAYLOAD of the packet. (so this slice does not contain the length and acket ID)
name: Option<String>
For debugging purposes, the type of the packet, like ‘Handshake (handshaking)’.
Implementations§
Source§impl Packet
impl Packet
Sourcepub fn new<T: AsRef<[u8]>>(data: T) -> Result<Self, PacketError>
pub fn new<T: AsRef<[u8]>>(data: T) -> Result<Self, PacketError>
Initializes a new Packet
by parsing the data
buffer.
Sourcepub fn get_full_packet(&self) -> &[u8] ⓘ
pub fn get_full_packet(&self) -> &[u8] ⓘ
This is the WHOLE packet.
Sourcepub fn get_payload(&self) -> &[u8] ⓘ
pub fn get_payload(&self) -> &[u8] ⓘ
This is the PAYLOAD. So the bytes except the Packet Length and the Packet ID.
Sourcepub fn get_length(&self) -> usize
pub fn get_length(&self) -> usize
Returns the Packet
length
attribute. From protocol.
Sourcepub fn len_payload(&self) -> usize
pub fn len_payload(&self) -> usize
Returns the number of bytes in the payload.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of bytes in the packet. To be clear, this is the length of the received TCP packet.
Sourcefn parse_packet(data: &[u8]) -> Result<(usize, VarInt, &[u8]), PacketError>
fn parse_packet(data: &[u8]) -> Result<(usize, VarInt, &[u8]), PacketError>
Tries to parse raw bytes and return in order: (Packet Length, Packet ID, Packet payload bytes)
Trait Implementations§
Source§impl Default for Packet
Allows making a Packet
object with defaults.
Usage:
impl Default for Packet
Allows making a Packet
object with defaults.
Usage:
let packet = Packet::default();
Source§impl TryFrom<Packet> for FinishConfiguration
impl TryFrom<Packet> for FinishConfiguration
Source§impl TryFrom<Packet> for LoginAcknowledged
impl TryFrom<Packet> for LoginAcknowledged
Source§impl TryFrom<Packet> for LoginStart
impl TryFrom<Packet> for LoginStart
Source§impl TryFrom<Packet> for ServerboundKnownPacks
impl TryFrom<Packet> for ServerboundKnownPacks
impl Eq for Packet
impl StructuralPartialEq for Packet
Auto Trait Implementations§
impl Freeze for Packet
impl RefUnwindSafe for Packet
impl Send for Packet
impl Sync for Packet
impl Unpin for Packet
impl UnwindSafe for Packet
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string
, but without panic on OOM.