Documentation ¶
Index ¶
- Constants
- func Clone(b []byte) []byte
- func GetBufioReader(r io.Reader, size int) *bufio.Reader
- func GetBytes[T constraints.Integer](size T) []byte
- func PutBufioReader(b *bufio.Reader)
- func PutBytes(b []byte)
- type Buffer
- func (b *Buffer) Advance(n int)
- func (b *Buffer) Bytes() []byte
- func (b *Buffer) Cap() int
- func (b *Buffer) Close() error
- func (b *Buffer) Grow(n int)
- func (b *Buffer) Len() int
- func (b *Buffer) Next(n int) []byte
- func (b *Buffer) Read(buf []byte) (int, error)
- func (b *Buffer) ReadByte() (byte, error)
- func (b *Buffer) ReadFrom(r io.Reader) (int64, error)
- func (b *Buffer) Reset()
- func (b *Buffer) String() string
- func (b *Buffer) Truncate(n int)
- func (b *Buffer) Write(buf []byte) (int, error)
- func (b *Buffer) WriteByte(c byte) error
- func (b *Buffer) WriteString(buf string) (int, error)
- func (b *Buffer) WriteTo(w io.Writer) (int64, error)
- type Pool
- type ReverseProxyBuffer
Constants ¶
const DefaultSize = 16 * 0x400
const MaxLength = math.MaxInt32
MaxLength is the maximum length of an element that can be added to the Pool.
const MaxSegmentSize = math.MaxUint16
const MinRead = 512
MinRead is the minimum slice size passed to a Read call by Buffer.ReadFrom. As long as the Buffer has at least MinRead bytes beyond what is required to hold the contents of r, ReadFrom will not grow the underlying buffer.
Variables ¶
This section is empty.
Functions ¶
func GetBytes ¶
func GetBytes[T constraints.Integer](size T) []byte
func PutBufioReader ¶ added in v0.3.6
Types ¶
type Buffer ¶ added in v0.3.5
type Buffer struct { // Pool is the buffer pool to use. If nil, this Buffer will use the // global buffer pool. Pool Pool // contains filtered or unexported fields }
Buffer is a buffer like bytes.Buffer that:
1. Uses a buffer pool. 2. Frees memory on read.
If you only have a few buffers and read/write at a steady rate, *don't* use this package, it'll be slower.
However:
- If you frequently create/destroy buffers, this implementation will be significantly nicer to the allocator.
- If you have many buffers with bursty traffic, this implementation will use significantly less memory.
func NewBUfferNoCopy ¶ added in v0.3.6
NewBuffer constructs a new buffer initialized to `buf`.
func NewBuffer ¶ added in v0.3.5
NewBuffer constructs a new buffer initialized to `buf`. Unlike `bytes.Buffer`, we *copy* the buffer but don't reuse it (to ensure that we *only* use buffers from the pool).
func NewBufferSize ¶ added in v0.3.6
func NewBufferSize[T constraints.Integer](size T) *Buffer
NewBufferSize constructs a new buffer of the given size.
func NewBufferString ¶ added in v0.3.6
NewBufferString is identical to NewBuffer *except* that it allows one to initialize the buffer from a string (without having to allocate an intermediate bytes slice).
func (*Buffer) Bytes ¶ added in v0.3.5
Bytes returns the slice of bytes currently buffered in the Buffer.
The buffer returned by Bytes is valid until the next call grow, truncate, read, or write. Really, just don't touch the Buffer until you're done with the return value of this function.
func (*Buffer) Cap ¶ added in v0.3.6
Cap returns the current capacity of the buffer.
Note: Buffer *may* re-allocate when writing (or growing by) `n` bytes even if `Cap() < Len() + n` to avoid excessive copying.
func (*Buffer) Grow ¶ added in v0.3.6
Grow grows the internal buffer such that `n` bytes can be written without reallocating.
func (*Buffer) Len ¶ added in v0.3.5
Len returns the number of bytes that can be read from this buffer.
func (*Buffer) Next ¶ added in v0.3.6
Next is an alternative to `Read` that returns a byte slice instead of taking one.
The returned byte slice is valid until the next read, write, grow, or truncate.
func (*Buffer) Read ¶ added in v0.3.6
Read reads at most `len(buf)` bytes from the internal buffer into the given buffer.
func (*Buffer) String ¶ added in v0.3.5
String returns the string representation of the buffer.
It returns `<nil>` the buffer is a nil pointer.
func (*Buffer) Truncate ¶ added in v0.3.5
Truncate truncates the Buffer.
Panics if `n > b.Len()`.
This function may free memory by shrinking the internal buffer.
func (*Buffer) WriteString ¶ added in v0.3.5
WriteString writes a string to the buffer.
This function is identical to Write except that it allows one to write a string directly without allocating an intermediate byte slice.
type ReverseProxyBuffer ¶
type ReverseProxyBuffer struct{}
func (ReverseProxyBuffer) Get ¶
func (ReverseProxyBuffer) Get() []byte
func (ReverseProxyBuffer) Put ¶
func (ReverseProxyBuffer) Put(b []byte)