Documentation ¶
Index ¶
- func Put(b *Buffer)
- type Buffer
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Cap() int
- func (b *Buffer) Len() int
- func (b *Buffer) ReadFrom(r io.Reader) (int64, error)
- func (b *Buffer) Reset()
- func (b *Buffer) Set(p []byte)
- func (b *Buffer) SetString(s string)
- func (b *Buffer) String() string
- func (b *Buffer) TrimNewline()
- func (b *Buffer) Write(p []byte) (int, error)
- func (b *Buffer) WriteBool(v bool)
- func (b *Buffer) WriteByte(c byte) error
- func (b *Buffer) WriteFloat(f float64, bitSize int)
- func (b *Buffer) WriteInt(n int64)
- func (b *Buffer) WriteString(s string) (int, error)
- func (b *Buffer) WriteTo(w io.Writer) (int64, error)
- func (b *Buffer) WriteUint(n uint64)
- type Pool
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Buffer ¶
type Buffer struct { // B is a byte buffer to use in append-like workloads. // See example code for details. B []byte }
Buffer provides byte buffer, which can be used for minimizing memory allocations.
Buffer may be used with functions appending data to the given []byte slice. See example code for details.
Use Get for obtaining an empty byte buffer.
Example ¶
bb := Get() bb.WriteString("first line\n") bb.Write([]byte("second line\n")) bb.B = append(bb.B, "third line\n"...) fmt.Printf("bytebuffer contents=%q", bb.B) // It is safe to release byte buffer now, since it is // no longer used. Put(bb)
Output:
func Get ¶
func Get() *Buffer
Get returns an empty byte buffer from the pool.
Got byte buffer may be returned to the pool via Put call. This reduces the number of memory allocations required for byte buffer management.
func (*Buffer) Bytes ¶
Bytes returns b.B, i.e. all the bytes accumulated in the buffer.
The purpose of this function is bytes.Buffer compatibility.
func (*Buffer) ReadFrom ¶
ReadFrom implements io.ReaderFrom.
The function appends all the data read from r to b.
func (*Buffer) TrimNewline ¶ added in v1.3.0
func (b *Buffer) TrimNewline()
TrimNewline trims any final "\n" byte from the end of the buffer.
func (*Buffer) WriteByte ¶
WriteByte appends the byte c to the buffer.
The purpose of this function is bytes.Buffer compatibility.
The function always returns nil.
func (*Buffer) WriteFloat ¶ added in v1.3.0
func (*Buffer) WriteString ¶
WriteString appends s to Buffer.B.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool represents byte buffer pool.
Distinct pools may be used for distinct types of byte buffers. Properly determined byte buffer types with their own pools may help reducing memory waste.