buffer

package
v2.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer interface {
	// Len returns the byte length.
	Len() int
	// Nodes returns the number of nodes.
	Nodes() int
	// Delay sets the delayed release point.
	Delay(delay int)
	// Bytes returns all bytes. It is relatively slow and not recommended.
	Bytes() []byte
	// Release releases the buffer.
	Release()
	// Slide slides the lower index.
	Slide(lower int) bool
	// VisitBytes iterates over all bytes.
	VisitBytes(fn func(bytes []byte) bool) bool
}

type Bytes added in v2.4.0

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

Bytes is a byte buffer.

func MallocBytes added in v2.4.0

func MallocBytes(cap int) *Bytes

MallocBytes allocates a Bytes with the given capacity from the default byte pool.

func NewBytes added in v2.4.0

func NewBytes(buf []byte, static ...bool) *Bytes

NewBytes creates a Bytes over buf. When static is true, the buffer is not returned to the pool on release.

func NewBytesWithCapacity added in v2.4.0

func NewBytesWithCapacity(cap int) *Bytes

NewBytesWithCapacity creates a Bytes with the given capacity.

func (*Bytes) Available added in v2.4.0

func (b *Bytes) Available() int

Available returns the available space.

func (*Bytes) Bytes added in v2.4.0

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

Bytes returns the byte data.

func (*Bytes) Cap added in v2.4.0

func (b *Bytes) Cap() int

Cap returns the capacity.

func (*Bytes) Delay added in v2.6.0

func (b *Bytes) Delay(delay int)

Delay sets the delayed release point.

func (*Bytes) Len added in v2.4.0

func (b *Bytes) Len() int

Len returns the data length.

func (*Bytes) Nodes added in v2.6.0

func (b *Bytes) Nodes() int

Nodes returns the number of nodes.

func (*Bytes) Release added in v2.4.0

func (b *Bytes) Release()

Release releases the buffer.

func (*Bytes) Slide added in v2.6.0

func (b *Bytes) Slide(delta int) bool

Slide slides the lower index.

func (*Bytes) VisitBytes added in v2.6.0

func (b *Bytes) VisitBytes(fn func(bytes []byte) bool) bool

VisitBytes iterates over all bytes.

type BytesPool added in v2.4.0

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

BytesPool is a byte buffer pool.

func NewBytesPool added in v2.4.0

func NewBytesPool(grade int) *BytesPool

NewBytesPool creates a byte pool with the given number of grades.

func NewBytesPoolWithCapacity added in v2.4.0

func NewBytesPoolWithCapacity(cap int) *BytesPool

NewBytesPoolWithCapacity creates a byte pool whose maximum capacity fits cap.

func (*BytesPool) Get added in v2.4.0

func (p *BytesPool) Get(cap int) *Bytes

Get returns a Bytes with the given capacity, or nil when no matching pool exists.

type NocopyBuffer

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

NocopyBuffer is a zero-copy buffer.

func NewNocopyBuffer

func NewNocopyBuffer(blocks ...any) *NocopyBuffer

NewNocopyBuffer creates a zero-copy buffer mounting the given blocks.

func (*NocopyBuffer) Bytes

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

Bytes returns all bytes.

func (*NocopyBuffer) Delay added in v2.3.0

func (b *NocopyBuffer) Delay(delay int)

Delay sets the delayed release point.

func (*NocopyBuffer) Len

func (b *NocopyBuffer) Len() int

Len returns the byte length.

func (*NocopyBuffer) MallocBytes added in v2.4.0

func (b *NocopyBuffer) MallocBytes(cap int, whence ...Whence) *Bytes

MallocBytes allocates a Bytes with the given capacity and mounts it.

func (*NocopyBuffer) MallocWriter added in v2.4.0

func (b *NocopyBuffer) MallocWriter(cap int, whence ...Whence) *Writer

MallocWriter allocates a Writer with the given capacity and mounts it.

func (*NocopyBuffer) Mount

func (b *NocopyBuffer) Mount(block any, whence ...Whence)

Mount mounts block onto the buffer, at the head or tail according to whence.

func (*NocopyBuffer) Nodes

func (b *NocopyBuffer) Nodes() int

Nodes returns the number of nodes.

func (*NocopyBuffer) Release

func (b *NocopyBuffer) Release()

Release releases the buffer.

func (*NocopyBuffer) Slide added in v2.6.0

func (b *NocopyBuffer) Slide(delta int) bool

Slide slides the lower index.

func (*NocopyBuffer) VisitBytes added in v2.6.0

func (b *NocopyBuffer) VisitBytes(fn func(bytes []byte) bool) bool

VisitBytes iterates over all bytes.

func (*NocopyBuffer) VisitNodes added in v2.6.0

func (b *NocopyBuffer) VisitNodes(fn func(node *NocopyNode) bool) bool

VisitNodes iterates over all nodes.

type NocopyNode

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

NocopyNode is a zero-copy buffer node.

func (*NocopyNode) Bytes

func (n *NocopyNode) Bytes() []byte

