pub struct Reassembler { /* private fields */ }Expand description
Incremental reassembler for one direction of a connection.
A session reads one frame at a time and owns a Reassembler; reassemble_binary is the same
validation for a sequence that is already in hand. Both allow only one fragmented message in
flight, as the protocol requires.
Implementations§
Source§impl Reassembler
impl Reassembler
Sourcepub fn new(max_message_len: usize) -> Self
pub fn new(max_message_len: usize) -> Self
Creates a reassembler that rejects a reassembled message longer than max_message_len.
A session usually passes MAX_REASSEMBLED_LEN, the bound a receiver may choose for
itself.
Sourcepub fn push(&mut self, frame: &[u8]) -> Result<Option<(u8, Vec<u8>)>>
pub fn push(&mut self, frame: &[u8]) -> Result<Option<(u8, Vec<u8>)>>
Feeds one Noise transport plaintext.
Returns Some((id, payload)) when the frame completes a message: immediately for a plain
frame, and on the fragment that carries the last flag for a sequence. Every other fragment
returns Ok(None).
§Errors
Returns an error, and drops any message in flight, for the malformed sequences the protocol
defines: an empty frame, a plain frame while a fragmented message is in flight, a fragment
without its flags byte, reserved flag bits, a continuation fragment without a first
fragment, a second first fragment while one is in flight, a first fragment without its
original message id, an original id of BINARY_MESSAGE_ID_FRAGMENT, and a message larger
than max_message_len.
The framing carries no byte count and no sequence number, so a fragment lost from the middle of a message cannot be detected here.