buffer

package
v2.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 29, 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 获取字节长度
	Len() int
	// Nodes 获取节点数
	Nodes() int
	// Delay 设置延迟释放点
	Delay(delay int)
	// Bytes 获取所有字节(性能较低,不推荐使用)
	Bytes() []byte
	// Release 释放
	Release()
	// Slide 滑动lower索引
	Slide(lower int) bool
	// VisitBytes 迭代所有字节
	VisitBytes(fn func(bytes []byte) bool) bool
}

type Bytes added in v2.4.0

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

Bytes 字节缓冲

func MallocBytes added in v2.4.0

func MallocBytes(cap int) *Bytes

MallocBytes 从字节池分配字节

func NewBytes added in v2.4.0

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

NewBytes 以指定buf创建字节

func NewBytesWithCapacity added in v2.4.0

func NewBytesWithCapacity(cap int) *Bytes

NewBytesWithCapacity 以指定容量创建字节

func (*Bytes) Available added in v2.4.0

func (b *Bytes) Available() int

Available 返回可用空间

func (*Bytes) Bytes added in v2.4.0

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

Bytes 获取字节数据

func (*Bytes) Cap added in v2.4.0

func (b *Bytes) Cap() int

Cap 返回容量

func (*Bytes) Delay added in v2.6.0

func (b *Bytes) Delay(delay int)

Delay 设置延迟释放点

func (*Bytes) Len added in v2.4.0

func (b *Bytes) Len() int

Len 返回数据长度

func (*Bytes) Nodes added in v2.6.0

func (b *Bytes) Nodes() int

Nodes 获取节点数

func (*Bytes) Release added in v2.4.0

func (b *Bytes) Release()

Release 释放

func (*Bytes) Slide added in v2.6.0

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

Slide 滑动lower索引

func (*Bytes) VisitBytes added in v2.6.0

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

VisitBytes 迭代所有字节

type BytesPool added in v2.4.0

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

BytesPool 字节缓冲池

func NewBytesPool added in v2.4.0

func NewBytesPool(grade int) *BytesPool

NewBytesPool 分级创建字节池

func NewBytesPoolWithCapacity added in v2.4.0

func NewBytesPoolWithCapacity(cap int) *BytesPool

NewBytesPoolWithCapacity 以指定容量创建字节池

func (*BytesPool) Get added in v2.4.0

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

Get 获取

type NocopyBuffer

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

NocopyBuffer 零拷贝缓冲区

func NewNocopyBuffer

func NewNocopyBuffer(blocks ...any) *NocopyBuffer

NewNocopyBuffer 创建零拷贝缓冲区

func (*NocopyBuffer) Bytes

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

Bytes 获取字节

func (*NocopyBuffer) Delay added in v2.3.0

func (b *NocopyBuffer) Delay(delay int)

Delay 设置延迟释放点

func (*NocopyBuffer) Len

func (b *NocopyBuffer) Len() int

Len 获取字节长度

func (*NocopyBuffer) MallocBytes added in v2.4.0

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

MallocBytes 分配一块内存给Bytes

func (*NocopyBuffer) MallocWriter added in v2.4.0

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

MallocWriter 分配一块内存给Writer

func (*NocopyBuffer) Mount

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

Mount 挂载块到Buffer上

func (*NocopyBuffer) Nodes

func (b *NocopyBuffer) Nodes() int

Nodes 获取节点数

func (*NocopyBuffer) Release

func (b *NocopyBuffer) Release()

Release 释放

func (*NocopyBuffer) Slide added in v2.6.0

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

Slide 滑动lower索引

func (*NocopyBuffer) VisitBytes added in v2.6.0

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

VisitBytes 迭代所有字节

func (*NocopyBuffer) VisitNodes added in v2.6.0

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

VisitNodes 迭代所有节点

type NocopyNode

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

NocopyNode 零拷贝缓冲区节点

func (*NocopyNode) Bytes

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

Bytes 获取该节点的字节数据

func (*NocopyNode) Len

func (n *NocopyNode) Len() int

Len 获取字节长度

func (*NocopyNode) Nodes added in v2.6.0

func (n *NocopyNode) Nodes() int

Nodes 获取节点数

func (*NocopyNode) Release

func (n *NocopyNode) Release()

Release 释放

func (*NocopyNode) Slide added in v2.6.0

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

Slide 消费指定字节数

type Reader

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

Reader 字节读取器

func NewReader

func NewReader(data []byte) *Reader

NewReader 以指定数据创建读取器

func (*Reader) ReadBool

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

ReadBool 读取bool值

func (*Reader) ReadBools

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

ReadBools 读取多个bool值

func (*Reader) ReadByte

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

ReadByte 读取byte值

func (*Reader) ReadBytes

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

ReadBytes 读取多个byte值

func (*Reader) ReadFloat32

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

ReadFloat32 读取float32值

