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 const UNCONSTRAINED: Self = _
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.
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 with_max_body_len(max_body_len: usize) -> PacketConstraints
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
.
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
.
Sourcepub fn try_encapsulate(&self, outer: &Self) -> Option<PacketConstraints>
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
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 for PacketConstraints
impl PartialEq for PacketConstraints
impl Copy for PacketConstraints
impl Eq for PacketConstraints
impl StructuralPartialEq for PacketConstraints
Auto Trait Implementations§
impl Freeze for PacketConstraints
impl RefUnwindSafe for PacketConstraints
impl Send for PacketConstraints
impl Sync for PacketConstraints
impl Unpin for PacketConstraints
impl UnwindSafe for PacketConstraints
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)