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 ¶
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 { // Buf is the current chunk that can be used for serialization. Buf []byte // 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) AppendString ¶
AppendBytes appends a string to buffer.
func (*Buffer) BuildBytes ¶
BuildBytes creates a single byte slice with all the contents of the buffer. Data is copied if it does not fit in a single chunk.
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 { StartSize int // Minimum chunk size that is allocated. PooledSize int // Minimum chunk size that is reused, reusing chunks too small will result in overhead. MaxSize int // Maximum chunk size that will be allocated. }
PoolConfig contains configuration for the allocation and reuse strategy.