Expand description
Self-built wire-frame codec for SPG.
Frame layout (little-endian):
+-----------------+--------+----------------------------+
| payload_len:u32 | op:u8 | payload[payload_len bytes] |
+-----------------+--------+----------------------------+Header is always FRAME_HEADER_LEN bytes. Maximum payload is
MAX_PAYLOAD bytes; oversized frames are rejected before allocation.
Endianness is little-endian everywhere (modern CPUs are LE; the protocol is self-defined so we drop the PG/MySQL big-endian baggage).
Structs§
- Column
Desc - Column metadata sent in a
RowDescriptionframe. - Frame
- One decoded frame held in memory.
Enums§
- Frame
Error - Decode-side errors. Encode never produces these unless the caller exceeded
MAX_PAYLOAD; seeencode. - Op
- Wire opcodes (1 byte each). Numeric values are stable on the wire — never renumber an existing variant.
- Wire
Type - On-wire type tags. Stable bytes — never renumber.
- Wire
Value - One value as it travels on the wire. Mirrors
spg-storage::Valuebutspg-wireis dep-free of storage — callers convert at the boundary.
Constants§
- FRAME_
HEADER_ LEN - Fixed-header byte count:
u32 length+u8 opcode. - MAX_
PAYLOAD - Hard ceiling on payload size. Keeps
decodebounded even when a peer declares an absurd length. 16 MiB is generous for v0.x — revisit alongside streaming result-set support.
Functions§
- build_
auth - Build an
Authframe carrying the candidate password. - build_
auth_ user - Build an
AuthUserframe:[u16 user_len][user][password]. - build_
command_ complete - build_
data_ row - build_
data_ row_ batch - Pack many rows into one frame. All rows must have the same
cell_count; the count is written once at the front of the payload (saving 2 bytes per row vs a stream ofDataRowframes). - build_
error_ response - build_
query - build_
row_ description - build_
stats_ request - Build a
Statsrequest frame. Payload is empty. - build_
stats_ response - Build a
StatsResponseframe carrying a UTF-8 text body. - decode
- Attempt to decode one frame from the front of
buf. - encode
- Encode one frame, appending to
out. - parse_
auth - Read the candidate password out of an
Authframe. The bytes must be valid UTF-8; non-UTF-8 inputs surface as a clear protocol error. - parse_
auth_ user - Parse
(username, password)out of anAuthUserframe. Both slices must be valid UTF-8; truncated payloads surface as a clear protocol error. - parse_
command_ complete - parse_
data_ row - parse_
data_ row_ batch - parse_
error_ response - parse_
query - parse_
row_ description - parse_
stats_ response