Skip to main content

BlockAssembler

Struct BlockAssembler 

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

Reassembles Block1 fragments into a complete request payload.

RFC 7959 §2.5: The server collects Block1 fragments from the client, validating sequential block numbers and consistent SZX values. Once the final block (M=0) arrives, the full payload is returned.

Implementations§

Source§

impl BlockAssembler

Source

pub fn new(max_payload: usize) -> Self

Creates a new assembler with default block size and the given payload limit.

§Arguments
  • max_payload - Maximum total payload size after reassembly. Prevents resource exhaustion from unbounded block sequences.
Source

pub fn process_block( &mut self, block: &BlockOption, data: &[u8], ) -> CoapResult<bool>

Processes an incoming Block1 fragment.

Validates that blocks arrive in order and that the reassembled payload does not exceed the configured maximum size.

Returns true when the final block has been received and the full payload is available via payload().

Source

pub fn payload(&self) -> Option<&[u8]>

Returns the reassembled payload, or None if transfer is incomplete.

Source

pub fn into_payload(self) -> CoapResult<Vec<u8>>

Consumes the assembler and returns the reassembled payload.

Returns Err if the transfer is not yet complete.

Source

pub fn szx(&self) -> u8

Returns the negotiated block size exponent.

Source

pub fn is_complete(&self) -> bool

Returns whether the final block has been received.

Source

pub fn reset(&mut self)

Resets the assembler for reuse.

Trait Implementations§

Source§

impl Debug for BlockAssembler

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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.