package buffer
import "go.uber.org/zap/buffer"
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.
Index ¶
- type Buffer
- func (b *Buffer) AppendBool(v bool)
- func (b *Buffer) AppendByte(v byte)
- func (b *Buffer) AppendBytes(v []byte)
- func (b *Buffer) AppendFloat(f float64, bitSize int)
- func (b *Buffer) AppendInt(i int64)
- func (b *Buffer) AppendString(s string)
- func (b *Buffer) AppendTime(t time.Time, layout string)
- func (b *Buffer) AppendUint(i uint64)
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Cap() int
- func (b *Buffer) Free()
- func (b *Buffer) Len() int
- func (b *Buffer) Reset()
- func (b *Buffer) String() string
- func (b *Buffer) TrimNewline()
- func (b *Buffer) Write(bs []byte) (int, error)
- func (b *Buffer) WriteByte(v byte) error
- func (b *Buffer) WriteString(s string) (int, error)
- type Pool
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 (*Buffer) AppendBool ¶
AppendBool appends a bool to the underlying buffer.
func (*Buffer) AppendByte ¶
AppendByte writes a single byte to the Buffer.
func (*Buffer) AppendBytes ¶
AppendBytes writes the given slice of bytes to the Buffer.
func (*Buffer) AppendFloat ¶
AppendFloat appends a float to the underlying buffer. It doesn't quote NaN or +/- Inf.
func (*Buffer) AppendInt ¶
AppendInt appends an integer to the underlying buffer (assuming base 10).
func (*Buffer) AppendString ¶
AppendString writes a string to the Buffer.
func (*Buffer) AppendTime ¶
AppendTime appends the time formatted using the specified layout.
func (*Buffer) AppendUint ¶
AppendUint appends an unsigned integer to the underlying buffer (assuming base 10).
func (*Buffer) Bytes ¶
Bytes returns a mutable reference to the underlying byte slice.
func (*Buffer) Cap ¶
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 ¶
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 ¶
String returns a string copy of the underlying byte slice.
func (*Buffer) TrimNewline ¶
func (b *Buffer) TrimNewline()
TrimNewline trims any final "\n" byte from the end of the buffer.
func (*Buffer) Write ¶
Write implements io.Writer.
func (*Buffer) WriteByte ¶
WriteByte writes a single byte to the Buffer.
Error returned is always nil, function signature is compatible with bytes.Buffer and bufio.Writer
func (*Buffer) WriteString ¶
WriteString writes a string to the Buffer.
Error returned is always nil, function signature is compatible with bytes.Buffer and bufio.Writer
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
A Pool is a type-safe wrapper around a sync.Pool.
func NewPool ¶
func NewPool() Pool
NewPool constructs a new Pool.
func (Pool) Get ¶
Get retrieves a Buffer from the pool, creating one if necessary.
Source Files ¶
buffer.go pool.go
- Version
- v1.27.0 (latest)
- Published
- Feb 20, 2024
- Platform
- linux/amd64
- Imports
- 3 packages
- Last checked
- 6 minutes ago –
Tools for package owners.