Documentation

Overview

    Package bufferpool maintains a pool of bytes.Buffers for use in encoding and transport implementations.

    Index

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    func Put

    func Put(buf *Buffer)

      Put returns a Buffer to the Buffer pool.

      Types

      type Buffer

      type Buffer struct {
      	// contains filtered or unexported fields
      }

        Buffer represents a poolable buffer. It wraps an underlying *bytes.Buffer with lightweight detection of races.

        func Get

        func Get() *Buffer

          Get returns a new Buffer from the Buffer pool that has been reset.

          func (*Buffer) Bytes

          func (b *Buffer) Bytes() []byte

            Bytes returns the bytes in the underlying buffer, as well as a function to call when the caller is done using the bytes. This is easy to mis-use and lead to a use-after-free that cannot be detected, so it is strongly recommended that this method is NOT used.

            func (*Buffer) Len

            func (b *Buffer) Len() int

              Len is the same as bytes.Buffer.Len.

              func (*Buffer) Read

              func (b *Buffer) Read(p []byte) (int, error)

                Read is the same as bytes.Buffer.Read.

                func (*Buffer) ReadFrom

                func (b *Buffer) ReadFrom(r io.Reader) (int64, error)

                  ReadFrom is the same as bytes.Buffer.ReadFrom.

                  func (*Buffer) Release

                  func (b *Buffer) Release()

                    Release releases the buffer back to the buffer pool.

                    func (*Buffer) Reset

                    func (b *Buffer) Reset()

                      Reset is the same as bytes.Buffer.Reset.

                      func (*Buffer) Write

                      func (b *Buffer) Write(p []byte) (int, error)

                        Write is the same as bytes.Buffer.Write.

                        func (*Buffer) WriteTo

                        func (b *Buffer) WriteTo(w io.Writer) (int64, error)

                          WriteTo is the same as bytes.Buffer.WriteTo.

                          type Option

                          type Option func(*Pool)

                            Option configures a buffer pool.

                            func DetectUseAfterFreeForTests

                            func DetectUseAfterFreeForTests() Option

                              DetectUseAfterFreeForTests is an option that allows unit tests to detect bad use of a pooled buffer after it has been released to the pool.

                              type Pool

                              type Pool struct {
                              	// contains filtered or unexported fields
                              }

                                Pool represents a buffer pool with a set of options.

                                func NewPool

                                func NewPool(opts ...Option) *Pool

                                  NewPool returns a pool that we can allocate buffers from.

                                  func (*Pool) Get

                                  func (p *Pool) Get() *Buffer

                                    Get returns a buffer from the pool.