Expand description
Pure protocol types, parsing, and response building for the memcached
binary protocol. This module has no dependency on redis-module and
can be tested in a normal cargo test process.
Structs§
- Header
- Parsed memcached binary-protocol request header.
- Request
- A fully parsed binary-protocol request, borrowing from the input buffer.
- Response
Meta - Groups the protocol-level metadata fields that every binary response carries. Using a struct avoids exceeding clippy’s argument limit on the response-writing functions.
Enums§
- Opcode
- Memcached binary-protocol opcode.
- Parse
Result - Outcome of
try_parse_request.
Constants§
- CAS_
ZERO - CAS value used in error and control responses.
- HEADER_
LEN - Length of a binary-protocol request/response header in bytes.
- MAGIC_
REQ - Magic byte for a binary-protocol request frame (
0x80). - MAGIC_
RES - Magic byte for a binary-protocol response frame (
0x81). - MAX_
BODY_ LEN - Maximum allowed body length per frame. Memcached’s default
item_size_maxis 1 MiB; we allow up to 20 MiB to be generous while still preventing multi-gigabyte allocations from a single malicious or buggy frame. - MAX_
KEY_ LEN - Maximum allowed key length. The memcached binary protocol uses a u16 for key_len (max 65535), but the traditional memcached limit is 250 bytes. We enforce the 250-byte limit for compatibility.
- ST_ARGS
- Invalid arguments (
0x0004). - ST_
AUTH_ CONTINUE - Authentication continue (multi-step SASL) (
0x0021). - ST_
AUTH_ ERROR - Authentication error (
0x0020). - ST_IX
- Key exists (used by
ADDwhen key already present) (0x0002). - ST_NF
- Key not found (
0x0001). - ST_
NOT_ STORED - Item not stored (CAS mismatch or
REPLACEon missing key) (0x0005). - ST_OK
- Success status (
0x0000). - ST_UNK
- Unknown command (
0x0081).
Functions§
- build_
raw_ request_ frame - Build a request frame using a raw opcode byte. Useful for testing unknown-opcode handling.
- build_
request_ frame - Build a binary-protocol request frame from parts. Useful for tests and for any code that needs to construct wire-format requests.
- parse_
request - Legacy convenience wrapper — returns
Nonefor any non-Ok result. Prefertry_parse_requestin new code. - try_
parse_ request - Try to parse one complete request from
buf. - write_
error_ for_ raw_ opcode - Write an error response for an unknown or malformed opcode, using the raw opcode byte from the wire.
- write_
raw_ response - Write a complete binary-protocol response to
wusing a raw opcode byte. This is the low-level writer; preferwrite_responsewhen you have a knownOpcode. - write_
response - Write a complete binary-protocol response to
w. - write_
simple_ response - Convenience: write a simple response with no extras or key.