Skip to main content

Crate spg_wire

Crate spg_wire 

Source
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§

ColumnDesc
Column metadata sent in a RowDescription frame.
Frame
One decoded frame held in memory.

Enums§

FrameError
Decode-side errors. Encode never produces these unless the caller exceeded MAX_PAYLOAD; see encode.
Op
Wire opcodes (1 byte each). Numeric values are stable on the wire — never renumber an existing variant.
WireType
On-wire type tags. Stable bytes — never renumber.
WireValue
One value as it travels on the wire. Mirrors spg-storage::Value but spg-wire is 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 decode bounded 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 Auth frame carrying the candidate password.
build_auth_user
Build an AuthUser frame: [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 of DataRow frames).
build_error_response
build_query
build_row_description
build_stats_request
Build a Stats request frame. Payload is empty.
build_stats_response
Build a StatsResponse frame 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 Auth frame. 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 an AuthUser frame. 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