pub struct FrameReader<R> { /* private fields */ }Expand description
NDJSON frame reader over any AsyncRead. Reads byte-at-a-time from an INTERNAL
BufReader (misuse-proof: callers cannot forget the buffering and pay a
poll-per-byte penalty).
next() is cancellation-safe: all parse state lives in self; dropping the
future loses no bytes.
Implementations§
Source§impl<R: AsyncRead + Unpin> FrameReader<R>
impl<R: AsyncRead + Unpin> FrameReader<R>
pub fn new(reader: R, max_frame: usize) -> Self
Sourcepub fn into_inner(self) -> BufReader<R>
pub fn into_inner(self) -> BufReader<R>
Unwrap to the BUFFERED reader half. Returns the internal BufReader — NOT the
raw stream — so bytes already read ahead (e.g. a frame the peer pipelined behind
the one just parsed) travel WITH the reader instead of being silently dropped.
Call this only BETWEEN frames: any partially-accumulated frame bytes in the
codec’s own line buffer are discarded (immediately after a successful next()
that buffer is empty, so the hand-off is lossless).
Sourcepub async fn next(&mut self) -> Result<Option<Inbound>>
pub async fn next(&mut self) -> Result<Option<Inbound>>
Ok(None) = clean EOF. Violations do not consume the following frames.
EOF while discarding an oversized line still reports TooLarge (the next
call returns Ok(None)). A truncated ORDINARY frame at EOF is silently
dropped (matches MCP stdio convention — deliberate).