type PoolConfig … var config … var buffers … func initBuffers() { … } func init() { … } // Init sets up a non-default pooling and allocation strategy. Should be run before serialization is done. func Init(cfg PoolConfig) { … } // putBuf puts a chunk to reuse pool if it can be reused. func putBuf(buf []byte) { … } // getBuf gets a chunk from reuse pool or creates a new one if reuse failed. func getBuf(size int) []byte { … } type Buffer … // EnsureSpace makes sure that the current chunk contains at least s free bytes, // possibly creating a new chunk. func (b *Buffer) EnsureSpace(s int) { … } func (b *Buffer) ensureSpaceSlow(s int) { … } // AppendByte appends a single byte to buffer. func (b *Buffer) AppendByte(data byte) { … } // AppendBytes appends a byte slice to buffer. func (b *Buffer) AppendBytes(data []byte) { … } func (b *Buffer) appendBytesSlow(data []byte) { … } // AppendString appends a string to buffer. func (b *Buffer) AppendString(data string) { … } func (b *Buffer) appendStringSlow(data string) { … } // Size computes the size of a buffer by adding sizes of every chunk. func (b *Buffer) Size() int { … } // DumpTo outputs the contents of a buffer to a writer and resets the buffer. func (b *Buffer) DumpTo(w io.Writer) (written int, err error) { … } // 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. You can optionally provide one byte // slice as argument that it will try to reuse. func (b *Buffer) BuildBytes(reuse ...[]byte) []byte { … } type readCloser … func (r *readCloser) Read(p []byte) (n int, err error) { … } func (r *readCloser) Close() error { … } // ReadCloser creates an io.ReadCloser with all the contents of the buffer. func (b *Buffer) ReadCloser() io.ReadCloser { … }