Skip to main content

Module streaming

Module streaming 

Source
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§

ParseProgress
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.