Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTooLarge = errors.New("bytes.Buffer: too large")
ErrTooLarge is passed to panic if memory cannot be allocated to store data in a buffer.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer[T constraints.Unsigned] struct { // contains filtered or unexported fields }
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.
func NewBuffer ¶
func NewBuffer[T constraints.Unsigned](size int) *Buffer[T]
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.
func NewBufferFrom ¶
func NewBufferFrom[T constraints.Unsigned](b []T) *Buffer[T]
func (*Buffer[T]) Cap ¶
Cap returns the capacity of the buffer's underlying byte slice, that is, the total space allocated for the buffer's data.
func (*Buffer[T]) Grow ¶
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.
func (*Buffer[T]) Len ¶
Len returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Slice()).
func (*Buffer[T]) Reset ¶
func (b *Buffer[T]) Reset()
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).
func (*Buffer[T]) Slice ¶
func (b *Buffer[T]) Slice() []T
Slice 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.