Struct blaze_pk::packet::Packet

source ·
pub struct Packet {
    pub header: PacketHeader,
    pub contents: Bytes,
}
Expand description

Structure for Blaze packets contains the contents of the packet and the header for identification.

Packets can be cloned with little memory usage increase because the content is stored as Bytes.

Fields§

§header: PacketHeader

The packet header

§contents: Bytes

The packet encoded byte contents

Implementations§

source§

impl Packet

source

pub fn raw(header: PacketHeader, contents: Vec<u8>) -> Self

Creates a packet from its raw components

header The packet header contents The encoded packet contents

source

pub const fn raw_empty(header: PacketHeader) -> Self

Creates a packet from its raw components where the contents are empty

header The packet header

source

pub fn response<C: Encodable>(packet: &Packet, contents: C) -> Self

Creates a packet responding to the provided packet. Clones the header of the request packet and changes the type to repsonse

packet The packet to respond to contents The contents to encode for the packet

source

pub fn respond<C: Encodable>(&self, contents: C) -> Self

Creates a packet responding to the current packet. Clones the header of the request packet and changes the type to repsonse

packet The packet to respond to contents The contents to encode for the packet

source

pub fn response_raw(packet: &Packet, contents: Vec<u8>) -> Self

Creates a response packet responding to the provided packet but with raw contents that have already been encoded.

packet The packet to respond to contents The raw encoded packet contents

source

pub const fn response_empty(packet: &Packet) -> Self

Creates a response packet responding to the provided packet but with empty contents.

packet The packet to respond to

source

pub const fn respond_empty(&self) -> Self

Creates a response packet responding to the provided packet but with empty contents.

packet The packet to respond to contents The contents to encode for the packet

source

pub fn error<C: Encodable>(packet: &Packet, error: u16, contents: C) -> Self

Creates a error respond packet responding to the provided packet with the provided error and contents

packet The packet to respond to error The response error value contents The response contents

source

pub fn respond_error<C: Encodable>(&self, error: u16, contents: C) -> Self

Creates a error respond packet responding to the provided packet with the provided error and contents

packet The packet to respond to error The response error value contents The response contents

source

pub fn error_raw(packet: &Packet, error: u16, contents: Vec<u8>) -> Self

Creates a error respond packet responding to the provided packet with the provided error and raw encoded contents

packet The packet to respond to error The response error value contents The raw encoded contents

source

pub const fn error_empty(packet: &Packet, error: u16) -> Packet

Creates a error respond packet responding to the provided packet with the provided error with empty contents

packet The packet to respond to error The response error value

source

pub const fn respond_error_empty(&self, error: u16) -> Packet

Creates a error respond packet responding to the provided packet with the provided error with empty contents

packet The packet to respond to error The response error value

source

pub fn notify<C: Encodable, T: PacketComponents>( component: T, contents: C ) -> Packet

Creates a notify packet for the provided component with the provided contents.

component The packet component to use for the header contents The contents of the packet to encode

source

pub fn notify_raw<T: PacketComponents>( component: T, contents: Vec<u8> ) -> Packet

Creates a notify packet for the provided component with the provided raw encoded contents.

component The packet component contents The encoded packet contents

source

pub fn notify_empty<T: PacketComponents>(component: T) -> Packet

Creates a notify packet for the provided component with empty contents

component The packet component

source

pub fn request<C: Encodable, T: PacketComponents>( id: u16, component: T, contents: C ) -> Packet

Creates a new request packet from the provided id, component, and contents

id The packet id component The packet component contents The packet contents

source

pub fn request_raw<T: PacketComponents>( id: u16, component: T, contents: Vec<u8> ) -> Packet

Creates a new request packet from the provided id, component with raw encoded contents

id The packet id component The packet component contents The raw encoded contents

source

pub fn request_empty<T: PacketComponents>(id: u16, component: T) -> Packet

Creates a new request packet from the provided id, component with empty contents

id The packet id component The packet component contents The packet contents

source

pub fn decode<C: Decodable>(&self) -> DecodeResult<C>

Attempts to decode the contents bytes of this packet into the provided Codec type value.

source

pub fn read(src: &mut BytesMut) -> Option<Self>

Attempts to read a packet from the provided bytes source

src The bytes to read from

source

pub fn write(&self, dst: &mut BytesMut)

Writes the contents and header of the packet onto the dst source of bytes

dst The destination buffer

Trait Implementations§

source§

impl Clone for Packet

source§

fn clone(&self) -> Packet

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Packet

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Encoder<&Packet> for PacketCodec

Encoder implementation for borrowed packets

§

type Error = Error

The type of encoding errors. Read more
source§

fn encode( &mut self, item: &Packet, dst: &mut BytesMut ) -> Result<(), Self::Error>

Encodes a frame into the buffer provided. Read more
source§

impl Encoder<Packet> for PacketCodec

Encoder implementation for owned packets

§

type Error = Error

The type of encoding errors. Read more
source§

fn encode( &mut self, item: Packet, dst: &mut BytesMut ) -> Result<(), Self::Error>

Encodes a frame into the buffer provided. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more