buffer

package
v0.0.0-...-1e4b8bd Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer is a simple wrapper over a slice of bytes with a cursor. It allows for easy command building and results parsing.

func New

func New(data []byte) *Buffer

New creates a new buffer from a given slice of bytes and sets the cursor to the beginning.

func NewCommandBuffer

func NewCommandBuffer(size int) *Buffer

NewCommandBuffer pre-allocates a buffer of a given size and reserves 4 bytes at the beginning for the driver, these would be used to set command length and sequence number.

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

Bytes returns entire buffer contents.

func (*Buffer) Cur

func (b *Buffer) Cur() []byte

Cur returns remaining unread buffer.

func (*Buffer) More

func (b *Buffer) More() bool

More returns true if there's more to read.

func (*Buffer) Read

func (b *Buffer) Read(n int) []byte

Read returns next N bytes and advances the cursor.

func (*Buffer) ReadDecimal

func (b *Buffer) ReadDecimal(precision, decimals int) mysql.Decimal

ReadDecimal decodes a decimal value from the buffer anf then advances cursor accordingly.

func (*Buffer) ReadFloat32

func (b *Buffer) ReadFloat32() float32

ReadFloat32 reads a float32 and advances cursor by 4 bytes.

func (*Buffer) ReadFloat64

func (b *Buffer) ReadFloat64() float64

ReadFloat64 reads a float64 and advances cursor by 8 bytes.

func (*Buffer) ReadStringEOF

func (b *Buffer) ReadStringEOF() []byte

ReadStringEOF reads remaining contents of the buffer as a new string.

func (*Buffer) ReadStringLenEnc

func (b *Buffer) ReadStringLenEnc() (str []byte, size int)

ReadStringLenEnc reads a length-encoded string and advances cursor accordingly.

func (*Buffer) ReadStringNullTerm

func (b *Buffer) ReadStringNullTerm() []byte

ReadStringNullTerm reads a NULL-terminated string and advances cursor by its length plus 1 extra byte.

func (*Buffer) ReadStringVarEnc

func (b *Buffer) ReadStringVarEnc(n int) []byte

ReadStringVarEnc reads a variable-length length of the string and the string itself, then advances cursor by the same number of bytes.

func (*Buffer) ReadStringVarLen

func (b *Buffer) ReadStringVarLen(n int) []byte

ReadStringVarLen reads a variable-length string and advances cursor by the same number of bytes.

func (*Buffer) ReadUint16

func (b *Buffer) ReadUint16() uint16

ReadUint16 reads a uint16 and advances cursor by 2 bytes.

func (*Buffer) ReadUint24

func (b *Buffer) ReadUint24() uint32

ReadUint24 reads a 3-byte integer as uint32 and advances cursor by 3 bytes.

func (*Buffer) ReadUint32

func (b *Buffer) ReadUint32() uint32

ReadUint32 reads a uint32 and advances cursor by 4 bytes.

func (*Buffer) ReadUint48

func (b *Buffer) ReadUint48() uint64

ReadUint48 reads a 6-byte integer as uint64 and advances cursor by 6 bytes.

func (*Buffer) ReadUint64

func (b *Buffer) ReadUint64() uint64

ReadUint64 reads a uint64 and advances cursor by 8 bytes.

func (*Buffer) ReadUint8

func (b *Buffer) ReadUint8() uint8

ReadUint8 reads a uint8 and advances cursor by 1 byte.

func (*Buffer) ReadUintLenEnc

func (b *Buffer) ReadUintLenEnc() (val uint64, isNull bool, size int)

ReadUintLenEnc reads a length-encoded integer and advances cursor accordingly.

func (*Buffer) ReadVarLen64

func (b *Buffer) ReadVarLen64(n int) uint64

ReadVarLen64 reads a number encoded in given size of bytes and advances cursor accordingly.

func (*Buffer) Skip

func (b *Buffer) Skip(n int)

Skip advances the cursor by N bytes.

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(v byte)

WriteByte writes given byte to the buffer and advances cursor by 1.

func (*Buffer) WriteStringEOF

func (b *Buffer) WriteStringEOF(s string)

WriteStringEOF writes given string to the buffer and advances cursor by its length.

func (*Buffer) WriteStringLenEnc

func (b *Buffer) WriteStringLenEnc(s string)

WriteStringLenEnc writes a length-encoded string to the buffer and advances cursor accordingly.

func (*Buffer) WriteUint16

func (b *Buffer) WriteUint16(v uint16)

WriteUint16 writes given uint16 value to the buffer and advances cursor by 2.

func (*Buffer) WriteUint32

func (b *Buffer) WriteUint32(v uint32)

WriteUint32 writes given uint32 value to the buffer and advances cursor by 4.

Jump to

Keyboard shortcuts

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