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
impl Packet
sourcepub fn raw(header: PacketHeader, contents: Vec<u8>) -> Self
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
sourcepub const fn raw_empty(header: PacketHeader) -> Self
pub const fn raw_empty(header: PacketHeader) -> Self
Creates a packet from its raw components where the contents are empty
header
The packet header
sourcepub fn response<C: Encodable>(packet: &Packet, contents: C) -> Self
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
sourcepub fn respond<C: Encodable>(&self, contents: C) -> Self
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
sourcepub fn response_raw(packet: &Packet, contents: Vec<u8>) -> Self
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
sourcepub const fn response_empty(packet: &Packet) -> Self
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
sourcepub const fn respond_empty(&self) -> Self
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
sourcepub fn error<C: Encodable>(packet: &Packet, error: u16, contents: C) -> Self
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
sourcepub fn respond_error<C: Encodable>(&self, error: u16, contents: C) -> Self
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
sourcepub fn error_raw(packet: &Packet, error: u16, contents: Vec<u8>) -> Self
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
sourcepub const fn error_empty(packet: &Packet, error: u16) -> Packet
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
sourcepub const fn respond_error_empty(&self, error: u16) -> Packet
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
sourcepub fn notify<C: Encodable, T: PacketComponents>(
component: T,
contents: C
) -> Packet
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
sourcepub fn notify_raw<T: PacketComponents>(
component: T,
contents: Vec<u8>
) -> Packet
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
sourcepub fn notify_empty<T: PacketComponents>(component: T) -> Packet
pub fn notify_empty<T: PacketComponents>(component: T) -> Packet
Creates a notify packet for the provided component with empty contents
component
The packet component
sourcepub fn request<C: Encodable, T: PacketComponents>(
id: u16,
component: T,
contents: C
) -> Packet
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
sourcepub fn request_raw<T: PacketComponents>(
id: u16,
component: T,
contents: Vec<u8>
) -> Packet
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
sourcepub fn request_empty<T: PacketComponents>(id: u16, component: T) -> Packet
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
sourcepub fn decode<C: Decodable>(&self) -> DecodeResult<C>
pub fn decode<C: Decodable>(&self) -> DecodeResult<C>
Attempts to decode the contents bytes of this packet into the provided Codec type value.
Trait Implementations§
source§impl Encoder<&Packet> for PacketCodec
impl Encoder<&Packet> for PacketCodec
Encoder implementation for borrowed packets