Struct packet::serialize::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 overflowusize
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
impl PacketConstraints
sourcepub fn new(
header_len: usize,
footer_len: usize,
min_body_len: usize,
max_body_len: usize
) -> PacketConstraints
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
.
sourcepub fn try_new(
header_len: usize,
footer_len: usize,
min_body_len: usize,
max_body_len: usize
) -> Option<PacketConstraints>
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
.
sourcepub fn header_len(&self) -> usize
pub fn header_len(&self) -> usize
The number of bytes in this packet’s header.
The number of bytes in this packet’s footer.
sourcepub fn min_body_len(&self) -> usize
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.
sourcepub fn max_body_len(&self) -> usize
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
.
Trait Implementations§
source§impl Clone for PacketConstraints
impl Clone for PacketConstraints
source§fn clone(&self) -> PacketConstraints
fn clone(&self) -> PacketConstraints
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for PacketConstraints
impl Debug for PacketConstraints
source§impl PartialEq<PacketConstraints> for PacketConstraints
impl PartialEq<PacketConstraints> for PacketConstraints
source§fn eq(&self, other: &PacketConstraints) -> bool
fn eq(&self, other: &PacketConstraints) -> bool
self
and other
values to be equal, and is used
by ==
.