Documentation ¶
Index ¶
- Constants
- type RingBuffer
- func (r *RingBuffer) Bytes() []byte
- func (r *RingBuffer) Cap() int
- func (r *RingBuffer) Clear()
- func (r *RingBuffer) CopyFromFd(fd int) (int, error)
- func (r *RingBuffer) IsEmpty() bool
- func (r *RingBuffer) Len() int
- func (r *RingBuffer) Read(p []byte) (int, error)
- func (r *RingBuffer) Release(n int)
- func (r *RingBuffer) Write(p []byte) (int, error)
- func (r *RingBuffer) WriteString(s string) (int, error)
- func (r *RingBuffer) WriteToFd(fd int) (int, error)
Constants ¶
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) 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.