Struct PacketHeader

Source
#[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,

Source

pub fn auto() -> PacketHeader<T>

Creates a new PacketHeader with the type_id of T and the payload_size of T.

Source

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, String, etc.) This can also be useful for reference types.

§Safety

The caller must ensure that the payload_size is correct, and that the sendable implementation accounts for the variable size of the payload.

Source

pub fn verify_checksum(&self, payload: &[u8]) -> bool

Verifies the checksum of the payload.

Source

pub fn to_bytes(&self) -> [u8; 20]

Converts the PacketHeader into a byte array.

Source§

impl PacketHeader<UnknownType>

Source

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.

Source

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.

Source

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>
where T: 'static + Sendable + Clone,

Source§

fn clone(&self) -> PacketHeader<T>

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<T: Sendable> Debug for PacketHeader<T>

Source§

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

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

impl<T> Hash for PacketHeader<T>
where T: 'static + Sendable + Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> PartialEq for PacketHeader<T>
where T: 'static + Sendable + PartialEq,

Source§

fn eq(&self, other: &PacketHeader<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> Copy for PacketHeader<T>
where T: 'static + Sendable + Copy,

Source§

impl<T> Eq for PacketHeader<T>
where T: 'static + Sendable + Eq,

Source§

impl<T> StructuralPartialEq for PacketHeader<T>
where T: 'static + Sendable,

Auto Trait Implementations§

§

impl<T> Freeze for PacketHeader<T>

§

impl<T> RefUnwindSafe for PacketHeader<T>
where T: RefUnwindSafe,

§

impl<T> Send for PacketHeader<T>
where T: Send,

§

impl<T> Sync for PacketHeader<T>
where T: Sync,

§

impl<T> Unpin for PacketHeader<T>
where T: Unpin,

§

impl<T> UnwindSafe for PacketHeader<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where 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 T
where T: Clone,

Source§

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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.