ringbytes

package
v0.43.9 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTooManyToWrite 内容太长,无法写入
	ErrTooManyToWrite = errors.New("too many data to write")
	// ErrInvalidBuffer 用于读取的 buffer 无效
	ErrInvalidBuffer = errors.New("invalid buffer")
	// ErrNotEnough 数据不足以读取长度 n 的内容
	ErrNotEnough = errors.New("not enough data")
	// ErrInvalidSkipSize 无效的长度
	ErrInvalidSkipSize = errors.New("invalid skip size")
	// ErrIsFull 缓冲区已满
	ErrIsFull = errors.New("buffer is full")
	// ErrIsEmpty 缓冲区已满
	ErrIsEmpty = errors.New("buffer is empty")
	// ErrInvalidLength 无效长度
	ErrInvalidLength = errors.New("invalid length")
)

Functions

This section is empty.

Types

type RingBytes

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

RingBytes 环形缓冲区,无锁版本,线程不安全

func New

func New(size int) *RingBytes

NewUnlock 创建环形结构,无锁版本,线程不安全

func (*RingBytes) Cap

func (r *RingBytes) Cap() int

Cap 容量

func (*RingBytes) Free

func (r *RingBytes) Free() int

Free 剩余空间

func (*RingBytes) IsEmpty

func (r *RingBytes) IsEmpty() bool

IsEmpty 缓冲区是否为空,没有任何数据可读

func (*RingBytes) IsFull

func (r *RingBytes) IsFull() bool

IsFull 缓冲区是否已满,不可以继续写入任何数据

func (*RingBytes) Len

func (r *RingBytes) Len() int

Len 存储的有效数据长度

func (*RingBytes) Peek

func (r *RingBytes) Peek(n int) ([]byte, error)

Peek 读取 n 个长度的内容,但不会产生任何影响 不会改变 r.read 和 r.write

func (*RingBytes) Read

func (r *RingBytes) Read(n int) ([]byte, error)

Read 获取缓冲中的数据

func (*RingBytes) Reset

func (r *RingBytes) Reset()

Reset 重置

func (*RingBytes) Skip

func (r *RingBytes) Skip(n int) error

Skip 跳过 n 个字段,会改变 r.read

func (*RingBytes) String

func (r *RingBytes) String() string

func (*RingBytes) Write

func (r *RingBytes) Write(p []byte) (int, error)

Write 写入数据

只有全部写入,或者都不写入两种情况,不存在只写入一部分的情形

func (*RingBytes) WriteN

func (r *RingBytes) WriteN(p []byte, n int) error

WriteN 从 p 中取出长度 n 的数据写入 只有全部写入,或者都不写入两种情况,不存在只写入一部分的情形 当剩余空间不足时,写入失败

Jump to

Keyboard shortcuts

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