Expand description
Streaming command parser for zero-copy receive optimization.
This module provides incremental parsing that can pause after parsing a command header, allowing the caller to receive large values directly into a target buffer (e.g., cache segment memory) without intermediate copies.
§Example
ⓘ
use protocol_resp::streaming::{StreamingParser, ParseProgress};
let mut parser = StreamingParser::new();
// Feed data as it arrives
match parser.parse(buffer)? {
ParseProgress::Incomplete => {
// Need more data
}
ParseProgress::NeedValue { header, value_len, .. } => {
// Allocate target buffer for value
let mut target = cache.reserve_set(header.key, value_len)?;
// Receive remaining bytes directly into target
recv_into(target.value_mut())?;
// Complete the command
parser.complete_value(target.value_mut());
}
ParseProgress::Complete(cmd, consumed) => {
// Handle complete command
}
}Structs§
- SetHeader
- Parsed SET command header (without the value).
Enums§
- Parse
Progress - Result of incremental parsing.
Constants§
- STREAMING_
THRESHOLD - Threshold for using streaming parse (64KB). Values smaller than this don’t benefit enough from zero-copy receive.
Functions§
- complete_
set - Complete parsing a SET command after the value has been received.
- parse_
streaming - Parse a command, potentially yielding early for large SET values.