Skip to main content

bornera_core/framing/
port.rs

1//! Narrow protocol-adapter port for incremental frame decoding.
2
3use calandria::RetainedBytes;
4
5/// Protocol-owned incremental decoding of complete inbound frames.
6///
7/// Implementations retain one bounded stream accumulation rather than an
8/// unreported queue of decoded frames. Callers drain `next_frame` after each
9/// accepted input before admitting more bytes.
10pub trait FrameDecoder {
11    /// Complete opaque frame emitted to inbound classification.
12    type Frame;
13    /// Protocol-specific terminal decoder error.
14    type Error;
15
16    /// Admits bytes into protocol-specific accumulation.
17    fn feed(&mut self, bytes: &[u8]) -> Result<(), Self::Error>;
18
19    /// Extracts at most one complete frame while retaining later bytes.
20    fn next_frame(&mut self) -> Result<Option<Self::Frame>, Self::Error>;
21
22    /// Reports all variable memory currently retained by the decoder.
23    fn retained_bytes(&self) -> RetainedBytes;
24}