Documentation
¶
Index ¶
- type Buf
- func (b *Buf) Bytes() []byte
- func (b *Buf) Cap() int
- func (b *Buf) Get(position int64) (byte, error)
- func (b *Buf) IncrementPosition(numBytes int64)
- func (b *Buf) Len() int
- func (b *Buf) Peek(n int) ([]byte, error)
- func (b *Buf) Position() int64
- func (b *Buf) Read(p []byte) (n int, err error)
- func (b *Buf) ReadByte() (byte, error)
- func (b *Buf) Reset()
- func (b *Buf) SetPosition(position int64)
- func (b *Buf) Write(p []byte) (n int, err error)
- func (b *Buf) WriteBuf(bb *Buf) (n int, err error)
- func (b *Buf) WriteByte(c byte) error
- type BufPosition
- type BufReadonly
- func (br *BufReadonly) Bytes() []byte
- func (br *BufReadonly) Get(position int64) (byte, error)
- func (br *BufReadonly) IncrementPosition(numBytes int64)
- func (br *BufReadonly) Len() int
- func (br *BufReadonly) Peek(n int) ([]byte, error)
- func (br *BufReadonly) Position() int64
- func (br *BufReadonly) Read(p []byte) (n int, err error)
- func (br *BufReadonly) ReadByte() (byte, error)
- func (br *BufReadonly) SetPosition(position int64)
- type Read
- type Write
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buf ¶
type Buf struct {
// contains filtered or unexported fields
}
Buf is a dynamically-sized byte buffer, wrapping a []byte. It manages its own position, logical length, and capacity growth.
func (*Buf) Bytes ¶
Bytes returns a slice of all logical bytes currently in the buffer. The returned slice is valid until the next write operation that might cause reallocation.
func (*Buf) Get ¶
Get returns the byte at the given absolute position in the buffer, without advancing the current position. Position is relative to the start of the buffer's logical content.
func (*Buf) IncrementPosition ¶
IncrementPosition increments the current position by numBytes.
func (*Buf) Peek ¶
Peek returns the next n bytes from the current position without advancing the reader. The returned slice shares the underlying array of the buffer. If n is larger than the available bytes, Peek returns all available bytes.
func (*Buf) Read ¶
Read reads up to len(p) bytes into p from the current position. It returns the number of bytes read and any error encountered. EOF is returned when no more bytes are available from the current position within the logical length.
func (*Buf) ReadByte ¶
ReadByte reads and returns the next byte from the current position. If no byte is available, it returns error io.EOF.
func (*Buf) Reset ¶
func (b *Buf) Reset()
Reset resets the buffer to be empty, but it retains the underlying storage for use by future writes by slicing data to zero length. Reset also resets the position and logical length to 0.
func (*Buf) SetPosition ¶
SetPosition sets the current position in the buffer. No bounds checking is performed on the position value itself, but subsequent operations (Read/Write) will handle boundaries.
func (*Buf) Write ¶
Write writes len(p) bytes from p to the buffer at the current position. It returns the number of bytes written and any error encountered. If the write extends beyond the current logical length, the buffer's logical length is updated. If the write starts beyond the current logical length, the gap is filled with zeros.
type BufPosition ¶
type BufPosition interface {
Position() int64
SetPosition(position int64)
IncrementPosition(numBytes int64)
}
BufPosition defines an interface for types that track a position.
type BufReadonly ¶
type BufReadonly struct {
// contains filtered or unexported fields
}
BufReadonly is a read-only wrapper around a byte slice. It's analogous to TypeScript's BufReadonly class.
func NewBufReadonly ¶
func NewBufReadonly(data []byte) *BufReadonly
NewBufReadonly creates a new BufReadonly wrapping the given byte slice. The provided slice is used directly and should not be modified externally if read-only behavior is to be guaranteed.
func (*BufReadonly) Bytes ¶
func (br *BufReadonly) Bytes() []byte
Bytes returns all bytes in the buffer, regardless of position.
func (*BufReadonly) Get ¶
func (br *BufReadonly) Get(position int64) (byte, error)
Get returns the byte at the given absolute position in the buffer, without advancing the current position.
func (*BufReadonly) IncrementPosition ¶
func (br *BufReadonly) IncrementPosition(numBytes int64)
IncrementPosition increments the current position by numBytes.
func (*BufReadonly) Len ¶
func (br *BufReadonly) Len() int
Len returns the total length of the underlying byte slice.
func (*BufReadonly) Peek ¶
func (br *BufReadonly) Peek(n int) ([]byte, error)
Peek returns the next n bytes without advancing the reader. If n is negative, an error is returned. If n is 0, Peek returns an empty slice and no error. If the buffer's read position is out of bounds (negative or >= len(br.bytes)), it returns (nil, io.EOF). If n is larger than the available bytes from br.pos, Peek returns all available bytes and no error.
func (*BufReadonly) Position ¶
func (br *BufReadonly) Position() int64
Position returns the current position in the buffer.
func (*BufReadonly) Read ¶
func (br *BufReadonly) Read(p []byte) (n int, err error)
Read reads up to len(p) bytes into p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered. If the buffer's read position is negative, it returns (0, io.EOF).
func (*BufReadonly) ReadByte ¶
func (br *BufReadonly) ReadByte() (byte, error)
ReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error io.EOF. If the buffer's read position is negative, it returns (0, io.EOF).
func (*BufReadonly) SetPosition ¶
func (br *BufReadonly) SetPosition(position int64)
SetPosition sets the current position in the buffer.
type Read ¶
type Read interface {
BufPosition
io.Reader
io.ByteReader
Get(position int64) (byte, error)
Bytes() []byte
Len() int
Peek(n int) ([]byte, error)
}
Read defines an interface for readable buffers.
type Write ¶
type Write interface {
BufPosition
io.Writer
io.ByteWriter
Cap() int
}
Write defines an interface for writable buffers.