packet::serialize

Struct PacketConstraints

Source
pub struct PacketConstraints { /* private fields */ }
Expand description

The constraints required by a PacketBuilder.

PacketConstraints represents the constraints that must be satisfied in order to serialize a PacketBuilder.

A PacketConstraints, c, guarantees two properties:

  • c.max_body_len() >= c.min_body_len()
  • c.header_len() + c.min_body_len() + c.footer_len() does not overflow usize

It is not possible (using safe code) to obtain a PacketConstraints which violates these properties, so code may rely for its correctness on the assumption that these properties hold.

Implementations§

Source§

impl PacketConstraints

Source

pub const UNCONSTRAINED: Self = _

A no-op PacketConstraints which does not add any constraints - there is no header, footer, minimum body length requirement, or maximum body length requirement.

Source

pub fn new( header_len: usize, footer_len: usize, min_body_len: usize, max_body_len: usize, ) -> PacketConstraints

Constructs a new PacketConstraints.

§Panics

new panics if the arguments violate the validity properties of PacketConstraints - if max_body_len < min_body_len, or if header_len + min_body_len + footer_len overflows usize.

Source

pub fn try_new( header_len: usize, footer_len: usize, min_body_len: usize, max_body_len: usize, ) -> Option<PacketConstraints>

Tries to construct a new PacketConstraints.

new returns None if the provided values violate the validity properties of PacketConstraints - if max_body_len < min_body_len, or if header_len + min_body_len + footer_len overflows usize.

Source

pub fn with_max_body_len(max_body_len: usize) -> PacketConstraints

Constructs a new PacketConstraints with a given max_body_len.

The header_len, footer_len, and min_body_len are all 0.

Source

pub fn header_len(&self) -> usize

The number of bytes in this packet’s header.

Source

pub fn footer_len(&self) -> usize

The number of bytes in this packet’s footer.

Source

pub fn min_body_len(&self) -> usize

The minimum body length (in bytes) required by this packet in order to avoid adding padding.

min_body_len returns the minimum number of body bytes required in order to avoid adding padding. Note that, if padding bytes are required, they may not necessarily belong immediately following the body, depending on which packet layer imposes the minimum. In particular, in a nested packet, padding goes after the body of the layer which imposes the minimum. This means that, if the layer that imposes the minimum is not the innermost one, then padding must be added not after the innermost body, but instead in between footers. [NestedPacketBuilder::serialize_into] is responsible for inserting padding when serializing nested packets.

If there is no minimum body length, this returns 0.

Source

pub fn max_body_len(&self) -> usize

The maximum length (in bytes) of a body allowed by this packet.

If there is no maximum body length, this returns core::usize::MAX.

Source

pub fn try_encapsulate(&self, outer: &Self) -> Option<PacketConstraints>

Attempts to encapsulate self in outer.

Upon success, try_encapsulate returns a PacketConstraints which represents the encapsulation of self in outer. Its header length, footer length, minimum body length, and maximum body length are set accordingly.

This is probably not the method you want to use; consider Serializer::encapsulate instead.

Trait Implementations§

Source§

impl Clone for PacketConstraints

Source§

fn clone(&self) -> PacketConstraints

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 PacketConstraints

Source§

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

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

impl PartialEq for PacketConstraints

Source§

fn eq(&self, other: &PacketConstraints) -> 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 Copy for PacketConstraints

Source§

impl Eq for PacketConstraints

Source§

impl StructuralPartialEq for PacketConstraints

Auto Trait Implementations§

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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.