Skip to main content

Module protocol

Module protocol 

Source
Expand description

PostgreSQL v3 wire protocol message framing (Phase 3.1 PG parity).

Implements the bits of the PG v3 protocol RedDB needs for simple query support: startup negotiation, authentication (trust), the simple query flow (QT/D*/C/Z), and error reporting.

The full PG reference lives at: https://www.postgresql.org/docs/current/protocol-message-formats.html

§Frame format (v3)

After the startup message, every frame is:

[u8 type] [i32 length (includes itself)] [payload]

Frames are big-endian. We use tokio::io::AsyncRead/Write so the listener can plug into the same task model as the existing wire binary protocol.

Structs§

ColumnDescriptor
StartupParams

Enums§

BackendMessage
Backend (server → client) messages we emit.
FrontendMessage
Frontend (client → server) messages we parse.
PgWireError
Error type surfaced by the framing layer. Wraps IO errors plus structural validation failures (bad message tag, truncated frame).
TransactionStatus

Constants§

PG_CANCEL_REQUEST
PG_GSSENC_REQUEST
PG_PROTOCOL_V3
Protocol version constant: 3.0 → 196608 (major<<16 | minor).
PG_SSL_REQUEST
Special startup-phase requests that share the StartupMessage length header. The PG reference calls out three: SSLRequest (80877103), GSSENCRequest (80877104), CancelRequest (80877102).

Functions§

read_frame
Read a regular tagged frame after the startup handshake.
read_startup
Read the initial StartupMessage (or SSL/GSS request). The startup frame has no type byte — just a length prefix followed by the payload. Returns either a decoded Startup/SSL/GSS message or an error.
write_frame
Serialize + send a backend message.
write_raw_byte
Emit a raw byte (used for the SSL/GSS negotiation response: ‘N’ meaning “not supported, continue in plaintext”).