elastic

package
v2.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2022 License: Apache-2.0 Imports: 6 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

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

Buffer combines ring-buffer and list-buffer. Ring-buffer is the top-priority buffer to store response data, gnet will only switch to list-buffer if the data size of ring-buffer reaches the maximum(MaxStackingBytes), list-buffer is more flexible and scalable, which helps the application reduce memory footprint.

func New

func New(maxStaticBytes int) (*Buffer, error)

New instantiates an elastic.Buffer and returns it.

func (*Buffer) Buffered

func (mb *Buffer) Buffered() int

Buffered returns the number of bytes that can be read from the current buffer.

func (*Buffer) Discard

func (mb *Buffer) Discard(n int) (discarded int, err error)

Discard discards n bytes in this buffer.

func (*Buffer) IsEmpty

func (mb *Buffer) IsEmpty() bool

IsEmpty indicates whether this buffer is empty.

func (*Buffer) Peek

func (mb *Buffer) Peek(n int) [][]byte

Peek returns n bytes as [][]byte, these bytes won't be discarded until Buffer.Discard() is called.

func (*Buffer) Read

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

Read reads data from the Buffer.

func (*Buffer) ReadFrom

func (mb *Buffer) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements io.ReaderFrom.

func (*Buffer) Release

func (mb *Buffer) Release()

Release frees all resource of this buffer.

func (*Buffer) Reset

func (mb *Buffer) Reset(maxStaticBytes int)

Reset resets the buffer.

func (*Buffer) Write

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

Write appends data to this buffer.

func (*Buffer) WriteTo

func (mb *Buffer) WriteTo(w io.Writer) (n int64, err error)

WriteTo implements io.WriterTo.

func (*Buffer) Writev

func (mb *Buffer) Writev(bs [][]byte) (int, error)

Writev appends multiple byte slices to this buffer.

type RingBuffer

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

RingBuffer is the elastic wrapper of ring.Buffer.

func (*RingBuffer) Available

func (b *RingBuffer) Available() int

Available returns the length of available bytes to write.

func (*RingBuffer) Buffered

func (b *RingBuffer) Buffered() int

Buffered returns the length of available bytes to read.

func (*RingBuffer) Bytes

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

Bytes returns all available read bytes. It does not move the read pointer and only copy the available data.

func (*RingBuffer) Cap

func (b *RingBuffer) Cap() int

Cap returns the size of the underlying buffer.

func (*RingBuffer) Discard

func (b *RingBuffer) Discard(n int) (int, error)

Discard skips the next n bytes by advancing the read pointer.

func (*RingBuffer) Done

func (b *RingBuffer) Done()

Done checks and returns the internal ring-buffer to pool.

func (*RingBuffer) IsEmpty

func (b *RingBuffer) IsEmpty() bool

IsEmpty tells if this ring-buffer is empty.

func (*RingBuffer) IsFull

func (b *RingBuffer) IsFull() bool

IsFull tells if this ring-buffer is full.

func (*RingBuffer) Len

func (b *RingBuffer) Len() int

Len returns the length of the underlying buffer.

func (*RingBuffer) Peek

func (b *RingBuffer) Peek(n int) (head []byte, tail []byte)

Peek returns the next n bytes without advancing the read pointer, it returns all bytes when n <= 0.

func (*RingBuffer) Read

func (b *RingBuffer) Read(p []byte) (int, 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 (*RingBuffer) ReadByte

func (b *RingBuffer) ReadByte() (byte, error)

ReadByte reads and returns the next byte from the input or ErrIsEmpty.

func (*RingBuffer) ReadFrom

func (b *RingBuffer) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements io.ReaderFrom.

func (*RingBuffer) Reset

func (b *RingBuffer) Reset()

Reset the read pointer and write pointer to zero.

func (*RingBuffer) Write

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

Write writes len(p) bytes from p to the underlying buf. It returns the number of bytes written from p (n == len(p) > 0) and any error encountered that caused the write to stop early. If the length of p is greater than the writable capacity of this ring-buffer, it will allocate more memory to this ring-buffer. Write must not modify the slice data, even temporarily.

func (*RingBuffer) WriteByte

func (b *RingBuffer) WriteByte(c byte) error

WriteByte writes one byte into buffer.

func (*RingBuffer) WriteString

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

WriteString writes the contents of the string s to buffer, which accepts a slice of bytes.

func (*RingBuffer) WriteTo

func (b *RingBuffer) WriteTo(w io.Writer) (int64, error)

WriteTo implements io.WriterTo.

Jump to

Keyboard shortcuts

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