#[repr(C)]pub struct PacketHeader<T>where
T: 'static + Sendable,{
pub payload_size: u32,
/* private fields */
}
Expand description
The header of a packet. When a packet is sent over a socket, it is prepended with this header. This contains the type_id of the payload, the size of the payload, and a checksum of the payload. The checksum is used to verify that the payload was received correctly. The type_id is used to determine the type of the payload. The payload_size is used to determine the size of the payload.
Fields§
§payload_size: u32
Implementations§
Source§impl<T> PacketHeader<T>where
T: 'static + Sendable,
impl<T> PacketHeader<T>where
T: 'static + Sendable,
Sourcepub fn auto() -> PacketHeader<T>
pub fn auto() -> PacketHeader<T>
Creates a new PacketHeader with the type_id of T and the payload_size of T.
Sourcepub unsafe fn new(payload_size: u32) -> PacketHeader<T>
pub unsafe fn new(payload_size: u32) -> PacketHeader<T>
Creates a new PacketHeader with the specified length of the payload.
This can be useful for types where the size of the payload is not constant. (e.g. Vec
§Safety
The caller must ensure that the payload_size is correct, and that the sendable implementation accounts for the variable size of the payload.
Sourcepub fn verify_checksum(&self, payload: &[u8]) -> bool
pub fn verify_checksum(&self, payload: &[u8]) -> bool
Verifies the checksum of the payload.
Source§impl PacketHeader<UnknownType>
impl PacketHeader<UnknownType>
Sourcepub unsafe fn into_ty<U: Copy + Sendable>(self) -> PacketHeader<U>
pub unsafe fn into_ty<U: Copy + Sendable>(self) -> PacketHeader<U>
Converts the PacketHeader into a PacketHeader with a different type.
§Safety
The caller must ensure that the type_id and payload_size are correct. The caller must also ensure that the type T is the correct type.
Sourcepub unsafe fn from_bytes_unchecked(bytes: &[u8]) -> PacketHeader<UnknownType>
pub unsafe fn from_bytes_unchecked(bytes: &[u8]) -> PacketHeader<UnknownType>
Creates a new PacketHeader from a byte array.
§Safety
This function is unsafe because it creates a PacketHeader from a byte array without checking the checksum.
Use PacketHeader::from_bytes
if you want to check the checksum.
Sourcepub fn from_bytes(
bytes: &[u8],
data: &[u8],
) -> Option<PacketHeader<UnknownType>>
pub fn from_bytes( bytes: &[u8], data: &[u8], ) -> Option<PacketHeader<UnknownType>>
Creates a new PacketHeader from a byte array.
Trait Implementations§
Source§impl<T> Clone for PacketHeader<T>
impl<T> Clone for PacketHeader<T>
Source§fn clone(&self) -> PacketHeader<T>
fn clone(&self) -> PacketHeader<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more