buffer

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: MIT Imports: 11 Imported by: 5

Documentation

Overview

Example (Index)
for _, i := range [...]int{64, 128, 192, 256, 257} {
	fmt.Println(i, "=", index(i))
}
Output:


64 = 0
128 = 1
192 = 2
256 = 2
257 = 3
Example (RoundPow)
for _, i := range [...]int{0, 1, 2, 64, 128, 192, 256, 257} {
	fmt.Println(i, "=", roundPow(i))
}
Output:


0 = 1
1 = 1
2 = 2
64 = 64
128 = 128
192 = 256
256 = 256
257 = 512

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrNegativeCount = errors.New("negative count")
	ErrInvalidValue  = errors.New("invalid value")
	ErrFewArgs       = errors.New("too few arguments")
)

Functions

This section is empty.

Types

type Buffer

type Buffer struct {
	B []byte
}

A byte buffer, highly optimized to minimize allocations and GC pressure.

func NewBuffer

func NewBuffer(size int) *Buffer

func (*Buffer) Bytes

func (b *Buffer) Bytes() []byte

func (*Buffer) Cap

func (b *Buffer) Cap() int

func (*Buffer) Grow

func (b *Buffer) Grow(n int) error

Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics.

func (*Buffer) Len

func (b *Buffer) Len() int

func (*Buffer) ReadFrom

func (b *Buffer) ReadFrom(r io.Reader) (int64, error)

ReadFrom implements io.ReaderFrom.

func (*Buffer) Reset

func (b *Buffer) Reset()

func (*Buffer) Str added in v0.16.0

func (b *Buffer) Str() StringBuffer

func (*Buffer) String

func (b *Buffer) String() string

WriteString implements fmt.Stringer.

func (*Buffer) Write

func (b *Buffer) Write(p []byte) (n int, err error)

Write implements io.Writer.

func (*Buffer) WriteByte

func (b *Buffer) WriteByte(c byte) error

WriteByte implements io.ByteWriter.

func (*Buffer) WriteString

func (b *Buffer) WriteString(s string) (n int, err error)

WriteString implements io.StringWriter.

func (*Buffer) WriteTo

func (b *Buffer) WriteTo(w io.Writer) (int64, error)

type Pool

type Pool struct {
	// contains filtered or unexported fields
}

Pool represents byte buffer pool.

Distinct pools may be used for distinct types of byte buffers. Properly determined byte buffer types with their own pools may help reducing memory waste.

func (*Pool) Get

func (p *Pool) Get() *Buffer

Get returns new byte buffer with zero length.

The byte buffer may be returned to the pool via Put after the use in order to minimize GC overhead.

func (*Pool) Put

func (p *Pool) Put(b *Buffer)

Put releases byte buffer obtained via Get to the pool.

The buffer mustn't be accessed after returning to the pool.

type StringBuffer added in v0.16.0

type StringBuffer struct {
	B *Buffer
}
Example
buf := NewBuffer(64)

buf.Str().WritefCb("hello %s", []any{123}, func(b *Buffer, c byte, v any) error {
	b.WriteString("world")
	return nil
})
Output:

TODO

func (StringBuffer) WriteBool added in v0.16.0

func (b StringBuffer) WriteBool(v bool)

func (StringBuffer) WriteFloat32 added in v0.16.0

func (b StringBuffer) WriteFloat32(val float32)

Write float32

func (StringBuffer) WriteFloat32Lossy added in v0.16.0

func (b StringBuffer) WriteFloat32Lossy(val float32)

Write float32 with ONLY 6 digits precision although much much faster

func (StringBuffer) WriteFloat64 added in v0.16.0

func (b StringBuffer) WriteFloat64(val float64)

Write float64

func (StringBuffer) WriteFloat64Lossy added in v0.16.0

func (b StringBuffer) WriteFloat64Lossy(val float64)

Write float64 with ONLY 6 digits precision although much much faster

func (StringBuffer) WriteInt added in v0.16.0

func (b StringBuffer) WriteInt(val int)

Write int

func (StringBuffer) WriteInt16 added in v0.16.0

func (b StringBuffer) WriteInt16(nval int16)

Write int16

func (StringBuffer) WriteInt32 added in v0.16.0

func (b StringBuffer) WriteInt32(nval int32)

Write int32

func (StringBuffer) WriteInt64 added in v0.16.0

func (b StringBuffer) WriteInt64(nval int64)

Write int64

func (StringBuffer) WriteInt8 added in v0.16.0

func (b StringBuffer) WriteInt8(nval int8)

Write int8

func (StringBuffer) WriteString added in v0.16.0

func (b StringBuffer) WriteString(str string)

func (StringBuffer) WriteUint added in v0.16.0

func (b StringBuffer) WriteUint(val uint)

Write uint

func (StringBuffer) WriteUint16 added in v0.16.0

func (b StringBuffer) WriteUint16(val uint16)

Write uint16

func (StringBuffer) WriteUint32 added in v0.16.0

func (b StringBuffer) WriteUint32(val uint32)

Write uint32

func (StringBuffer) WriteUint64 added in v0.16.0

func (b StringBuffer) WriteUint64(val uint64)

Write uint64

func (StringBuffer) WriteUint8 added in v0.16.0

func (b StringBuffer) WriteUint8(val uint8)

Write uint8

func (StringBuffer) WriteVal added in v0.16.0

func (b StringBuffer) WriteVal(val any) (err error)

func (StringBuffer) Writef added in v0.16.0

func (b StringBuffer) Writef(format string, args ...any)

func (StringBuffer) WritefCb added in v0.16.0

func (b StringBuffer) WritefCb(format string, args []any, cb func(b *Buffer, c byte, v any) error) (err error)

Jump to

Keyboard shortcuts

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