pub struct Fragmenter<'a> { /* private fields */ }Expand description
Cuts a data block into the fragments of a session, and builds the coded ones.
The block is left where it is: nothing is copied until a fragment is asked for.
Implementations§
Source§impl<'a> Fragmenter<'a>
impl<'a> Fragmenter<'a>
Sourcepub fn new(
block: &'a [u8],
frag_size: u8,
) -> Result<Fragmenter<'a>, LorawanError>
pub fn new( block: &'a [u8], frag_size: u8, ) -> Result<Fragmenter<'a>, LorawanError>
Prepares a block for a session.
§Arguments
block- the data to send.frag_size- how many bytes each fragment carries.
§Returns
The fragmenter, which says how many fragments the block takes and how much padding the last one needs.
§Errors
LorawanError::MalformedFrame for a fragment size of zero or a block that needs
more than MAX_FRAGMENTS fragments.
Sourcepub const fn nb_frag(&self) -> u16
pub const fn nb_frag(&self) -> u16
How many uncoded fragments the block was cut into.
§Returns
The count, which the session setup carries as NbFrag.
Sourcepub const fn padding(&self) -> u8
pub const fn padding(&self) -> u8
How many bytes of padding the last fragment carries.
§Returns
The count, which the session setup carries and the receiver strips.
Sourcepub fn fragment(&self, n: u16, out: &mut [u8]) -> Result<usize, LorawanError>
pub fn fragment(&self, n: u16, out: &mut [u8]) -> Result<usize, LorawanError>
Builds one fragment of the session.
§Arguments
n- which fragment, counting from one. Up tonb_fragit is a piece of the block; past that it is a coded fragment, the exclusive-or of a pseudo-random half of the pieces.out- where to write it, at leastfrag_sizebytes.
§Returns
How many bytes were written, which is always frag_size.
§Errors
LorawanError::MalformedFrame for a fragment number of zero, and
LorawanError::PayloadTooLong when the buffer is too small.
Trait Implementations§
Source§impl<'a> Clone for Fragmenter<'a>
impl<'a> Clone for Fragmenter<'a>
Source§fn clone(&self) -> Fragmenter<'a>
fn clone(&self) -> Fragmenter<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more