Documentation
¶
Index ¶
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.
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 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 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 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 (*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.