pgwirebase

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package pgwirebase contains type definitions and very basic protocol structures to be used by both the pgwire package and by others (particularly by the sql package). The contents of this package have been extracted from the pgwire package for the implementation of the COPY IN protocol, which lives in sql.

Index

Constants

View Source
const (
	// PGBinaryIPv4family is the pgwire constant for IPv4. It is defined as
	// AF_INET.
	PGBinaryIPv4family byte = 2
	// PGBinaryIPv6family is the pgwire constant for IPv4. It is defined as
	// AF_NET + 1.
	PGBinaryIPv6family byte = 3
)
View Source
const (
	ClientMsgBind        ClientMessageType = 'B'
	ClientMsgClose       ClientMessageType = 'C'
	ClientMsgCopyData    ClientMessageType = 'd'
	ClientMsgCopyDone    ClientMessageType = 'c'
	ClientMsgCopyFail    ClientMessageType = 'f'
	ClientMsgDescribe    ClientMessageType = 'D'
	ClientMsgExecute     ClientMessageType = 'E'
	ClientMsgFlush       ClientMessageType = 'H'
	ClientMsgParse       ClientMessageType = 'P'
	ClientMsgPassword    ClientMessageType = 'p'
	ClientMsgSimpleQuery ClientMessageType = 'Q'
	ClientMsgSync        ClientMessageType = 'S'
	ClientMsgTerminate   ClientMessageType = 'X'

	ServerMsgAuth                 ServerMessageType = 'R'
	ServerMsgBackendKeyData       ServerMessageType = 'K'
	ServerMsgBindComplete         ServerMessageType = '2'
	ServerMsgCommandComplete      ServerMessageType = 'C'
	ServerMsgCloseComplete        ServerMessageType = '3'
	ServerMsgCopyInResponse       ServerMessageType = 'G'
	ServerMsgDataRow              ServerMessageType = 'D'
	ServerMsgEmptyQuery           ServerMessageType = 'I'
	ServerMsgErrorResponse        ServerMessageType = 'E'
	ServerMsgNoticeResponse       ServerMessageType = 'N'
	ServerMsgNoData               ServerMessageType = 'n'
	ServerMsgParameterDescription ServerMessageType = 't'
	ServerMsgParameterStatus      ServerMessageType = 'S'
	ServerMsgParseComplete        ServerMessageType = '1'
	ServerMsgPortalSuspended      ServerMessageType = 's'
	ServerMsgReady                ServerMessageType = 'Z'
	ServerMsgRowDescription       ServerMessageType = 'T'
)

http://www.postgresql.org/docs/9.4/static/protocol-message-formats.html

View Source
const MaxPreparedStatementArgs = math.MaxUint16

MaxPreparedStatementArgs is the maximum number of arguments a prepared statement can have when prepared via the Postgres wire protocol. This is not documented by Postgres, but is a consequence of the fact that a 16-bit integer in the wire format is used to indicate the number of values to bind during prepared statement execution.

View Source
const PGDecDigits = 4

PGDecDigits represents the number of decimal digits per int16 Postgres "digit".

Variables

View Source
var (
	// PGEpochJDate represents the pg epoch.
	PGEpochJDate = time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC)
)

Functions

func DecodeDatum

func DecodeDatum(
	evalCtx *tree.EvalContext, t *types.T, code FormatCode, b []byte,
) (tree.Datum, error)

DecodeDatum decodes bytes with specified type and format code into a datum. If res is nil, then user defined types are not attempted to be resolved.

func GetMessageTooBigSize

func GetMessageTooBigSize(err error) int

GetMessageTooBigSize attempts to unwrap and find a MessageTooBig.

func IsMessageTooBigError

func IsMessageTooBigError(err error) bool

IsMessageTooBigError denotes whether a message is too big.

func NewInvalidBinaryRepresentationErrorf

func NewInvalidBinaryRepresentationErrorf(format string, args ...interface{}) error

NewInvalidBinaryRepresentationErrorf creates a pgwire InvalidBinaryRepresentation.

func NewProtocolViolationErrorf

func NewProtocolViolationErrorf(format string, args ...interface{}) error

NewProtocolViolationErrorf creates a pgwire ProtocolViolationError.

func NewUnrecognizedMsgTypeErr

func NewUnrecognizedMsgTypeErr(typ ClientMessageType) error

NewUnrecognizedMsgTypeErr creates an error for an unrecognized pgwire message.

Types

type BufferedReader

type BufferedReader interface {
	io.Reader
	ReadString(delim byte) (string, error)
	ReadByte() (byte, error)
}

BufferedReader extended io.Reader with some convenience methods.

type ClientMessageType

type ClientMessageType byte

ClientMessageType represents a client pgwire message.

func (ClientMessageType) String

func (i ClientMessageType) String() string

type FormatCode

type FormatCode uint16

FormatCode represents a pgwire data format.

