buffer

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Byte = 1 << (iota * 10)
	KiByte
	MiByte
	GiByte
)

Variables

This section is empty.

Functions

This section is empty.

Types

type RingBuffer

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

RingBuffer an efficient, automatically resizable, and memory-reusable circular buffer implementation.

func NewRingBuffer

func NewRingBuffer() *RingBuffer

NewRingBuffer returns a default 64 kb size circular buffer.

func NewRingBufferWithCap

func NewRingBufferWithCap(cap int) *RingBuffer

NewRingBufferWithCap returns a cap byte size circular buffer.

func (*RingBuffer) Bytes

func (r *RingBuffer) Bytes() []byte

Bytes return all data in ringBuffer.

func (*RingBuffer) Cap

func (r *RingBuffer) Cap() int

Cap return the ringBuffer capacity.

func (*RingBuffer) Clear

func (r *RingBuffer) Clear()

Clear up the ringBuffer.

func (*RingBuffer) CopyFromFd

func (r *RingBuffer) CopyFromFd(fd int) (int, error)

CopyFromFd read data from fd to ringBuffer. an err is returned when the ringBuffer gets data from the network and encounters a non-retryable error.

func (*RingBuffer) IsEmpty

func (r *RingBuffer) IsEmpty() bool

IsEmpty return true if ringBuffer is empty.

func (*RingBuffer) Len

func (r *RingBuffer) Len() int

Len returns the number of readable bytes of the ring Buffer.

func (*RingBuffer) Read

func (r *RingBuffer) Read(p []byte) (int, error)

Read max len(p) of data to p, returning a BufferEmptyErr error if the buffer is empty.

func (*RingBuffer) Release

func (r *RingBuffer) Release(n int)

Release maximum n bytes of data in ringBuffer.

func (*RingBuffer) Write

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

Write max len(p) of data to ringBuffer, returning a BufferFullErr error if the buffer is full.

func (*RingBuffer) WriteString

func (r *RingBuffer) WriteString(s string) (int, error)

WriteString write string into ringBuffer.

func (*RingBuffer) WriteToFd

func (r *RingBuffer) WriteToFd(fd int) (int, error)

WriteToFd write the ring Buffer data to the network. an err is returned when the ringBuffer write data to the network and encounters a non-retryable error.

Jump to

Keyboard shortcuts

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