buffer

package
v0.1.1-beta24 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2025 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
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.

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.

Variables

View Source
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.

View Source
var ErrMessageSizeExceeded = MessageSizeExceeded{Message: "maximum message size exceeded"}

ErrMessageSizeExceeded is thrown when the maximum message size is exceeded.

View Source
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

func EncodeBoolean(value bool) string

EncodeBoolean returns a string value ("on"/"off") representing the given boolean value

func NewInsufficientData

func NewInsufficientData(length int) error

NewInsufficientData constructs a new error message wrapping the ErrInsufficientData type with additional metadata.

func NewMessageSizeExceeded

func NewMessageSizeExceeded(max, size int) error

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

type MessageSizeExceeded struct {
	Message string
	Size    int
	Max     int
}

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 interface {
	GetString() (string, error)
	GetBytes(int) ([]byte, error)
	GetUint16() (uint16, error)
	GetUint32() (uint32, error)
	GetPrepareType() (PrepareType, error)
	ReadTypedMsg() (types.ClientMessage, int, error)

	ReadUntypedMsg() (int, error)

	Slurp(size int) error

	//
	ResetReader(size int)
	PeekMsg() []byte
}

Reader provides a convenient way to read pgwire protocol messages

func CreateTestReader

func CreateTestReader(msg []byte, buffer BufferedReader) Reader

func NewReader

func NewReader(reader io.Reader, bufferSize int) Reader

NewReader constructs a new Postgres wire buffer for the given io.Reader

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

type Writer interface {
	Start(types.ServerMessage)
	AddByte(byte)
	AddInt16(int16) int
	AddInt32(int32) int
	AddBytes([]byte) int
	AddString(string) int
	Bytes() []byte
	Error() error
	End() error
	Reset()
	AddNullTerminate()
	SetError(error)
}

Writer provides a convenient way to write pgwire protocol messages

func NewWriter

func NewWriter(writer io.Writer) Writer

NewWriter constructs a new Postgres buffered message writer for the given io.Writer

Jump to

Keyboard shortcuts

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