Skip to main content

Module wire

Module wire 

Source
Expand description

Wire format for replicated mutations — see docs/wire.md for the full spec.

Each frame is *2\r\n:<offset>\r\n<RESP2 multi-bulk argv>. The envelope is itself a valid RESP2 array of 2 elements, so any RESP-aware debug tool can peek a captured stream. The inner argv payload is byte-identical to what a client would have sent when issuing the same command, so feeding it through the existing parse_command_into reconstructs the same Argv the primary applied.

Enums§

SnapshotMarker
Decoded snapshot marker, returned by decode_snapshot_marker.
WireError
Wire-layer error. Only WireError::Truncated is recoverable by the caller (read more bytes and retry); the other variants signal a corrupt or protocol-violating peer and call for dropping the connection.

Constants§

SNAPSHOT_CHUNK_MAX
Per-chunk cap: a chunk’s $L\r\n length must not exceed this. Replica drops the link if a chunk header reports a larger size. 64 KiB matches a typical TCP segment + keeps the per-chunk allocation modest. The primary may pick any chunk size from 1 up to this.
SNAPSHOT_LINE_MAX
Maximum length of a snapshot control line (+SNAPSHOT_END N\r\n). 256 B is generous — the longest legal line is +SNAPSHOT_END + 20 digits + \r\n = 38 B.

Functions§

decode_frame
Decode the first complete frame at the front of buf.
decode_snapshot_chunk
Decode the next snapshot chunk ($L\r\n<L bytes>\r\n) at the front of buf. Returns:
decode_snapshot_marker
Peek the next line at the front of buf to detect a snapshot marker. Returns:
encode_frame
Encode one replication frame: outer *2, offset integer, then the argv as a RESP2 multi-bulk request. Allocates a fresh Vec<u8>. Generic over ArgvView so the hot path can pass a borrowed argv straight from the dispatcher (no Argv materialisation per write).
encode_snapshot_begin
Encode the snapshot-begin marker. Allocates the exact 11 bytes.
encode_snapshot_chunk
Encode one snapshot chunk as a RESP bulk string. Caller is responsible for chunking — typical strategy is fixed SNAPSHOT_CHUNK_MAX-sized reads from a snapshot file or in-memory serializer.
encode_snapshot_end
Encode the snapshot-end marker carrying the ack offset (the next live frame’s offset will equal this value).