Expand description
Zero-Copy RESP Protocol Parser
This module implements a high-performance, zero-copy parser for the RESP protocol.
Zero-copy means we avoid copying data wherever possible, instead using references
and Bytes which can be cheaply cloned (it’s just incrementing a reference count).
§Design Philosophy
- Zero-Copy: We use
bytes::Bytesto avoid memory allocations during parsing. - Incremental: The parser can handle partial data and resume when more arrives.
- Error Recovery: Clear error messages for debugging protocol issues.
§How the Parser Works
The parser reads from a buffer and returns either:
Ok(Some((value, consumed)))- Successfully parsed a value,consumedbytes were usedOk(None)- Need more data, the message is incompleteErr(ParseError)- Invalid protocol data
This design allows the caller to:
- Append incoming network data to a buffer
- Call
parse()to attempt parsing - If successful, advance the buffer by
consumedbytes - If incomplete, wait for more data
- If error, handle or disconnect the client
Structs§
- Resp
Parser - A zero-copy RESP protocol parser.
Enums§
- Parse
Error - Errors that can occur during RESP parsing.
Constants§
- MAX_
BULK_ SIZE - Maximum size for a single bulk string (512 MB, same as Redis)
- MAX_
NESTING_ DEPTH - Maximum array nesting depth (prevent stack overflow)
Functions§
- parse_
message - Helper function to parse a single RESP message from bytes.
Type Aliases§
- Parse
Result - Result type for parsing operations.