bufferpool

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

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 is a thin wrapper around a byte slice. It's intended to be pooled, so the only way to construct one is via a Pool.

func Borrow

func Borrow() *Buffer

Borrow retrieves a buffer from the pool, creating one if necessary.

func (*Buffer) AppendBool

func (b *Buffer) AppendBool(v bool)

AppendBool appends a bool to the underlying buffer.

func (*Buffer) AppendByte

func (b *Buffer) AppendByte(v byte)

AppendByte writes a single byte to the Buffer.

func (*Buffer) AppendBytes

func (b *Buffer) AppendBytes(bs []byte)

func (*Buffer) AppendFloat

func (b *Buffer) AppendFloat(f float64)

AppendFloat appends a float to the underlying buffer. It doesn't quote NaN or +/- Inf.

func (*Buffer) AppendInt

func (b *Buffer) AppendInt(i int64)

AppendInt appends an integer to the underlying buffer (assuming base 10).

func (*Buffer) AppendKeyValue

func (b *Buffer) AppendKeyValue(key string, value interface{})

AppendKeyValue append string key and interface value

func (*Buffer) AppendNewLine

func (b *Buffer) AppendNewLine()

AppendNewLine append string key and interface value

func (*Buffer) AppendString

func (b *Buffer) AppendString(s string)

AppendString writes a string to the Buffer.

func (*Buffer) AppendUint

func (b *Buffer) AppendUint(i uint64)

AppendUint appends an unsigned integer to the underlying buffer (assuming base 10).

func (*Buffer) AppendValue

func (b *Buffer) AppendValue(val interface{})

AppendValue append interface value

func (*Buffer) Bytes

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

Bytes returns a mutable reference to the underlying byte slice.

func (*Buffer) Cap

func (b *Buffer) Cap() int

Cap returns the capacity of the underlying byte slice.

func (*Buffer) Free

func (b *Buffer) Free()

Free returns the Buffer to its Pool.

Callers must not retain references to the Buffer after calling Free.

func (*Buffer) Len

func (b *Buffer) Len() int

Len returns the length of the underlying byte slice.

func (*Buffer) Reset

func (b *Buffer) Reset()

Reset resets the underlying byte slice. Subsequent writes re-use the slice's backing array.

func (*Buffer) String

func (b *Buffer) String() string

String returns a string copy of the underlying byte slice.

func (*Buffer) Write

func (b *Buffer) Write(bs []byte) (int, error)

Write implements io.Writer.

type ChanPool

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

func NewChanPool

func NewChanPool(max int) *ChanPool

NewChanPool using chan constructs a new pool of Buffer.

func (*ChanPool) Borrow

func (p *ChanPool) Borrow() *Buffer

func (*ChanPool) Return

func (p *ChanPool) Return(buf *Buffer)

type Pool

type Pool interface {
	// Borrow retrieves a Buffer from the pool, creating one if necessary.
	Borrow() *Buffer
	// Return returns a Buffer to the pool.
	Return(buf *Buffer)
}

type SyncPool

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

func NewSyncPool

func NewSyncPool() *SyncPool

NewSyncPool using sync.Pool constructs a new Pool.

func (*SyncPool) Borrow

func (p *SyncPool) Borrow() *Buffer

func (*SyncPool) Return

func (p *SyncPool) Return(buf *Buffer)

Jump to

Keyboard shortcuts

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