protocol

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package protocol holds PostgreSQL v3 frontend/backend message codes and a few small helpers. The codes are mirrored from src/include/libpq/protocol.h in the PostgreSQL source tree.

Index

Constants

View Source
const (
	MsgAuthentication       byte = 'R'
	MsgBackendKeyData       byte = 'K'
	MsgBindComplete         byte = '2'
	MsgCloseComplete        byte = '3'
	MsgCommandComplete      byte = 'C'
	MsgDataRow              byte = 'D'
	MsgEmptyQueryResponse   byte = 'I'
	MsgErrorResponse        byte = 'E'
	MsgNoData               byte = 'n'
	MsgNoticeResponse       byte = 'N'
	MsgNotificationResponse byte = 'A'
	MsgParameterDescription byte = 't'
	MsgParameterStatus      byte = 'S'
	MsgParseComplete        byte = '1'
	MsgPortalSuspended      byte = 's'
	MsgReadyForQuery        byte = 'Z'
	MsgRowDescription       byte = 'T'
	MsgNegotiateProtocol    byte = 'v'
	MsgCopyInResponse       byte = 'G'
	MsgCopyOutResponse      byte = 'H'
	MsgCopyBothResponse     byte = 'W'
)

Backend message types (server -> client).

View Source
const (
	MsgBind     byte = 'B'
	MsgClose    byte = 'C'
	MsgDescribe byte = 'D'
	MsgExecute  byte = 'E'
	MsgFlush    byte = 'H'
	MsgParse    byte = 'P'
	MsgQuery    byte = 'Q'
	MsgSync     byte = 'S'
	MsgTerm     byte = 'X'
	MsgPassword byte = 'p' // also SASL{Initial,}Response
	MsgCopyData byte = 'd' // bidirectional
	MsgCopyDone byte = 'c' // bidirectional
	MsgCopyFail byte = 'f' // frontend only
)

Frontend message types (client -> server).

View Source
const (
	AuthOK                = 0
	AuthCleartextPassword = 3
	AuthMD5Password       = 5
	AuthSASL              = 10
	AuthSASLContinue      = 11
	AuthSASLFinal         = 12
)

Authentication request subtypes (the int32 immediately following the length in an 'R' message).

View Source
const (
	FormatText   int16 = 0
	FormatBinary int16 = 1
)

Format codes for Bind/RowDescription.

View Source
const ProtocolVersion3 = (3 << 16) | 0

Protocol version: major 3, minor 0. Newer minors exist but 3.0 is what every server understands and is what we actually need.

Variables

This section is empty.

Functions

func IsRange

func IsRange(o OID) bool

IsRange reports whether oid names a PostgreSQL range type we recognise. Range types share a common wire format (flags byte + optional lower/upper bounds) regardless of the element type, so the decoder does not need to dispatch further on the element OID.

Types

type OID

type OID uint32

OID values are stable PostgreSQL constants from src/include/catalog/pg_type.dat. We only enumerate the ones with specialised encoders. Anything else falls back to the string encoder, which is the safe path for the text protocol.

const (
	OIDBool        OID = 16
	OIDBytea       OID = 17
	OIDName        OID = 19
	OIDInt8        OID = 20
	OIDInt2        OID = 21
	OIDInt4        OID = 23
	OIDText        OID = 25
	OIDOID         OID = 26
	OIDJSON        OID = 114
	OIDFloat4      OID = 700
	OIDFloat8      OID = 701
	OIDBPChar      OID = 1042
	OIDVarchar     OID = 1043
	OIDDate        OID = 1082
	OIDTime        OID = 1083
	OIDTimestamp   OID = 1114
	OIDTimestampTZ OID = 1184
	OIDInterval    OID = 1186
	OIDTimeTZ      OID = 1266
	OIDNumeric     OID = 1700
	OIDUUID        OID = 2950
	OIDJSONB       OID = 3802

	// Array OIDs (pg_type.typelem resolves to the scalar OID above).
	OIDBoolArray        OID = 1000
	OIDInt2Array        OID = 1005
	OIDInt4Array        OID = 1007
	OIDTextArray        OID = 1009
	OIDBPCharArray      OID = 1014
	OIDVarcharArray     OID = 1015
	OIDInt8Array        OID = 1016
	OIDFloat4Array      OID = 1021
	OIDFloat8Array      OID = 1022
	OIDOIDArray         OID = 1028
	OIDByteaArray       OID = 1001
	OIDDateArray        OID = 1182
	OIDTimestampArray   OID = 1115
	OIDTimestampTZArray OID = 1185
	OIDUUIDArray        OID = 2951
	OIDJSONArray        OID = 199
	OIDJSONBArray       OID = 3807
	OIDNumericArray     OID = 1231

	// Range types (pg_type.dat).
	OIDInt4Range OID = 3904
	OIDNumRange  OID = 3906
	OIDTsRange   OID = 3908
	OIDTsTzRange OID = 3910
	OIDDateRange OID = 3912
	OIDInt8Range OID = 3926
)

func ArrayElem

func ArrayElem(o OID) OID

ArrayElem returns the element OID for the given array OID, or 0 if the OID is not a recognised array type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL