buffer

package
v0.0.0-...-101e1e6 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2021 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package buffer is a bytes buffer. The ringBuffer is implements Buffer interface by a ring loop bytes buffer.

Index

Constants

View Source
const DefaultBufferCapacity = 4096

DefaultBufferCapacity is default buffer Capacity

Variables

View Source
var ErrBufferCapacityNotEnough = errors.New("buffer capacity is not enough")

ErrBufferCapacityNotEnough is defined error of buffer full When write bytes to buffer and buffer remain space not enough this error will throw.

Functions

func NewBuffer

func NewBuffer(capacity int) *ringBuffer

NewBuffer will create buffer of capacity

Types

type Buffer

type Buffer interface {
	// NextN is get next n bytes in buffer
	// This method will return count and next bytes.
	// This method not move bytes pointer.
	NextN(n int) (int, []byte)
	// ShiftN is move bytes pointer forward
	ShiftN(n int) int
	// ReadN is get next bytes in buffer and move bytes pointer forward.
	ReadN(n int) (int, []byte)
	// Size will return bytes length in buffer
	Size() int
	// Capacity will return the buffer capacity
	Capacity() int
	// Write will write bytes to buffer
	// When buffer full will throw ErrBufferCapacityNotEnough error
	Write(p []byte) (int, error)
	// Reset will reset the buffer
	Reset()
	// Bytes will return all bytes in buffer
	Bytes() []byte
}

Buffer is bytes buffer interface

type Pool

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

Pool is buffer pool

func NewPool

func NewPool(bufferCapacity int) *Pool

NewPool will get a Buffer pool

func (*Pool) Get

func (p *Pool) Get() Buffer

Get is get Buffer from pool

func (*Pool) Put

func (p *Pool) Put(buf Buffer)

Put is put Buffer to pool

Jump to

Keyboard shortcuts

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