TCP Protocol Frame Contract v1#
Scope#
This document specifies the length-prefixed binary frame format used on the MuduDB custom TCP client/server connection. It carries request/response messages between mcli / client libraries and mudud.
Version history#
Version |
Date |
Summary |
|---|---|---|
1 |
2026-6-25 |
Initial 40-byte header with magic, version, 32-bit message type, 64-bit flags, request id, trace id, and payload length. |
Frame layout#
+-----------------------------+
| Header (40 bytes) |
+-----------------------------+
| Payload (variable) |
+-----------------------------+
Each frame is encoded as a single header followed by a payload. The transport layer is responsible for delivering the exact byte range; there is no separate length prefix outside the header.
Header#
All header fields are big-endian.
Offset |
Size |
Field |
Description |
|---|---|---|---|
0 |
4 |
|
Magic |
4 |
4 |
|
Protocol frame version. Current value: |
8 |
4 |
|
Message type discriminant (see below). |
12 |
8 |
|
Frame flags. Bit 0 ( |
20 |
8 |
|
Client-assigned request identifier. |
28 |
8 |
|
Distributed trace identifier. |
36 |
4 |
|
Length of the payload in bytes. |
Message types#
Value |
Name |
Payload encoding |
|---|---|---|
1 |
Handshake |
|
2 |
Auth |
|
3 |
Query |
|
4 |
Execute |
|
5 |
Batch |
|
6 |
Response |
|
7 |
Error |
|
8 |
Get |
|
9 |
Put |
|
10 |
RangeScan |
|
11 |
ProcedureInvoke |
|
12 |
SessionCreate |
|
13 |
SessionClose |
|
Handshake and version negotiation#
The protocol defines a handshake message for version negotiation:
HandshakeRequestcontainssupported_versions: Vec<u32>and optionalcapabilities: Vec<String>.HandshakeResponsecontainsselected_version: u32and optional server capabilities.
The current server implementation selects version 1 only. A client that does not include 1 in supported_versions receives IncompatibleProtocolVersion.
Integrity mechanisms#
Magic check: decoders reject frames whose magic does not match
0x4D53_464D.Version check: decoders reject any version other than
1.Length checks: decoders require at least 40 bytes for the header and
payload_lenadditional bytes for the payload.Message type validation: unknown message type values are rejected.
Payload length validation: decoders require at least
payload_lenbytes after the header and pass exactly that slice toFrame::from_parts. Buffers may contain bytes for subsequent frames.Flag validation: decoders reject frames with unknown flag bits set (only bit 0 is defined).
Compatibility matrix#
Reader \ Writer |
v1 |
|---|---|
v1 |
Compatible |
Only version 1 is supported.
Upgrade and rollback rules#
Upgrade: A future v2 frame may extend the header (e.g., add capability flags) or define new message types. V2 clients and servers must negotiate the version via the handshake before sending v2 frames.
Rollback: A v1 server receiving a v2-only frame returns
UnsupportedFormatVersion. A v2 server receiving a v1-only client selects version1during handshake.Breaking changes: New message types may be added in minor protocol versions. Removed or renamed message types require a major version bump.
Deprecation policy#
Version 1 may be deprecated only after:
All bundled clients and drivers support the new version.
The new version has been the default for at least one release cycle.
A compatibility test matrix exercises v1 client / v2 server and v2 client / v1 server.
References#
Frame format:
mudu_contract/src/protocol/format/latest.rsMessage types and payloads:
mudu_contract/src/protocol/mod.rsHandshake handler:
mudu_kernel/src/server/handlers/handshake.rs