Module protocol

Module protocol 

Source
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.
ResponseMeta
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.
ParseResult
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_max is 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 ADD when key already present) (0x0002).
ST_NF
Key not found (0x0001).
ST_NOT_STORED
Item not stored (CAS mismatch or REPLACE on 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 None for any non-Ok result. Prefer try_parse_request in 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 w using a raw opcode byte. This is the low-level writer; prefer write_response when you have a known Opcode.
write_response
Write a complete binary-protocol response to w.
write_simple_response
Convenience: write a simple response with no extras or key.