const (
	// FormatText is the default, text format.
	FormatText FormatCode = 0
	// FormatBinary is an alternative, binary, encoding.
	FormatBinary FormatCode = 1
)

func (FormatCode) String

func (i FormatCode) String() string

type PGNumeric

type PGNumeric struct {
	Ndigits, Weight, Dscale int16
	Sign                    PGNumericSign
}

PGNumeric represents a numeric.

type PGNumericSign

type PGNumericSign uint16

PGNumericSign indicates the sign of a numeric.

const (
	// PGNumericPos represents the + sign.
	PGNumericPos PGNumericSign = 0x0000
	// PGNumericNeg represents the - sign.
	PGNumericNeg PGNumericSign = 0x4000
)

func (PGNumericSign) String

func (i PGNumericSign) String() string

type PrepareType

type PrepareType byte

PrepareType represents a subtype for prepare messages.

const (
	// PrepareStatement represents a prepared statement.
	PrepareStatement PrepareType = 'S'
	// PreparePortal represents a portal.
	PreparePortal PrepareType = 'P'
)

func (PrepareType) String

func (i PrepareType) String() string

type ReadBuffer

type ReadBuffer struct {
	Msg []byte
	// contains filtered or unexported fields
}

ReadBuffer provides a convenient way to read pgwire protocol messages.

func MakeReadBuffer

func MakeReadBuffer(opts ...ReadBufferOption) ReadBuffer

MakeReadBuffer returns a new ReaderBuffer with the given size.

func (*ReadBuffer) GetBytes

func (b *ReadBuffer) GetBytes(n int) ([]byte, error)

GetBytes returns the buffer's contents as a []byte.

func (*ReadBuffer) GetPrepareType

func (b *ReadBuffer) GetPrepareType() (PrepareType, error)

GetPrepareType returns the buffer's contents as a PrepareType.

func (*ReadBuffer) GetString

func (b *ReadBuffer) GetString() (string, error)

GetString reads a null-terminated string.

func (*ReadBuffer) GetUint16

func (b *ReadBuffer) GetUint16() (uint16, error)

GetUint16 returns the buffer's contents as a uint16.

func (*ReadBuffer) GetUint32

func (b *ReadBuffer) GetUint32() (uint32, error)

GetUint32 returns the buffer's contents as a uint32.

func (*ReadBuffer) GetUint64

func (b *ReadBuffer) GetUint64() (uint64, error)

GetUint64 returns the buffer's contents as a uint64.

func (*ReadBuffer) ReadTypedMsg

func (b *ReadBuffer) ReadTypedMsg(rd BufferedReader) (ClientMessageType, int, error)

ReadTypedMsg reads a message from the provided reader, returning its type code and body. It returns the message type, number of bytes read, and an error if there was one.

func (*ReadBuffer) ReadUntypedMsg

func (b *ReadBuffer) ReadUntypedMsg(rd io.Reader) (int, error)

ReadUntypedMsg reads a length-prefixed message. It is only used directly during the authentication phase of the protocol; readTypedMsg is used at all other times. This returns the number of bytes read and an error, if there was one. The number of bytes returned can be non-zero even with an error (e.g. if data was read but didn't validate) so that we can more accurately measure network traffic.

If the error is related to consuming a buffer that is larger than the maxMessageSize, the remaining bytes will be read but discarded.

func (*ReadBuffer) SlurpBytes

func (b *ReadBuffer) SlurpBytes(rd io.Reader, n int) (int, error)

SlurpBytes will consume n bytes from the read buffer, using the existing buffer to ingest the message.

type ReadBufferOption

type ReadBufferOption func(*ReadBuffer)

ReadBufferOption is an optional argument to use with ReadBuffer.

type ServerErrFieldType

type ServerErrFieldType byte

ServerErrFieldType represents the error fields.

const (
	ServerErrFieldSeverity       ServerErrFieldType = 'S'
	ServerErrFieldSQLState       ServerErrFieldType = 'C'
	ServerErrFieldMsgPrimary     ServerErrFieldType = 'M'
	ServerErrFieldDetail         ServerErrFieldType = 'D'
	ServerErrFieldHint           ServerErrFieldType = 'H'
	ServerErrFieldSrcFile        ServerErrFieldType = 'F'
	ServerErrFieldSrcLine        ServerErrFieldType = 'L'
	ServerErrFieldSrcFunction    ServerErrFieldType = 'R'
	ServerErrFieldConstraintName ServerErrFieldType = 'n'
)

http://www.postgresql.org/docs/current/static/protocol-error-fields.html

func (ServerErrFieldType) String

func (i ServerErrFieldType) String() string

type ServerMessageType

type ServerMessageType byte

ServerMessageType represents a server pgwire message.

func (ServerMessageType) String

func (i ServerMessageType) String() string

Jump to

Keyboard shortcuts

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