pub struct FrameReader { /* private fields */ }Implementations§
Source§impl FrameReader
impl FrameReader
Sourcepub fn read_from<R: Read>(
&mut self,
reader: &mut R,
) -> Result<Vec<OwnedFrame>, ProtocolError>
pub fn read_from<R: Read>( &mut self, reader: &mut R, ) -> Result<Vec<OwnedFrame>, ProtocolError>
Read bytes from reader and return any newly complete frames.
If the internal buffer already holds partial data from a previous call,
the reader is drained until the pending frame is complete or EOF.
If the buffer is empty, exactly one read is performed and whatever
complete frames are present are returned.
Header fields (magic, version, message type, payload length) are
validated as soon as a full header is in the buffer — before any
payload bytes are accumulated — so a malicious oversized
payload_length cannot cause a large allocation.
§Errors
| Condition | Error kind |
|---|---|
Underlying read() returns an I/O error | ProtocolErrorKind::InternalError |
| Magic bytes mismatch | ProtocolErrorKind::InvalidMagic |
| Version mismatch | ProtocolErrorKind::UnsupportedVersion |
Unknown msg_type byte | ProtocolErrorKind::UnknownMessageType |
payload_length > MAX_PAYLOAD_SIZE | ProtocolErrorKind::PayloadTooLarge |
§Panics
Never panics. All slice indexing in the extraction loop is guarded by
the buffer.len() - offset < HEADER_SIZE check, and the fixed-width
try_into() conversions are infallible for the exact slice lengths used.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FrameReader
impl RefUnwindSafe for FrameReader
impl Send for FrameReader
impl Sync for FrameReader
impl Unpin for FrameReader
impl UnsafeUnpin for FrameReader
impl UnwindSafe for FrameReader
Blanket Implementations§
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
Mutably borrows from an owned value. Read more