reader

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: MIT, MPL-2.0 Imports: 9 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.

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

type Reader struct {
	Buffer         io.Reader
	Msg            []byte
	MaxMessageSize int
	// contains filtered or unexported fields
}

Reader provides a convenient way to read pgwire protocol messages

func NewReader

func NewReader(logger *slog.Logger, reader io.Reader, bufferSize int) *Reader

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

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

func (reader *Reader) ReadUntypedMsg() (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 (*Reader) Slurp

func (reader *Reader) Slurp(size int) error

Slurp reads the remaining

Jump to

Keyboard shortcuts

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