Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeBoolean(value bool) string
- func NewInsufficientData(length int) error
- func NewMessageSizeExceeded(max, size int) error
- func NewMissingNulTerminator() error
- type BufferedReader
- type MessageSizeExceeded
- type PrepareType
- type Reader
- func (reader *Reader) GetBytes(n int) ([]byte, error)
- func (reader *Reader) GetPrepareType() (PrepareType, error)
- func (reader *Reader) GetString() (string, error)
- func (reader *Reader) GetUint16() (uint16, error)
- func (reader *Reader) GetUint32() (uint32, error)
- func (reader *Reader) ReadTypedMsg() (types.ClientMessage, int, error)
- func (reader *Reader) ReadUntypedMsg() (int, error)
- func (reader *Reader) Slurp(size int) error
- type ServerErrFieldType
- type Writer
- func (writer *Writer) AddByte(b byte)
- func (writer *Writer) AddBytes(b []byte) (size int)
- func (writer *Writer) AddInt16(i int16) (size int)
- func (writer *Writer) AddInt32(i int32) (size int)
- func (writer *Writer) AddNullTerminate()
- func (writer *Writer) AddString(s string) (size int)
- func (writer *Writer) Bytes() []byte
- func (writer *Writer) End() error
- func (writer *Writer) Error() error
- func (writer *Writer) Reset()
- func (writer *Writer) Start(t types.ServerMessage)
Constants ¶
const DefaultBufferSize = 1 << 24 // 16777216 bytes
DefaultBufferSize represents the default buffer size whenever the buffer size is not set or a negative value is presented.
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.
Variables ¶
var ErrInsufficientData = errors.New("insufficient data")
ErrInsufficientData is thrown when there is insufficient data available inside the given message to unmarshal into a given type.
var ErrMessageSizeExceeded = MessageSizeExceeded{Message: "maximum message size exceeded"}
ErrMessageSizeExceeded is thrown when the maximum message size is exceeded.
var ErrMissingNulTerminator = errors.New("NUL terminator not found")
ErrMissingNulTerminator is thrown when no NUL terminator is found when interperating a message property as a string.
Functions ¶
func EncodeBoolean ¶
EncodeBoolean returns a string value ("on"/"off") representing the given boolean value
func NewInsufficientData ¶
NewInsufficientData constructs a new error message wrapping the ErrInsufficientData type with additional metadata.
func NewMessageSizeExceeded ¶
NewMessageSizeExceeded constructs a new error message wrapping the ErrMaxMessageSizeExceeded type with additional metadata.
func NewMissingNulTerminator ¶
func NewMissingNulTerminator() error
NewMissingNulTerminator constructs a new error message wrapping the ErrMissingNulTerminator type with additional metadata.
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 MessageSizeExceeded ¶
MessageSizeExceeded represents a error implementation which could be used to indicate that the message size limit has been exceeded. The message size and maximum message length could be included inside the struct.
func UnwrapMessageSizeExceeded ¶
func UnwrapMessageSizeExceeded(err error) (result MessageSizeExceeded, _ bool)
UnwrapMessageSizeExceeded attempts to unwrap the given error as MessageSizeExceeded. A boolean is returned indicating whether the error contained a MessageSizeExceeded message.
func (MessageSizeExceeded) Error ¶
func (err MessageSizeExceeded) Error() string
func (MessageSizeExceeded) Is ¶
func (err MessageSizeExceeded) Is(target error) bool
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' )
type Reader ¶
type Reader struct { Buffer BufferedReader Msg []byte MaxMessageSize int // contains filtered or unexported fields }
Reader provides a convenient way to read pgwire protocol messages
func (*Reader) GetPrepareType ¶
func (reader *Reader) GetPrepareType() (PrepareType, error)
GetPrepareType returns the buffer's contents as a PrepareType.
func (*Reader) ReadTypedMsg ¶
func (reader *Reader) ReadTypedMsg() (types.ClientMessage, 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 (*Reader) ReadUntypedMsg ¶
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.
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
type Writer ¶
Writer provides a convenient way to write pgwire protocol messages
func NewWriter ¶
NewWriter constructs a new Postgres buffered message writer for the given io.Writer
func (*Writer) AddByte ¶
AddByte writes the given byte to the writer frame. Bytes written to the frame could be read at any stage to interact with a Postgres client. Errors thrown while writing to the writer could be read by calling writer.Error()
func (*Writer) AddBytes ¶
AddBytes writes the given bytes to the writer frame. Bytes written to the frame could be read at any stage to interact with a Postgres client. Errors thrown while writing to the writer could be read by calling writer.Error()
func (*Writer) AddInt16 ¶
AddInt16 writes the given unsigned int16 to the writer frame. Bytes written to the frame could be read at any stage to interact with a Postgres client. Errors thrown while writing to the writer could be read by calling writer.Error()
func (*Writer) AddInt32 ¶
AddInt32 writes the given unsigned int32 to the writer frame. Bytes written to the frame could be read at any stage to interact with a Postgres client. Errors thrown while writing to the writer could be read by calling writer.Error()
func (*Writer) AddNullTerminate ¶
func (writer *Writer) AddNullTerminate()
AddNullTerminate writes a null terminate symbol to the end of the given data frame
func (*Writer) AddString ¶
AddString writes the given string to the writer frame. Bytes written to the frame could be read at any stage to interact with a Postgres client. Errors thrown while writing to the writer could be read by calling writer.Error()
func (*Writer) End ¶
End writes the prepared message to the given writer and resets the buffer. The to be expected message length is appended after the message status byte.
func (*Writer) Start ¶
func (writer *Writer) Start(t types.ServerMessage)
Start resets the buffer writer and starts a new message with the given message type. The message type (byte) and reserved message length bytes (int32) are written to the underlaying bytes buffer.