ringbuffer

package
v1.19.2 Latest Latest
Warning

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

Go to latest
Published: May 21, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIsFull  = errors.New("ringbuffer is full")
	ErrIsEmpty = errors.New("ringbuffer is empty")
)

Functions

This section is empty.

Types

type Buffer

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

Buffer is a circular buffer that implement io.ReaderWriter interface.

func New

func New(size int) *Buffer

New returns a new Buffer whose buffer has the given size.

func (*Buffer) Capacity

func (r *Buffer) Capacity() int

Capacity returns the size of the underlying buffer.

func (*Buffer) Free

func (r *Buffer) Free() int

Free returns the length of available bytes to write.

func (*Buffer) IsEmpty

func (r *Buffer) IsEmpty() bool

IsEmpty returns this ringbuffer is empty.

func (*Buffer) IsFull

func (r *Buffer) IsFull() bool

IsFull returns this ringbuffer is full.

func (*Buffer) Length

func (r *Buffer) Length() int

Length return the length of available read bytes.

func (*Buffer) Read

func (r *Buffer) Read(p []byte) (n int, err error)

Read reads up to len(p) bytes into p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered. Even if Read returns n < len(p), it may use all of p as scratch space during the call. If some data is available but not len(p) bytes, Read conventionally returns what is available instead of waiting for more. When Read encounters an error or end-of-file condition after successfully reading n > 0 bytes, it returns the number of bytes read. It may return the (non-nil) error from the same call or return the error (and n == 0) from a subsequent call. Callers should always process the n > 0 bytes returned before considering the error err. Doing so correctly handles I/O errors that happen after reading some bytes and also both of the allowed EOF behaviors.

func (*Buffer) Reset

func (r *Buffer) Reset()

Reset the read pointer and writer pointer to zero.

func (*Buffer) Write

func (r *Buffer) Write(p []byte) (n int, err error)

Write writes len(p) bytes from p to the underlying buf. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. Write returns a non-nil error if it returns n < len(p). Write must not modify the slice data, even temporarily.

Jump to

Keyboard shortcuts

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