Bytes returns the byte data of the node.

func (*NocopyNode) Len

func (n *NocopyNode) Len() int

Len returns the byte length.

func (*NocopyNode) Nodes added in v2.6.0

func (n *NocopyNode) Nodes() int

Nodes returns the number of nodes.

func (*NocopyNode) Release

func (n *NocopyNode) Release()

Release releases the node.

func (*NocopyNode) Slide added in v2.6.0

func (n *NocopyNode) Slide(delta int) bool

Slide consumes the given number of bytes.

type Reader

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

Reader is a byte reader.

func NewReader

func NewReader(data []byte) *Reader

NewReader creates a Reader over data.

func (*Reader) ReadBool

func (r *Reader) ReadBool() (bool, error)

ReadBool reads a bool value.

func (*Reader) ReadBools

func (r *Reader) ReadBools(n int) ([]bool, error)

ReadBools reads n bool values.

func (*Reader) ReadByte

func (r *Reader) ReadByte() (byte, error)

ReadByte reads a byte value.

func (*Reader) ReadBytes

func (r *Reader) ReadBytes(n int) ([]byte, error)

ReadBytes reads n bytes.

func (*Reader) ReadFloat32

func (r *Reader) ReadFloat32(order binary.ByteOrder) (float32, error)

ReadFloat32 reads a float32 value using order.

func (*Reader) ReadFloat32s

func (r *Reader) ReadFloat32s(order binary.ByteOrder, n int) ([]float32, error)

ReadFloat32s reads n float32 values using order.

func (*Reader) ReadFloat64

func (r *Reader) ReadFloat64(order binary.ByteOrder) (float64, error)

ReadFloat64 reads a float64 value using order.

func (*Reader) ReadFloat64s

func (r *Reader) ReadFloat64s(order binary.ByteOrder, n int) ([]float64, error)

ReadFloat64s reads n float64 values using order.

func (*Reader) ReadInt8

func (r *Reader) ReadInt8() (int8, error)

ReadInt8 reads an int8 value.

func (*Reader) ReadInt8s

func (r *Reader) ReadInt8s(n int) ([]int8, error)

ReadInt8s reads n int8 values.

func (*Reader) ReadInt16

func (r *Reader) ReadInt16(order binary.ByteOrder) (int16, error)

ReadInt16 reads an int16 value using order.

func (*Reader) ReadInt16s

func (r *Reader) ReadInt16s(order binary.ByteOrder, n int) ([]int16, error)

ReadInt16s reads n int16 values using order.

func (*Reader) ReadInt32

func (r *Reader) ReadInt32(order binary.ByteOrder) (int32, error)

ReadInt32 reads an int32 value using order.

func (*Reader) ReadInt32s

func (r *Reader) ReadInt32s(order binary.ByteOrder, n int) ([]int32, error)

ReadInt32s reads n int32 values using order.

func (*Reader) ReadInt64

func (r *Reader) ReadInt64(order binary.ByteOrder) (int64, error)

ReadInt64 reads an int64 value using order.

func (*Reader) ReadInt64s

func (r *Reader) ReadInt64s(order binary.ByteOrder, n int) ([]int64, error)

ReadInt64s reads n int64 values using order.

func (*Reader) ReadRune

func (r *Reader) ReadRune(order binary.ByteOrder) (rune, error)

ReadRune reads a rune value using order.

func (*Reader) ReadRunes

func (r *Reader) ReadRunes(order binary.ByteOrder, n int) ([]rune, error)

ReadRunes reads n rune values using order.

func (*Reader) ReadString

func (r *Reader) ReadString(len int) (string, error)

ReadString reads a string of the given length.

func (*Reader) ReadUint8

func (r *Reader) ReadUint8() (uint8, error)

ReadUint8 reads a uint8 value.

func (*Reader) ReadUint8s

func (r *Reader) ReadUint8s(n int) ([]uint8, error)

ReadUint8s reads n uint8 values.

func (*Reader) ReadUint16

func (r *Reader) ReadUint16(order binary.ByteOrder) (uint16, error)

ReadUint16 reads a uint16 value using order.

func (*Reader) ReadUint16s

func (r *Reader) ReadUint16s(order binary.ByteOrder, n int) ([]uint16, error)

ReadUint16s reads n uint16 values using order.

func (*Reader) ReadUint32

func (r *Reader) ReadUint32(order binary.ByteOrder) (uint32, error)

ReadUint32 reads a uint32 value using order.

func (*Reader) ReadUint32s

func (r *Reader) ReadUint32s(order binary.ByteOrder, n int) ([]uint32, error)

ReadUint32s reads n uint32 values using order.

func (*Reader) ReadUint64

func (r *Reader) ReadUint64(order binary.ByteOrder) (uint64, error)

ReadUint64 reads a uint64 value using order.

func (*Reader) ReadUint64s

func (r *Reader) ReadUint64s(order binary.ByteOrder, n int) ([]uint64, error)

ReadUint64s reads n uint64 values using order.

