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
- Variables
- func DecodeOidDatum(ctx ast.ParseTimeContext, id oid.Oid, code FormatCode, b []byte) (ast.Datum, error)
- func NewInvalidBinaryRepresentationErrorf(format string, args ...interface{}) error
- func NewProtocolViolationErrorf(format string, args ...interface{}) error
- func NewUnrecognizedMsgTypeErr(typ ClientMessageType) error
- type BufferedReader
- type ClientMessageType
- type Conn
- type FormatCode
- type PGNumeric
- type PGNumericSign
- type PrepareType
- type ReadBuffer
- func (b *ReadBuffer) GetBytes(n int) ([]byte, error)
- func (b *ReadBuffer) GetPrepareType() (PrepareType, error)
- func (b *ReadBuffer) GetString() (string, error)
- func (b *ReadBuffer) GetUint16() (uint16, error)
- func (b *ReadBuffer) GetUint32() (uint32, error)
- func (b *ReadBuffer) ReadTypedMsg(rd BufferedReader) (ClientMessageType, int, error)
- func (b *ReadBuffer) ReadUntypedMsg(rd io.Reader) (int, error)
- type ServerErrFieldType
- type ServerMessageType
Constants ¶
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' )
http://www.postgresql.org/docs/9.4/static/protocol-message-formats.html
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".
Variables ¶
var ( // PGEpochJDate represents the pg epoch. PGEpochJDate = time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC) )
Functions ¶
func DecodeOidDatum ¶
func DecodeOidDatum( ctx ast.ParseTimeContext, id oid.Oid, code FormatCode, b []byte, ) (ast.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 ¶
NewInvalidBinaryRepresentationErrorf creates a pgwire InvalidBinaryRepresentation.
func NewProtocolViolationErrorf ¶
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 Conn ¶
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: https://www.postgresql.org/docs/current/static/protocol-flow.html#PROTOCOL-COPY 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 ¶
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 (*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) 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.
type ServerErrFieldType ¶
type ServerErrFieldType byte
ServerErrFieldType represents the error fields.
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' )
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