pub struct FrameBuffer { /* private fields */ }Expand description
Buffer for accumulating incoming bytes and extracting complete frames.
Uses a state machine to handle partial reads efficiently.
All data is stored in a single BytesMut buffer to minimize allocations.
Implementations§
Source§impl FrameBuffer
impl FrameBuffer
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new frame buffer with default settings.
Default capacity: 64KB, max payload: 1GB.
Sourcepub fn with_max_payload(max_payload_size: u32) -> Self
pub fn with_max_payload(max_payload_size: u32) -> Self
Create a new frame buffer with custom max payload size.
Sourcepub fn with_capacity_and_max_payload(
capacity: usize,
max_payload_size: u32,
) -> Self
pub fn with_capacity_and_max_payload( capacity: usize, max_payload_size: u32, ) -> Self
Create a new frame buffer with custom capacity and max payload.
Sourcepub fn push(&mut self, data: &[u8]) -> Result<Vec<Frame>>
pub fn push(&mut self, data: &[u8]) -> Result<Vec<Frame>>
Push data into the buffer and extract all complete frames.
This is the main API for processing incoming data from the socket. Returns a vector of complete frames. If data is fragmented, partial data is buffered internally for the next push.
§Arguments
data- Raw bytes from socket read
§Returns
Vector of complete frames (may be empty if still waiting for data).
§Errors
Returns error if payload exceeds max_payload_size.
Sourcepub fn try_extract(&mut self) -> Option<Frame>
👎Deprecated: Use push() instead for proper multi-frame handling
pub fn try_extract(&mut self) -> Option<Frame>
Legacy method - try to extract a single frame.
Prefer using push() which handles multiple frames efficiently.