Documentation
¶
Overview ¶
Package buffer implements a buffer for serialization, consisting of a chain of []byte-s to reduce copying and to allow reuse of individual chunks.
Index ¶
- func Init(cfg PoolConfig)
- type Buffer
- func (b *Buffer) AppendByte(data byte)
- func (b *Buffer) AppendBytes(data []byte)
- func (b *Buffer) AppendFloat32(f float32, dataSize int)
- func (b *Buffer) AppendFloat64(f float64, dataSize int)
- func (b *Buffer) AppendInt(n int64, dataSize int)
- func (b *Buffer) AppendString(data string)
- func (b *Buffer) AppendUint(n uint64, dataSize int)
- func (b *Buffer) BuildBytes() []byte
- func (b *Buffer) Close() error
- func (b *Buffer) DumpTo(w io.Writer) (int, error)
- func (b *Buffer) EnsureSpace(s int)
- func (b *Buffer) Size() int
- type PoolConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init(cfg PoolConfig)
Init sets up a non-default pooling and allocation strategy. Should be run before serialization is done.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer is a buffer optimized for serialization without extra copying.
func (*Buffer) AppendByte ¶
AppendByte appends a single byte to buffer.
func (*Buffer) AppendBytes ¶
AppendBytes appends a byte slice to buffer.
func (*Buffer) AppendFloat32 ¶ added in v0.8.6
func (*Buffer) AppendFloat64 ¶ added in v0.8.6
func (*Buffer) AppendString ¶
func (*Buffer) AppendUint ¶ added in v0.8.6
func (*Buffer) BuildBytes ¶
func (*Buffer) EnsureSpace ¶
EnsureSpace makes sure that the current chunk contains at least s free bytes, possibly creating a new chunk.
type PoolConfig ¶
type PoolConfig struct {
PooledSize int // Minimum chunk size that is reused, reusing chunks too small will result in overhead.
}
PoolConfig contains configuration for the allocation and reuse strategy.
Click to show internal directories.
Click to hide internal directories.