bytepool

package
v1.16.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MemoryLimit int64 = 1024 * 1024 * 1024
)

Functions

func GetBytes

func GetBytes(length, capacity int) []byte

GetBytes gets a buffer with at least of capacity as defined by caller. panics with negative value

func GetBytesWithLen

func GetBytesWithLen(length int) []byte

func PutBytes

func PutBytes(buf []byte)

PutBytes recycles the buffer to the bytepool

func PutBytesStream

func PutBytesStream(bytesStream <-chan []byte)

func SetMemoryLimit

func SetMemoryLimit(n int64)

Types

type FrameBuffer

type FrameBuffer struct {
	*StringsBuffer
	// contains filtered or unexported fields
}

func NewFrameBuffer

func NewFrameBuffer() *FrameBuffer

func (*FrameBuffer) DiscardCurrentRow

func (f *FrameBuffer) DiscardCurrentRow()

DiscardCurrentRow unreads data after last NextRow is called

func (*FrameBuffer) Export

func (f *FrameBuffer) Export(result [][]string) (int, []int)

Export attempts to put the result into 2 dimensional string. returns the number of rows read and each number of elems in each row

func (*FrameBuffer) NewRow

func (f *FrameBuffer) NewRow()

func (*FrameBuffer) ReadColumnTexts

func (f *FrameBuffer) ReadColumnTexts(columnTexts [][]string) (int, []int)

ReadColumnTexts attempts to read into ReadColumnTexts May skip columns or panic if dimension are not correct Caller should check the size of input before calling this function return number of rows read and number of elems read in each row

type StringsBuffer

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

func NewStringsBuffer

func NewStringsBuffer() *StringsBuffer

func (*StringsBuffer) Close

func (s *StringsBuffer) Close()

func (*StringsBuffer) Export

func (s *StringsBuffer) Export() []string

Export return the current state of the StringsBuffer, safe to use until the next write or close operation

func (*StringsBuffer) ExportTo

func (s *StringsBuffer) ExportTo(result []string) int

ExportTo attempts to put the

func (*StringsBuffer) Len

func (s *StringsBuffer) Len() int

func (*StringsBuffer) NewElem

func (s *StringsBuffer) NewElem()

NewElem starts a new section to write another string

func (*StringsBuffer) NewEmptyResult

func (s *StringsBuffer) NewEmptyResult() []string

NewEmptyResult returns an empty slice of string, which guarantees that when used as argument to call Export, will always export all data in the buffer

func (*StringsBuffer) TruncateElem

func (s *StringsBuffer) TruncateElem(n int)

TruncateElem discard all but first n strings panics if there

func (*StringsBuffer) Write

func (s *StringsBuffer) Write(p []byte) (int, error)

func (*StringsBuffer) WriteByte

func (s *StringsBuffer) WriteByte(p byte) error

func (*StringsBuffer) WriteString

func (s *StringsBuffer) WriteString(p string) (int, error)

type ZBuffer

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

ZBuffer attempts to reuse all byte bufferStream without wastage, aims to have zero []byte being garbage collected.

func NewZBuffer

func NewZBuffer(bufferSize, channelSize int) *ZBuffer

NewZBuffer returns a *ZBuffer with given fixed buffer size and max buffer count

func NewZBufferDefault

func NewZBufferDefault() *ZBuffer

func (*ZBuffer) Close

func (z *ZBuffer) Close() error

Close cleaned up the buffer, any operations after calling close will not be safe

func (*ZBuffer) Flush

func (z *ZBuffer) Flush() error

func (*ZBuffer) Read

func (z *ZBuffer) Read(des []byte) (int, error)

Read transfer content to des, draining the buffer. If buffer is completely drained, io.EOF is returned

func (*ZBuffer) ReadByte

func (z *ZBuffer) ReadByte() (byte, error)

ReadByte reads 1 byte from buffer If buffer is drained, io.EOF is returned

func (*ZBuffer) ReadFrom

func (z *ZBuffer) ReadFrom(r io.Reader) (int64, error)

ReadFrom reads from r until io.EOF or error, expands the buffer when needed

func (*ZBuffer) Write

func (z *ZBuffer) Write(src []byte) (int, error)

Write appends contents of src to buffer, increase the size of buffer when needed. Blocks if buffer is full.

func (*ZBuffer) WriteByte

func (z *ZBuffer) WriteByte(b byte) error

WriteByte appends b to buffer, increase the size of buffer when needed.

func (*ZBuffer) WriteTo

func (z *ZBuffer) WriteTo(w io.Writer) (int64, error)

WriteTo writes to writer until buffer is closed

type ZReader

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

func NewZReader

func NewZReader(r io.Reader, bufferSize, channelSize int) *ZReader

func NewZReaderDefault

func NewZReaderDefault(r io.Reader) *ZReader

func (*ZReader) Close

func (z *ZReader) Close() error

func (*ZReader) PrependCurrentBuffer

func (z *ZReader) PrependCurrentBuffer(pre []byte)

func (*ZReader) Read

func (z *ZReader) Read(p []byte) (int, error)

func (*ZReader) ReadByte

func (z *ZReader) ReadByte() (byte, error)

func (*ZReader) ReadFull

func (z *ZReader) ReadFull(p []byte) error

func (*ZReader) ReadNextBuffer

func (z *ZReader) ReadNextBuffer() ([]byte, error)

ReadNextBuffer returns the remaining buffer if not empty, else attempts to read from the next buffer in channel

func (*ZReader) ReadUvarint

func (z *ZReader) ReadUvarint() (uint64, error)

func (*ZReader) UnreadCurrentBuffer

func (z *ZReader) UnreadCurrentBuffer(n int)

type ZWriter

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

func NewZWriter

func NewZWriter(w io.Writer, bufferSize, channelSize int) *ZWriter

func NewZWriterDefault

func NewZWriterDefault(w io.Writer) *ZWriter

func (*ZWriter) Close

func (z *ZWriter) Close() error

func (*ZWriter) Flush

func (z *ZWriter) Flush() error

func (*ZWriter) Write

func (z *ZWriter) Write(p []byte) (int, error)

func (*ZWriter) WriteByte

func (z *ZWriter) WriteByte(b byte) error

func (*ZWriter) WriteString

func (z *ZWriter) WriteString(s string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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