buffer

package
v0.0.0-...-2aa3dc7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSize = 128

Variables

This section is empty.

Functions

This section is empty.

Types

type Buffer

type Buffer interface {
	// Len returns the number of bytes in the buffer; b.Len() == len(b.Bytes()).
	Len() int

	// Bytes returns a byte slice with the buffer bytes.
	// It is valid for use only until the next buffer mutation.
	Bytes() []byte

	// Grow grows the buffer and returns an n-byte slice.
	// It be should be used directly and is only valid until the next buffer mutation.
	//
	// Usage:
	//
	//	p := b.Grow(8)
	//	binary.BigEndian.PutUint64(p, 1234)
	//
	Grow(n int) []byte

	// Write appends bytes from p to the buffer.
	//
	// Equivalent to:
	//
	//	buf := b.Grow(n)
	//	copy(buf, p)
	//
	Write(p []byte) (n int, err error)

	// WriteByte writes a byte to the buffer.
	WriteByte(b byte) error

	// Reset resets the buffer to be empty, but can retain its internal buffer.
	Reset()
}

Buffer is a general purpose byte buffer interface.

func New

func New() Buffer

New buffer returns a new buffer of a default size.

func NewBytes

func NewBytes(buf []byte) Buffer

New returns a new buffer and initializes it with a byte slice. The new buffer takes the ownership of the slice.

func NewSize

func NewSize(size int) Buffer

NewSize returns a new buffer with an initial capacity.

type Writer

type Writer interface {
	// WriteByte writes a byte to the buffer.
	WriteByte(c byte) error

	// WriteRune writes a rune to the buffer.
	WriteRune(r rune) (n int, err error)

	// WriteString writes a string to the buffer.
	WriteString(s string) (n int, err error)
}

Writer specifies additional methods for writing to a buffer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL