cockroach: Index | Files

package pgwirebase

import ""

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.


Package Files

clientmessagetype_string.go conn.go doc.go encoding.go formatcode_string.go msg.go pgnumericsign_string.go preparetype_string.go servererrfieldtype_string.go servermessagetype_string.go


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
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'
    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'

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.

const PGDecDigits = 4

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


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

func DecodeOidDatum Uses

func DecodeOidDatum(
    ctx tree.ParseTimeContext, id oid.Oid, code FormatCode, b []byte,
) (tree.Datum, error)

DecodeOidDatum decodes bytes with specified Oid and format code into a datum. If the ParseTimeContext is nil, reasonable defaults will be applied.

func NewInvalidBinaryRepresentationErrorf Uses

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

NewInvalidBinaryRepresentationErrorf creates a pgwire InvalidBinaryRepresentation.

func NewProtocolViolationErrorf Uses

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

NewProtocolViolationErrorf creates a pgwire ProtocolViolationError.

func NewUnrecognizedMsgTypeErr Uses

func NewUnrecognizedMsgTypeErr(typ ClientMessageType) error

NewUnrecognizedMsgTypeErr creates an error for an unrecognized pgwire message.

type BufferedReader Uses

type BufferedReader interface {
    ReadString(delim byte) (string, error)
    ReadByte() (byte, error)

BufferedReader extended io.Reader with some convenience methods.

type ClientMessageType Uses

type ClientMessageType byte

ClientMessageType represents a client pgwire message. go:generate stringer -type=ClientMessageType

func (ClientMessageType) String Uses

func (i ClientMessageType) String() string

type Conn Uses

type Conn interface {
    // Rd returns a reader to be used to consume bytes from the connection.
    // This reader can be used with a pgwirebase.ReadBuffer for reading messages.
    // Note that in the pgwire implementation, this reader encapsulates logic for
    // updating connection metrics.
    Rd() BufferedReader

    // BeginCopyIn sends the message server message initiating the Copy-in
    // subprotocol (COPY ... FROM STDIN). This message informs the client about
    // the columns that are expected for the rows to be inserted.
    // Currently, we only support the "text" format for COPY IN.
    // See:
    BeginCopyIn(ctx context.Context, columns []sqlbase.ResultColumn) error

    // SendCommandComplete sends a serverMsgCommandComplete with the given
    // payload.
    SendCommandComplete(tag []byte) error

Conn exposes some functionality of a pgwire network connection to be used by the Copy-in subprotocol implemented in the sql package.

type FormatCode Uses

type FormatCode uint16

FormatCode represents a pgwire data format.

go:generate stringer -type=FormatCode

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

func (FormatCode) String Uses

func (i FormatCode) String() string

type PGNumeric Uses

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

PGNumeric represents a numeric.

type PGNumericSign Uses

type PGNumericSign uint16

PGNumericSign indicates the sign of a numeric. go:generate stringer -type=PGNumericSign

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

func (PGNumericSign) String Uses

func (i PGNumericSign) String() string

type PrepareType Uses

type PrepareType byte

PrepareType represents a subtype for prepare messages. go:generate stringer -type=PrepareType

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

func (PrepareType) String Uses

func (i PrepareType) String() string

type ReadBuffer Uses

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

ReadBuffer provides a convenient way to read pgwire protocol messages.

func (*ReadBuffer) GetBytes Uses

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

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

func (*ReadBuffer) GetPrepareType Uses

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

GetPrepareType returns the buffer's contents as a PrepareType.

func (*ReadBuffer) GetString Uses

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

GetString reads a null-terminated string.

func (*ReadBuffer) GetUint16 Uses

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

GetUint16 returns the buffer's contents as a uint16.

func (*ReadBuffer) GetUint32 Uses

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

GetUint32 returns the buffer's contents as a uint32.

func (*ReadBuffer) ReadTypedMsg Uses

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 Uses

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.

type ServerErrFieldType Uses

type ServerErrFieldType byte

ServerErrFieldType represents the error fields. go:generate stringer -type=ServerErrFieldType

const (
    ServerErrFieldSeverity    ServerErrFieldType = 'S'
    ServerErrFieldSQLState    ServerErrFieldType = 'C'
    ServerErrFieldMsgPrimary  ServerErrFieldType = 'M'
    ServerErrFileldDetail     ServerErrFieldType = 'D'
    ServerErrFileldHint       ServerErrFieldType = 'H'
    ServerErrFieldSrcFile     ServerErrFieldType = 'F'
    ServerErrFieldSrcLine     ServerErrFieldType = 'L'
    ServerErrFieldSrcFunction ServerErrFieldType = 'R'

func (ServerErrFieldType) String Uses

func (i ServerErrFieldType) String() string

type ServerMessageType Uses

type ServerMessageType byte

ServerMessageType represents a server pgwire message. go:generate stringer -type=ServerMessageType

func (ServerMessageType) String Uses

func (i ServerMessageType) String() string

Package pgwirebase imports 28 packages (graph) and is imported by 9 packages. Updated 2020-08-05. Refresh now. Tools for package owners.