Package-Level Type Names (total 4, in which 2 are exported)
/* sort exporteds by: | */
A Buffer is a variable-sized buffer of bytes with Read and Write methods.
The zero value for Buffer is an empty buffer ready to use.
// contents are the bytes buf[off : len(buf)]
// last read operation, so that Unread* can work correctly.
// read at &buf[off], write at &buf[len(buf)]
Bytes returns a slice of length b.Len() holding the unread portion of the buffer.
The slice is valid for use only until the next buffer modification (that is,
only until the next call to a method like Read, Write, Reset, or Truncate).
The slice aliases the buffer content at least until the next buffer modification,
so immediate changes to the slice will affect the result of future reads.
Cap returns the capacity of the buffer's underlying byte slice, that is, the
total space allocated for the buffer's data.
Grow grows the buffer's capacity, if necessary, to guarantee space for
another n bytes. After Grow(n), at least n bytes can be written to the
buffer without another allocation.
If n is negative, Grow will panic.
If the buffer can't grow it will panic with ErrTooLarge.
Len returns the number of bytes of the unread portion of the buffer;
b.Len() == len(b.Bytes()).
Next returns a slice containing the next n bytes from the buffer,
advancing the buffer as if the bytes had been returned by Read.
If there are fewer than n bytes in the buffer, Next returns the entire buffer.
The slice is only valid until the next call to a read or write method.
Read reads the next len(p) bytes from the buffer or until the buffer
is drained. The return value n is the number of bytes read. If the
buffer has no data to return, err is io.EOF (unless len(p) is zero);
otherwise it is nil.
ReadByte reads and returns the next byte from the buffer.
If no byte is available, it returns error io.EOF.
ReadBytes reads until the first occurrence of delim in the input,
returning a slice containing the data up to and including the delimiter.
If ReadBytes encounters an error before finding a delimiter,
it returns the data read before the error and the error itself (often io.EOF).
ReadBytes returns err != nil if and only if the returned data does not end in
delim.
ReadFrom reads data from r until EOF and appends it to the buffer, growing
the buffer as needed. The return value n is the number of bytes read. Any
error except io.EOF encountered during the read is also returned. If the
buffer becomes too large, ReadFrom will panic with ErrTooLarge.
ReadRune reads and returns the next UTF-8-encoded
Unicode code point from the buffer.
If no bytes are available, the error returned is io.EOF.
If the bytes are an erroneous UTF-8 encoding, it
consumes one byte and returns U+FFFD, 1.
ReadString reads until the first occurrence of delim in the input,
returning a string containing the data up to and including the delimiter.
If ReadString encounters an error before finding a delimiter,
it returns the data read before the error and the error itself (often io.EOF).
ReadString returns err != nil if and only if the returned data does not end
in delim.
Reset resets the buffer to be empty,
but it retains the underlying storage for use by future writes.
Reset is the same as Truncate(0).
(*Buffer) ResetBuf(buf []byte)
String returns the contents of the unread portion of the buffer
as a string. If the Buffer is a nil pointer, it returns "<nil>".
To build strings more efficiently, see the strings.Builder type.
Truncate discards all but the first n unread bytes from the buffer
but continues to use the same allocated storage.
It panics if n is negative or greater than the length of the buffer.
UnreadByte unreads the last byte returned by the most recent successful
read operation that read at least one byte. If a write has happened since
the last read, if the last read returned an error, or if the read read zero
bytes, UnreadByte returns an error.
UnreadRune unreads the last rune returned by ReadRune.
If the most recent read or write operation on the buffer was
not a successful ReadRune, UnreadRune returns an error. (In this regard
it is stricter than UnreadByte, which will unread the last byte
from any read operation.)
Write appends the contents of p to the buffer, growing the buffer as
needed. The return value n is the length of p; err is always nil. If the
buffer becomes too large, Write will panic with ErrTooLarge.
WriteByte appends the byte c to the buffer, growing the buffer as needed.
The returned error is always nil, but is included to match bufio.Writer's
WriteByte. If the buffer becomes too large, WriteByte will panic with
ErrTooLarge.
WriteRune appends the UTF-8 encoding of Unicode code point r to the
buffer, returning its length and an error, which is always nil but is
included to match bufio.Writer's WriteRune. The buffer is grown as needed;
if it becomes too large, WriteRune will panic with ErrTooLarge.
WriteString appends the contents of s to the buffer, growing the buffer as
needed. The return value n is the length of s; err is always nil. If the
buffer becomes too large, WriteString will panic with ErrTooLarge.
WriteTo writes data to w until the buffer is drained or an error occurs.
The return value n is the number of bytes written; it always fits into an
int, but it is int64 to match the io.WriterTo interface. Any error
encountered during the write is also returned.
empty reports whether the unread portion of the buffer is empty.
grow grows the buffer to guarantee space for n more bytes.
It returns the index where bytes should be written.
If the buffer can't grow it will panic with ErrTooLarge.
readSlice is like ReadBytes but returns a reference to internal buffer data.
tryGrowByReslice is a inlineable version of grow for the fast-case where the
internal buffer only needs to be resliced.
It returns the index where bytes should be written and whether it succeeded.
*Buffer : compress/flate.Reader
*Buffer : expvar.Var
*Buffer : fmt.Stringer
*Buffer : io.ByteReader
*Buffer : io.ByteScanner
*Buffer : io.ByteWriter
*Buffer : io.Reader
*Buffer : io.ReaderFrom
*Buffer : io.ReadWriter
*Buffer : io.RuneReader
*Buffer : io.RuneScanner
*Buffer : io.StringWriter
*Buffer : io.Writer
*Buffer : io.WriterTo
*Buffer : github.com/vmihailenco/msgpack/v5.bufReader
*Buffer : github.com/vmihailenco/msgpack/v5.writer
*Buffer : github.com/aws/smithy-go/encoding/xml.writer
*Buffer : github.com/aws/smithy-go/middleware.stringer
*Buffer : github.com/aws/smithy-go/middleware.stringWriter
*Buffer : context.stringer
*Buffer : golang.org/x/net/http2.pipeBuffer
*Buffer : golang.org/x/net/http2.stringWriter
*Buffer : net/http.http2pipeBuffer
*Buffer : net/http.http2stringWriter
*Buffer : runtime.stringer
func Get(length int) *Buffer
func NewBuffer(buf []byte) *Buffer
func NewBufferString(s string) *Buffer
func (*Pool).Get() *Buffer
func (*Pool).New() *Buffer
func Put(buf *Buffer)
func (*Pool).Put(buf *Buffer)
func lock(buf *Buffer)
func unlock(buf *Buffer)
Pool represents byte buffer pool.
Different pools should be used for different usage patterns to achieve better
performance and lower memory usage.
// default is 0.95
calibratinguint32calls[20]uint32serveSizeuint32
Get returns an empty buffer from the pool. Returned buffer capacity
is determined by accumulated usage stats and changes over time.
The buffer may be returned to the pool using Put or retained for further
usage. In latter case buffer length must be updated using UpdateLen.
New returns an empty buffer bypassing the pool. Returned buffer capacity
is determined by accumulated usage stats and changes over time.
Put returns buffer to the pool.
UpdateLen updates stats about buffer length.
(*Pool) calibrate()(*Pool) getServePctile() float64(*Pool) getServeSize() int
var github.com/go-pg/pg/v10/types.jsonPool
The readOp constants describe the last action performed on
the buffer, so that UnreadRune and UnreadByte can check for
invalid usage. opReadRuneX constants are chosen such that
converted to int they correspond to the rune size that was read.
const opInvalid
const opRead
const opReadRune1
Package-Level Functions (total 9, in which 4 are exported)
Get retrieves a buffer of the appropriate length from the buffer pool or
allocates a new one. Get may choose to ignore the pool and treat it as empty.
Callers should not assume any relation between values passed to Put and the
values returned by Get.
If no suitable buffer exists in the pool, Get creates one.
NewBuffer creates and initializes a new Buffer using buf as its
initial contents. The new Buffer takes ownership of buf, and the
caller should not use buf after this call. NewBuffer is intended to
prepare a Buffer to read existing data. It can also be used to set
the initial size of the internal buffer for writing. To do that,
buf should have the desired capacity but a length of zero.
In most cases, new(Buffer) (or just declaring a Buffer variable) is
sufficient to initialize a Buffer.
NewBufferString creates and initializes a new Buffer using string s as its
initial contents. It is intended to prepare a buffer to read an existing
string.
In most cases, new(Buffer) (or just declaring a Buffer variable) is
sufficient to initialize a Buffer.
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.