util

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NonPrimitiveTypeError error = errors.New("Type provided to read/write does not fit inside 8 bytes.")

NonPrimitiveTypeError represents an error where the user provided a non-primitive data type for reading/writing

Functions

This section is empty.

Types

type Buffer

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

Buffer is a utility type which implements a very basic binary protocol for writing core go types.

func NewBuffer

func NewBuffer() *Buffer

NewBuffer creates a new Buffer instance using LittleEndian ByteOrder.

func NewBufferFrom

func NewBufferFrom(b *Buffer) *Buffer

NewBufferFrom creates a new Buffer instance using the remaining unread data from the provided Buffer instance. The new buffer assumes ownership of the underlying data.

func NewBufferFromBytes

func NewBufferFromBytes(b []byte) *Buffer

NewBufferFromBytes creates a new Buffer instance using the provided byte slice. The new buffer assumes ownership of the byte slice.

func NewBufferFromReader

func NewBufferFromReader(reader io.Reader) *Buffer

NewBufferFromReader creates a new Buffer instance using the provided io.Reader. This buffer is set to read-only.

func (*Buffer) Bytes

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

Bytes returns the unread portion of the underlying buffer storage. If the buffer was created with an `io.Reader`, then the remaining unread bytes are drained into a byte slice and returned.

func (*Buffer) Peek

func (b *Buffer) Peek(length int) ([]byte, error)

func (*Buffer) ReadBool

func (b *Buffer) ReadBool() bool

ReadBool reads a bool value from the buffer.

func (*Buffer) ReadBytes

func (b *Buffer) ReadBytes(length int) []byte

ReadBytes reads the specified length from the buffer and returns the byte slice.

func (*Buffer) ReadFloat32

func (b *Buffer) ReadFloat32() float32

ReadFloat32 reads a float32 value from the buffer.

func (*Buffer) ReadFloat64

func (b *Buffer) ReadFloat64() float64

ReadFloat64 reads a float64 value from the buffer.

func (*Buffer) ReadInt

func (b *Buffer) ReadInt() int

ReadInt reads an int value from the buffer.

func (*Buffer) ReadInt8

func (b *Buffer) ReadInt8() int8

ReadInt8 reads an int8 value from the buffer.

func (*Buffer) ReadInt16

func (b *Buffer) ReadInt16() int16

ReadInt16 reads an int16 value from the buffer.

func (*Buffer) ReadInt32

func (b *Buffer) ReadInt32() int32

ReadInt32 reads an int32 value from the buffer.

func (*Buffer) ReadInt64

func (b *Buffer) ReadInt64() int64

ReadInt64 reads an int64 value from the buffer.

func (*Buffer) ReadString

func (b *Buffer) ReadString() string

ReadString reads a uint16 value from the buffer representing the string's length, then uses the length to extract the exact length []byte representing the string.

func (*Buffer) ReadUInt

func (b *Buffer) ReadUInt() uint

ReadUInt reads a uint value from the buffer.

func (*Buffer) ReadUInt8

func (b *Buffer) ReadUInt8() uint8

ReadUInt8 reads a uint8 value from the buffer.

func (*Buffer) ReadUInt16

func (b *Buffer) ReadUInt16() uint16

ReadUInt16 reads a uint16 value from the buffer.

func (*Buffer) ReadUInt32

func (b *Buffer) ReadUInt32() uint32

ReadUInt32 reads a uint32 value from the buffer.

func (*Buffer) ReadUInt64

func (b *Buffer) ReadUInt64() uint64

ReadUInt64 reads a uint64 value from the buffer.

func (*Buffer) WriteBool

func (b *Buffer) WriteBool(i bool)

WriteBool writes a bool value to the buffer

func (*Buffer) WriteBytes

func (b *Buffer) WriteBytes(bytes []byte)

WriteBytes writes the contents of the byte slice to the buffer.

func (*Buffer) WriteFloat32

func (b *Buffer) WriteFloat32(i float32)

WriteFloat32 writes a float32 value to the buffer.

func (*Buffer) WriteFloat64

func (b *Buffer) WriteFloat64(i float64)

WriteFloat64 writes a float64 value to the buffer.

func (*Buffer) WriteInt

func (b *Buffer) WriteInt(i int)

WriteInt writes an int value to the buffer.

func (*Buffer) WriteInt8

func (b *Buffer) WriteInt8(i int8)

WriteInt8 writes an int8 value to the buffer.

func (*Buffer) WriteInt16

func (b *Buffer) WriteInt16(i int16)

WriteInt16 writes an int16 value to the buffer.

func (*Buffer) WriteInt32

func (b *Buffer) WriteInt32(i int32)

WriteInt32 writes an int32 value to the buffer.

func (*Buffer) WriteInt64

func (b *Buffer) WriteInt64(i int64)

WriteInt64 writes an int64 value to the buffer.

func (*Buffer) WriteString

func (b *Buffer) WriteString(i string)

WriteString writes the string's length as a uint16 followed by the string contents.

func (*Buffer) WriteUInt

func (b *Buffer) WriteUInt(i uint)

WriteUInt writes a uint value to the buffer.

func (*Buffer) WriteUInt8

func (b *Buffer) WriteUInt8(i uint8)

WriteUInt8 writes a uint8 value to the buffer.

func (*Buffer) WriteUInt16

func (b *Buffer) WriteUInt16(i uint16)

WriteUInt16 writes a uint16 value to the buffer.

func (*Buffer) WriteUInt32

func (b *Buffer) WriteUInt32(i uint32)

WriteUInt32 writes a uint32 value to the buffer.

func (*Buffer) WriteUInt64

func (b *Buffer) WriteUInt64(i uint64)

WriteUInt64 writes a uint64 value to the buffer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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