Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrTooLarge = errors.New("bytebuffers.Buffer: too large") ErrWriteWhenBorrowing = errors.New("bytebuffers.Buffer: cannot write when borrowing, cause prev borrowed was not return, please call Return() after the area was used") ErrBorrowZero = errors.New("bytebuffers.Buffer: cannot borrow zero") )
Functions ¶
Types ¶
type Buffer ¶
type Buffer interface {
// Len
// 长度
Len() (n int)
// Capacity
// 容量
Capacity() (n int)
// CapacityHint
// 容量提示
CapacityHint() (hint int)
// Peek
// 查看 n 个字节,但不会读掉。
Peek(n int) (p []byte)
// Next
// 取后 n 个
Next(n int) (p []byte, err error)
// Discard
// 丢弃
Discard(n int)
// Read
// 读取
Read(p []byte) (n int, err error)
// ReadByte
// 读取一个字节
ReadByte() (b byte, err error)
// ReadBytes
// 以 delim 读
ReadBytes(delim byte) (line []byte, err error)
// Index
// 标号
Index(delim byte) (i int)
// Write
// 写入
Write(p []byte) (n int, err error)
// WriteByte
// 写入字节
WriteByte(c byte) (err error)
// WriteString
// 写入字符串
WriteString(s string) (n int, err error)
// Set
// 重写入可读字节
Set(p []byte) (err error)
// SetString
// 重写入可读字符串
SetString(s string) (err error)
// ReadFrom
// 从一流里读取全部
ReadFrom(r io.Reader) (n int64, err error)
// ReadFromWithHint
// 以 hint 大小从一流里读取全部
ReadFromWithHint(r io.Reader, hint int) (n int64, err error)
// ReadFromLimited
// 从一流里读取 n 个字节
ReadFromLimited(r io.Reader, n int) (nn int, err error)
// WriteTo
// 全部写入一个流
WriteTo(w io.Writer) (n int64, err error)
// WriteToLimited
// 把 n 个字节写入一个流
WriteToLimited(w io.Writer, n int) (nn int, err error)
// CloneBytes
// 复制字节,非读操作。
CloneBytes() []byte
// Borrow
// 借出
Borrow(size int) (p []byte, err error)
// Return
// 归还借出的实际使用量
Return(used int)
// Borrowing
// 是否有借出
Borrowing() bool
// Reset
// 重置,当 Borrowing 时,无法重置。
Reset() bool
}
func NewBufferWithCapacityHint ¶ added in v1.2.0
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
func Pool ¶ added in v1.3.1
func Pool(hint int) BufferPool
Pool 创建一个缓冲池。
参数 hint 为 缓冲的基准容量,最大为 page size。
func (*BufferPool) Acquire ¶
func (p *BufferPool) Acquire() Buffer
func (*BufferPool) Release ¶
func (p *BufferPool) Release(b Buffer)
Click to show internal directories.
Click to hide internal directories.