func (*Reader) Reset

func (r *Reader) Reset()

Reset resets the read offset to zero.

func (*Reader) Seek

func (r *Reader) Seek(offset int64, whence int) (int64, error)

Seek implements the io.Seeker interface.

type Whence

type Whence int

Whence specifies where a node is mounted.

const (
	// Head mounts the node at the head.
	Head Whence = iota
	// Tail mounts the node at the tail.
	Tail
)

type Writer

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

Writer is a byte writer.

func MallocWriter added in v2.4.0

func MallocWriter(cap int) *Writer

MallocWriter allocates a Writer with the given capacity from the default writer pool.

func NewWriter

func NewWriter(buf []byte, static ...bool) *Writer

NewWriter creates a Writer over buf. When static is true, the writer is not returned to the pool on release.

func NewWriterWithCapacity added in v2.4.0

func NewWriterWithCapacity(cap ...int) *Writer

NewWriterWithCapacity creates a Writer with the given capacity.

func (*Writer) Available

func (w *Writer) Available() int

Available returns the available space.

func (*Writer) Bytes

func (w *Writer) Bytes() []byte

Bytes returns the byte data.

func (*Writer) Cap

func (w *Writer) Cap() int

Cap returns the capacity.

func (*Writer) Delay added in v2.6.0

func (w *Writer) Delay(delay int)

Delay sets the delayed release point.

func (*Writer) Grow

func (w *Writer) Grow(n int)

Grow grows the available space by n bytes.

func (*Writer) Len

func (w *Writer) Len() int

Len returns the data length.

func (*Writer) Nodes added in v2.6.0

func (w *Writer) Nodes() int

Nodes returns the number of nodes.

func (*Writer) Release added in v2.4.0

func (w *Writer) Release()

Release releases the writer.

func (*Writer) Slide added in v2.6.0

func (w *Writer) Slide(delta int) bool

Slide slides the lower index.

func (*Writer) VisitBytes added in v2.6.0

func (w *Writer) VisitBytes(fn func(bytes []byte) bool) bool

VisitBytes iterates over all bytes.

func (*Writer) Write

func (w *Writer) Write(p []byte) (n int, err error)

Write appends p and implements io.Writer.

func (*Writer) WriteBools

func (w *Writer) WriteBools(values ...bool)

WriteBools writes the given bool values.

func (*Writer) WriteBytes

func (w *Writer) WriteBytes(values ...byte)

WriteBytes writes the given bytes.

func (*Writer) WriteFloat32s

func (w *Writer) WriteFloat32s(order binary.ByteOrder, values ...float32)

WriteFloat32s writes the given float32 values using order.

func (*Writer) WriteFloat64s

func (w *Writer) WriteFloat64s(order binary.ByteOrder, values ...float64)

WriteFloat64s writes the given float64 values using order.

func (*Writer) WriteInt8s

func (w *Writer) WriteInt8s(values ...int8)

WriteInt8s writes the given int8 values.

func (*Writer) WriteInt16s

func (w *Writer) WriteInt16s(order binary.ByteOrder, values ...int16)

WriteInt16s writes the given int16 values using order.

func (*Writer) WriteInt32s

func (w *Writer) WriteInt32s(order binary.ByteOrder, values ...int32)

WriteInt32s writes the given int32 values using order.

func (*Writer) WriteInt64s

func (w *Writer) WriteInt64s(order binary.ByteOrder, values ...int64)

WriteInt64s writes the given int64 values using order.

func (*Writer) WriteRunes

func (w *Writer) WriteRunes(order binary.ByteOrder, values ...rune)

WriteRunes writes the given rune values using order.

func (*Writer) WriteString

func (w *Writer) WriteString(str string)

WriteString writes str.

func (*Writer) WriteUint8s

func (w *Writer) WriteUint8s(values ...uint8)

WriteUint8s writes the given uint8 values.

func (*Writer) WriteUint16s

func (w *Writer) WriteUint16s(order binary.ByteOrder, values ...uint16)

WriteUint16s writes the given uint16 values using order.

func (*Writer) WriteUint32s

func (w *Writer) WriteUint32s(order binary.ByteOrder, values ...uint32)

WriteUint32s writes the given uint32 values using order.

func (*Writer) WriteUint64s

func (w *Writer) WriteUint64s(order binary.ByteOrder, values ...uint64)

WriteUint64s writes the given uint64 values using order.

type WriterPool

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

WriterPool is a byte writer pool.

func NewWriterPool

func NewWriterPool(grade int) *WriterPool

NewWriterPool creates a writer pool with the given number of grades.

func NewWriterPoolWithCapacity added in v2.4.0

func NewWriterPoolWithCapacity(cap int) *WriterPool

NewWriterPoolWithCapacity creates a writer pool whose maximum capacity fits cap.

func (*WriterPool) Get

func (p *WriterPool) Get(cap int) *Writer

Get returns a Writer with the given capacity, or nil when no matching pool exists.

Jump to

Keyboard shortcuts

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