func (*Reader) ReadFloat32s

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

ReadFloat32s 读取多个float32值

func (*Reader) ReadFloat64

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

ReadFloat64 读取float64值

func (*Reader) ReadFloat64s

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

ReadFloat64s 读取多个float64值

func (*Reader) ReadInt8

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

ReadInt8 读取int8值

func (*Reader) ReadInt8s

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

ReadInt8s 读取多个int8值

func (*Reader) ReadInt16

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

ReadInt16 读取int16值

func (*Reader) ReadInt16s

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

ReadInt16s 读取多个int16值

func (*Reader) ReadInt32

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

ReadInt32 读取int32值

func (*Reader) ReadInt32s

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

ReadInt32s 读取多个int32值

func (*Reader) ReadInt64

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

ReadInt64 读取int64值

func (*Reader) ReadInt64s

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

ReadInt64s 读取多个int64值

func (*Reader) ReadRune

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

ReadRune 读取rune值

func (*Reader) ReadRunes

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

ReadRunes 读取多个rune值

func (*Reader) ReadString

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

ReadString 读取string值

func (*Reader) ReadUint8

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

ReadUint8 读取uint8值

func (*Reader) ReadUint8s

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

ReadUint8s 读取多个uint8值

func (*Reader) ReadUint16

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

ReadUint16 读取uint16值

func (*Reader) ReadUint16s

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

ReadUint16s 读取多个uint16值

func (*Reader) ReadUint32

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

ReadUint32 读取uint32值

func (*Reader) ReadUint32s

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

ReadUint32s 读取多个uint32值

func (*Reader) ReadUint64

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

ReadUint64 读取uint64值

func (*Reader) ReadUint64s

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

ReadUint64s 读取多个uint64值

func (*Reader) Reset

func (r *Reader) Reset()

Reset 重置

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 指定节点挂载位置

const (
	// Head 头部
	Head Whence = iota
	// Tail 尾部
	Tail
)

type Writer

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

Writer 字节写入器

func MallocWriter added in v2.4.0

func MallocWriter(cap int) *Writer

MallocWriter 分配一块内存给Writer

func NewWriter

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

NewWriter 以指定buf创建写入器

func NewWriterWithCapacity added in v2.4.0

func NewWriterWithCapacity(cap ...int) *Writer

NewWriterWithCapacity 以指定容量创建写入器

func (*Writer) Available

func (w *Writer) Available() int

Available 返回可用空间

func (*Writer) Bytes

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

Bytes 获取字节数据

func (*Writer) Cap

func (w *Writer) Cap() int

Cap 返回容量

func (*Writer) Delay added in v2.6.0

func (w *Writer) Delay(delay int)

Delay 设置延迟释放点

func (*Writer) Grow

func (w *Writer) Grow(n int)

Grow 增长空间

func (*Writer) Len

func (w *Writer) Len() int

Len 返回数据长度

func (*Writer) Nodes added in v2.6.0

func (w *Writer) Nodes() int

Nodes 获取节点数

func (*Writer) Release added in v2.4.0

func (w *Writer) Release()

Release 释放

func (*Writer) Slide added in v2.6.0

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

Slide 滑动lower索引

func (*Writer) VisitBytes added in v2.6.0

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

VisitBytes 迭代所有字节

func (*Writer) Write

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

Write 写数据,实现io.Writer接口

func (*Writer) WriteBools

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

WriteBools 写入bool值

func (*Writer) WriteBytes

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

WriteBytes 写入字节序

func (*Writer) WriteFloat32s

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

WriteFloat32s 写入float32

func (*Writer) WriteFloat64s

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

WriteFloat64s 写入float64

func (*Writer) WriteInt8s

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

WriteInt8s 写入int8

func (*Writer) WriteInt16s

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

WriteInt16s 写入int16

func (*Writer) WriteInt32s

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

WriteInt32s 写入int32

func (*Writer) WriteInt64s

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

WriteInt64s 写入int64

func (*Writer) WriteRunes

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

WriteRunes 写入rune

func (*Writer) WriteString

func (w *Writer) WriteString(str string)

WriteString 写入字符串

func (*Writer) WriteUint8s

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

WriteUint8s 写入uint8

func (*Writer) WriteUint16s

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

WriteUint16s 写入uint16

func (*Writer) WriteUint32s

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

WriteUint32s 写入uint32

func (*Writer) WriteUint64s

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

WriteUint64s 写入uint64

type WriterPool

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

WriterPool 写入器池

func NewWriterPool

func NewWriterPool(grade int) *WriterPool

NewWriterPool 分级创建写入器池

func NewWriterPoolWithCapacity added in v2.4.0

func NewWriterPoolWithCapacity(cap int) *WriterPool

NewWriterPoolWithCapacity 以指定容量创建写入器池

func (*WriterPool) Get

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

Get 获取

Jump to

Keyboard shortcuts

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