pub struct PacketFragmentationAssembler { /* private fields */ }Expand description
Packet fragmentation and reassembly engine.
§Thread safety
This struct is Send but not Sync; wrap in Arc<Mutex<...>> for shared use.
Implementations§
Source§impl PacketFragmentationAssembler
impl PacketFragmentationAssembler
Sourcepub fn new(config: PfaAssemblerConfig) -> Self
pub fn new(config: PfaAssemblerConfig) -> Self
Create a new assembler with the given configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Convenience constructor using default configuration.
Sourcepub fn generate_msg_id(&mut self) -> PfaMessageId
pub fn generate_msg_id(&mut self) -> PfaMessageId
Generate a new message ID that is not currently in use.
Sourcepub fn fragment(
&mut self,
msg_id: PfaMessageId,
data: &[u8],
) -> Result<Vec<PfaFragment>, String>
pub fn fragment( &mut self, msg_id: PfaMessageId, data: &[u8], ) -> Result<Vec<PfaFragment>, String>
Split data into MTU-sized fragments tagged with msg_id.
Returns an empty Vec if data is empty.
§Errors
Returns Err if the payload would require more than
config.max_fragments fragments.
Sourcepub fn receive_fragment(
&mut self,
fragment: PfaFragment,
now_ts: u64,
) -> PfaReceiveResult
pub fn receive_fragment( &mut self, fragment: PfaFragment, now_ts: u64, ) -> PfaReceiveResult
Process a received fragment.
now_ts is the current Unix-epoch timestamp in seconds and is used for
the fragment log and buffer creation timestamps.
Sourcepub fn reassemble(&mut self, msg_id: PfaMessageId) -> Option<Vec<u8>>
pub fn reassemble(&mut self, msg_id: PfaMessageId) -> Option<Vec<u8>>
Attempt to reassemble message msg_id if all fragments are present.
Returns None if the buffer does not exist or is incomplete.
Sourcepub fn expire_stale(&mut self, now_ts: u64)
pub fn expire_stale(&mut self, now_ts: u64)
Remove all buffers whose created_at is older than the configured timeout.
Sourcepub fn pending_messages(&self) -> Vec<(PfaMessageId, u32, u32)>
pub fn pending_messages(&self) -> Vec<(PfaMessageId, u32, u32)>
List pending messages: (msg_id, received_count, total_fragments).
Sourcepub fn verify_checksum(&self, fragment: &PfaFragment) -> bool
pub fn verify_checksum(&self, fragment: &PfaFragment) -> bool
Verify the checksum of a fragment (instance method forwarding to static).
Sourcepub fn assembler_stats(&self) -> PfaAssemblerStats
pub fn assembler_stats(&self) -> PfaAssemblerStats
Return a snapshot of assembler-level statistics.
Sourcepub fn config(&self) -> &PfaAssemblerConfig
pub fn config(&self) -> &PfaAssemblerConfig
Reference to the configuration.
Sourcepub fn pending_count(&self) -> usize
pub fn pending_count(&self) -> usize
Number of messages currently awaiting full reassembly.
Sourcepub fn fragment_log(&self) -> &VecDeque<PfaFragmentRecord>
pub fn fragment_log(&self) -> &VecDeque<PfaFragmentRecord>
A slice of the most recent fragment log entries.
Sourcepub fn has_pending(&self) -> bool
pub fn has_pending(&self) -> bool
True if the engine holds any in-flight reassembly buffers.
Sourcepub fn get_buffer(&self, msg_id: PfaMessageId) -> Option<&PfaReassemblyBuffer>
pub fn get_buffer(&self, msg_id: PfaMessageId) -> Option<&PfaReassemblyBuffer>
Return a reference to the reassembly buffer for msg_id, if any.
Sourcepub fn drain_log(&mut self) -> Vec<PfaFragmentRecord>
pub fn drain_log(&mut self) -> Vec<PfaFragmentRecord>
Drain and return all fragment log entries.
Auto Trait Implementations§
impl Freeze for PacketFragmentationAssembler
impl RefUnwindSafe for PacketFragmentationAssembler
impl Send for PacketFragmentationAssembler
impl Sync for PacketFragmentationAssembler
impl Unpin for PacketFragmentationAssembler
impl UnsafeUnpin for PacketFragmentationAssembler
impl UnwindSafe for PacketFragmentationAssembler
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more