Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

buffer

v1.28.0
go.uber.org/zap/buffer

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

23 matches

Top ↑

Package buffer provides a thin wrapper around a byte slice. Unlike the standard library's bytes.Buffer, it supports a portion of the strconv package's zero-allocation formatters.

Types

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.

Buffer.AppendBool

func (b *Buffer) AppendBool(v bool)

AppendBool appends a bool to the underlying buffer.

Buffer.AppendByte

func (b *Buffer) AppendByte(v byte)

AppendByte writes a single byte to the Buffer.

Buffer.AppendBytes

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

AppendBytes writes the given slice of bytes to the Buffer.

Buffer.AppendFloat

func (b *Buffer) AppendFloat(f float64, bitSize int)

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

Buffer.AppendInt

func (b *Buffer) AppendInt(i int64)

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

Buffer.AppendString

func (b *Buffer) AppendString(s string)

AppendString writes a string to the Buffer.

Buffer.AppendTime

func (b *Buffer) AppendTime(t time.Time, layout string)

AppendTime appends the time formatted using the specified layout.

Buffer.AppendUint

func (b *Buffer) AppendUint(i uint64)

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

Buffer.Bytes

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

Bytes returns a mutable reference to the underlying byte slice.

Buffer.Cap

func (b *Buffer) Cap() int

Cap returns the capacity of the underlying byte slice.

Buffer.Free

func (b *Buffer) Free()

Free returns the Buffer to its Pool.

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

Buffer.Len

func (b *Buffer) Len() int

Len returns the length of the underlying byte slice.

Buffer.Reset

func (b *Buffer) Reset()

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

Buffer.String

func (b *Buffer) String() string

String returns a string copy of the underlying byte slice.

Buffer.TrimNewline

func (b *Buffer) TrimNewline()

TrimNewline trims any final "\n" byte from the end of the buffer.

Buffer.Write

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

Write implements io.Writer.

Buffer.WriteByte

func (b *Buffer) WriteByte(v byte) error

WriteByte writes a single byte to the Buffer.

Error returned is always nil, function signature is compatible with bytes.Buffer and bufio.Writer

Buffer.WriteString

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

WriteString writes a string to the Buffer.

Error returned is always nil, function signature is compatible with bytes.Buffer and bufio.Writer

Pool

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

A Pool is a type-safe wrapper around a sync.Pool.

NewPool

func NewPool() Pool

NewPool constructs a new Pool.

Pool.Get

func (p Pool) Get() *Buffer

Get retrieves a Buffer from the pool, creating one if necessary.

Dependency graph