Documentation
¶
Index ¶
- type Buffer
- type Bytes
- func (b *Bytes) Available() int
- func (b *Bytes) Bytes() []byte
- func (b *Bytes) Cap() int
- func (b *Bytes) Delay(delay int)
- func (b *Bytes) Len() int
- func (b *Bytes) Nodes() int
- func (b *Bytes) Prepend(size int) []byte
- func (b *Bytes) Release()
- func (b *Bytes) Resize(size int) bool
- func (b *Bytes) Slide(delta int) bool
- func (b *Bytes) Truncate(size int) bool
- func (b *Bytes) VisitBytes(fn func(bytes []byte) bool) bool
- type BytesPool
- type NocopyBuffer
- func (b *NocopyBuffer) Bytes() []byte
- func (b *NocopyBuffer) Delay(delay int)
- func (b *NocopyBuffer) Len() int
- func (b *NocopyBuffer) MallocBytes(cap int, whence ...Whence) *Bytes
- func (b *NocopyBuffer) MallocWriter(cap int, whence ...Whence) *Writer
- func (b *NocopyBuffer) Mount(block any, whence ...Whence)
- func (b *NocopyBuffer) Nodes() int
- func (b *NocopyBuffer) Release()
- func (b *NocopyBuffer) Slice(lower, upper int) []byte
- func (b *NocopyBuffer) Slide(delta int) bool
- func (b *NocopyBuffer) VisitBytes(fn func(bytes []byte) bool) bool
- func (b *NocopyBuffer) VisitNodes(fn func(node *NocopyNode) bool) bool
- type NocopyNode
- type Reader
- func (r *Reader) ReadBool() (bool, error)
- func (r *Reader) ReadBools(n int) ([]bool, error)
- func (r *Reader) ReadByte() (byte, error)
- func (r *Reader) ReadBytes(n int) ([]byte, error)
- func (r *Reader) ReadFloat32(order binary.ByteOrder) (float32, error)
- func (r *Reader) ReadFloat32s(order binary.ByteOrder, n int) ([]float32, error)
- func (r *Reader) ReadFloat64(order binary.ByteOrder) (float64, error)
- func (r *Reader) ReadFloat64s(order binary.ByteOrder, n int) ([]float64, error)
- func (r *Reader) ReadInt8() (int8, error)
- func (r *Reader) ReadInt8s(n int) ([]int8, error)
- func (r *Reader) ReadInt16(order binary.ByteOrder) (int16, error)
- func (r *Reader) ReadInt16s(order binary.ByteOrder, n int) ([]int16, error)
- func (r *Reader) ReadInt32(order binary.ByteOrder) (int32, error)
- func (r *Reader) ReadInt32s(order binary.ByteOrder, n int) ([]int32, error)
- func (r *Reader) ReadInt64(order binary.ByteOrder) (int64, error)
- func (r *Reader) ReadInt64s(order binary.ByteOrder, n int) ([]int64, error)
- func (r *Reader) ReadRune(order binary.ByteOrder) (rune, error)
- func (r *Reader) ReadRunes(order binary.ByteOrder, n int) ([]rune, error)
- func (r *Reader) ReadString(len int) (string, error)
- func (r *Reader) ReadUint8() (uint8, error)
- func (r *Reader) ReadUint8s(n int) ([]uint8, error)
- func (r *Reader) ReadUint16(order binary.ByteOrder) (uint16, error)
- func (r *Reader) ReadUint16s(order binary.ByteOrder, n int) ([]uint16, error)
- func (r *Reader) ReadUint32(order binary.ByteOrder) (uint32, error)
- func (r *Reader) ReadUint32s(order binary.ByteOrder, n int) ([]uint32, error)
- func (r *Reader) ReadUint64(order binary.ByteOrder) (uint64, error)
- func (r *Reader) ReadUint64s(order binary.ByteOrder, n int) ([]uint64, error)
- func (r *Reader) Reset()
- func (r *Reader) Seek(offset int64, whence int) (int64, error)
- type Whence
- type Writer
- func (w *Writer) Available() int
- func (w *Writer) Bytes() []byte
- func (w *Writer) Cap() int
- func (w *Writer) Delay(delay int)
- func (w *Writer) Grow(n int)
- func (w *Writer) Len() int
- func (w *Writer) Nodes() int
- func (w *Writer) Release()
- func (w *Writer) Slide(delta int) bool
- func (w *Writer) VisitBytes(fn func(bytes []byte) bool) bool
- func (w *Writer) Write(p []byte) (n int, err error)
- func (w *Writer) WriteBools(values ...bool)
- func (w *Writer) WriteBytes(values ...byte)
- func (w *Writer) WriteFloat32s(order binary.ByteOrder, values ...float32)
- func (w *Writer) WriteFloat64s(order binary.ByteOrder, values ...float64)
- func (w *Writer) WriteInt8s(values ...int8)
- func (w *Writer) WriteInt16s(order binary.ByteOrder, values ...int16)
- func (w *Writer) WriteInt32s(order binary.ByteOrder, values ...int32)
- func (w *Writer) WriteInt64s(order binary.ByteOrder, values ...int64)
- func (w *Writer) WriteRunes(order binary.ByteOrder, values ...rune)
- func (w *Writer) WriteString(str string)
- func (w *Writer) WriteUint8s(values ...uint8)
- func (w *Writer) WriteUint16s(order binary.ByteOrder, values ...uint16)
- func (w *Writer) WriteUint32s(order binary.ByteOrder, values ...uint32)
- func (w *Writer) WriteUint64s(order binary.ByteOrder, values ...uint64)
- type WriterPool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer interface {
// Len returns the byte length.
Len() int
// Nodes returns the number of nodes.
Nodes() int
// Delay sets the delayed release point.
Delay(delay int)
// Bytes returns all bytes. It is relatively slow and not recommended.
Bytes() []byte
// Release releases the buffer.
Release()
// Slide slides the lower index.
Slide(lower int) bool
// VisitBytes iterates over all bytes.
VisitBytes(fn func(bytes []byte) bool) bool
}
type Bytes ¶ added in v2.4.0
type Bytes struct {
// contains filtered or unexported fields
}
Bytes is a byte buffer.
func MallocBytes ¶ added in v2.4.0
MallocBytes allocates a Bytes with the given capacity from the default byte pool.
func MallocBytesWithHeadroom ¶ added in v2.6.3
MallocBytesWithHeadroom allocates size readable bytes with reserved space before them.
func NewBytes ¶ added in v2.4.0
NewBytes creates a Bytes over buf. When static is true, the buffer is not returned to the pool on release.
func NewBytesWithCapacity ¶ added in v2.4.0
NewBytesWithCapacity creates a Bytes with the given capacity.
func (*Bytes) Prepend ¶ added in v2.6.3
Prepend exposes size bytes of reserved headroom and returns that prefix. It returns nil when the buffer is shared, its view has moved, or it does not have enough headroom.
func (*Bytes) Resize ¶ added in v2.6.5
Resize sets the readable length to size and reports false when size is out of range. The reserved headroom is kept intact so that a message header can still be prepended.
type BytesPool ¶ added in v2.4.0
type BytesPool struct {
// contains filtered or unexported fields
}
BytesPool is a byte buffer pool.
func NewBytesPool ¶ added in v2.4.0
NewBytesPool creates a byte pool with the given number of grades.
func NewBytesPoolWithCapacity ¶ added in v2.4.0
NewBytesPoolWithCapacity creates a byte pool whose maximum capacity fits cap.
func (*BytesPool) Get ¶ added in v2.4.0
Get returns a Bytes with the given capacity, or nil when no matching pool exists.
func (*BytesPool) GetWithHeadroom ¶ added in v2.6.3
GetWithHeadroom returns size readable bytes preceded by headroom reserved bytes, or nil when the arguments are invalid or no matching pool exists.
type NocopyBuffer ¶
type NocopyBuffer struct {
// contains filtered or unexported fields
}
NocopyBuffer is a zero-copy buffer.
func NewNocopyBuffer ¶
func NewNocopyBuffer(blocks ...any) *NocopyBuffer
NewNocopyBuffer creates a zero-copy buffer mounting the given blocks.
func (*NocopyBuffer) Delay ¶ added in v2.3.0
func (b *NocopyBuffer) Delay(delay int)
Delay sets the delayed release point.
func (*NocopyBuffer) MallocBytes ¶ added in v2.4.0
func (b *NocopyBuffer) MallocBytes(cap int, whence ...Whence) *Bytes
MallocBytes allocates a Bytes with the given capacity and mounts it.
func (*NocopyBuffer) MallocWriter ¶ added in v2.4.0
func (b *NocopyBuffer) MallocWriter(cap int, whence ...Whence) *Writer
MallocWriter allocates a Writer with the given capacity and mounts it.
func (*NocopyBuffer) Mount ¶
func (b *NocopyBuffer) Mount(block any, whence ...Whence)
Mount mounts block onto the buffer, at the head or tail according to whence.
func (*NocopyBuffer) Slice ¶ added in v2.6.3
func (b *NocopyBuffer) Slice(lower, upper int) []byte
Slice returns bytes in [lower, upper) without modifying the buffer. A range contained in one block aliases that block; a range spanning blocks is copied. Invalid ranges return nil.
func (*NocopyBuffer) Slide ¶ added in v2.6.0
func (b *NocopyBuffer) Slide(delta int) bool
Slide slides the lower index.
func (*NocopyBuffer) VisitBytes ¶ added in v2.6.0
func (b *NocopyBuffer) VisitBytes(fn func(bytes []byte) bool) bool
VisitBytes iterates over all bytes.
func (*NocopyBuffer) VisitNodes ¶ added in v2.6.0
func (b *NocopyBuffer) VisitNodes(fn func(node *NocopyNode) bool) bool
VisitNodes iterates over all nodes.
type NocopyNode ¶
type NocopyNode struct {
// contains filtered or unexported fields
}
NocopyNode is a zero-copy buffer node.
func (*NocopyNode) Bytes ¶
func (n *NocopyNode) Bytes() []byte
Bytes returns the byte data of the node.
func (*NocopyNode) Nodes ¶ added in v2.6.0
func (n *NocopyNode) Nodes() int
Nodes returns the number of nodes.
func (*NocopyNode) Slide ¶ added in v2.6.0
func (n *NocopyNode) Slide(delta int) bool
Slide consumes the given number of bytes.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader is a byte reader.
func (*Reader) ReadFloat32 ¶
ReadFloat32 reads a float32 value using order.
func (*Reader) ReadFloat32s ¶
ReadFloat32s reads n float32 values using order.
func (*Reader) ReadFloat64 ¶
ReadFloat64 reads a float64 value using order.
func (*Reader) ReadFloat64s ¶
ReadFloat64s reads n float64 values using order.
func (*Reader) ReadInt16s ¶
ReadInt16s reads n int16 values using order.
func (*Reader) ReadInt32s ¶
ReadInt32s reads n int32 values using order.
func (*Reader) ReadInt64s ¶
ReadInt64s reads n int64 values using order.
func (*Reader) ReadString ¶
ReadString reads a string of the given length.
func (*Reader) ReadUint8s ¶
ReadUint8s reads n uint8 values.
func (*Reader) ReadUint16 ¶
ReadUint16 reads a uint16 value using order.
func (*Reader) ReadUint16s ¶
ReadUint16s reads n uint16 values using order.
func (*Reader) ReadUint32 ¶
ReadUint32 reads a uint32 value using order.
func (*Reader) ReadUint32s ¶
ReadUint32s reads n uint32 values using order.
func (*Reader) ReadUint64 ¶
ReadUint64 reads a uint64 value using order.
func (*Reader) ReadUint64s ¶
ReadUint64s reads n uint64 values using order.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer is a byte writer.
func MallocWriter ¶ added in v2.4.0
MallocWriter allocates a Writer with the given capacity from the default writer pool.
func NewWriter ¶
NewWriter creates a Writer over buf. When static is true, the writer is not returned to the pool on release.
func NewWriterWithCapacity ¶ added in v2.4.0
NewWriterWithCapacity creates a Writer with the given capacity.
func (*Writer) VisitBytes ¶ added in v2.6.0
VisitBytes iterates over all bytes.
func (*Writer) WriteBools ¶
WriteBools writes the given bool values.
func (*Writer) WriteBytes ¶
WriteBytes writes the given bytes.
func (*Writer) WriteFloat32s ¶
WriteFloat32s writes the given float32 values using order.
func (*Writer) WriteFloat64s ¶
WriteFloat64s writes the given float64 values using order.
func (*Writer) WriteInt8s ¶
WriteInt8s writes the given int8 values.
func (*Writer) WriteInt16s ¶
WriteInt16s writes the given int16 values using order.
func (*Writer) WriteInt32s ¶
WriteInt32s writes the given int32 values using order.
func (*Writer) WriteInt64s ¶
WriteInt64s writes the given int64 values using order.
func (*Writer) WriteRunes ¶
WriteRunes writes the given rune values using order.
func (*Writer) WriteUint8s ¶
WriteUint8s writes the given uint8 values.
func (*Writer) WriteUint16s ¶
WriteUint16s writes the given uint16 values using order.
func (*Writer) WriteUint32s ¶
WriteUint32s writes the given uint32 values using order.
type WriterPool ¶
type WriterPool struct {
// contains filtered or unexported fields
}
WriterPool is a byte writer pool.
func NewWriterPool ¶
func NewWriterPool(grade int) *WriterPool
NewWriterPool creates a writer pool with the given number of grades.
func NewWriterPoolWithCapacity ¶ added in v2.4.0
func NewWriterPoolWithCapacity(cap int) *WriterPool
NewWriterPoolWithCapacity creates a writer pool whose maximum capacity fits cap.
func (*WriterPool) Get ¶
func (p *WriterPool) Get(cap int) *Writer
Get returns a Writer with the given capacity, or nil when no matching pool exists.