bytebuf

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 13 Imported by: 3

README

Byte buffers

Collection of various byte buffer implementations.

Chain buffer

A wrapper around []byte slice that supports chain write methods. Example of usage:

import "github.com/koykov/bytebuf"

var buf bytebuf.Chain
b := buf.Write([]byte("foo")).
    WriteString("bar").
    WriteByte('@').
    WriteInt(-123).
    WriteUint(123).
    WriteFloat(3.1415).
    WriteBool(true).
    WriteRune('X').
    WriteFormat("pre%dpost", 15)
    WriteX(1.23456).
    Bytes()
println(string(b)) // [email protected]

The same operations may be proceeded using append()/AppendInt()/... functions around []byte slice, but Chain provides handy API for that.

Chain buffer may be reused using internal pool. To get instance of the buffer from the pool call AcquireChain function. To put buffer back to the pool call ReleaseChain function.

Accumulative buffer

A wrapper around Chain buffer with "staked" features. The main idea is to accumulate (bufferize) various data and provide handy access to chunks of buffered data. Example of usage:

import "github.com/koykov/bytebuf"

var (
    buf bytebuf.Chain
    msg protobuf.ExampleMessage
)
chunk0 := buf.WriteMarshallerTo(&msg).Bytes()
chunk1 := buf.StakeOut().Write([]byte("foo")).
    WriteString("bar").
    WriteByte('@').
    WriteInt(-123).
    WriteUint(123).
    WriteFloat(3.1415).
    WriteBool(true).
    WriteRune('X').
    WriteFormat("pre%dpost", 15)
    WriteX(1.23456).
    StakedBytes()
println(string(chunk0)) // h�����,����?�ihttps
println(string(chunk1)) // [email protected]

Thus, one buffer may be used to bufferize multiple data and hence reduce pointers in application.

Accumulative buffer may be reused using internal pool. To get instance of the buffer from the pool call AcquireAccumulative function. To put buffer back to the pool call ReleaseAccumulative function.

Pools

Both Chain and Accumulative buffers are using internal pools to reduce memory allocations.

Usage:

cbuf := bytebuf.AcquireChain()
defer bytebuf.ReleaseChain(cbuf)
cbuf.WriteString("foo")
...

abuf := bytebuf.AcquireAccumulative()
defer bytebuf.ReleaseAccumulative(abuf)
abuf.WriteString("foo")
...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AccumulativeToBytes added in v1.0.5

func AccumulativeToBytes(dst []byte, val any, _ ...any) ([]byte, error)

AccumulativeToBytes registers x2bytes conversion function accepts Accumulative.

func ChainToBytes added in v1.0.5

func ChainToBytes(dst []byte, val any, _ ...any) ([]byte, error)

ChainToBytes registers x2bytes conversion function accepts Chain.

func ReleaseAccumulative added in v1.0.7

func ReleaseAccumulative(buf *Accumulative)

ReleaseAccumulative puts Accumulative buffer instance to the pool.

func ReleaseChain added in v1.0.7

func ReleaseChain(buf *Chain)

ReleaseChain puts Chain buffer instance to the pool.

Types

type AccBufWriter added in v1.0.4

type AccBufWriter = AccumulativeWriter

AccBufWriter is an alias of AccumulativeWriter type. DEPRECATED: use AccumulativeWriter instead. Kept for backward compatibility.

type Accumulative added in v1.0.5

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

Accumulative is a wrapper around Chain that allows to accumulate buffer data and use only necessary part.

See StakeOut and Staked* methods.

func AcquireAccumulative added in v1.0.7

func AcquireAccumulative() *Accumulative

AcquireAccumulative gets Accumulative buffer instance from the pool.

func NewAccumulative added in v1.0.7

func NewAccumulative(buf []byte) *Accumulative

NewAccumulative creates and initializes a new accumulative buffer instance using buf as its initial contents.

func NewAccumulativeSize added in v1.0.7

func NewAccumulativeSize(size int) *Accumulative

NewAccumulativeSize creates new accumulative buffer and initializes byte slice as an internal buffer.

func (*Accumulative) Bytes added in v1.0.5

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

Bytes returns contents of the buffer.

func (*Accumulative) BytesCopy added in v1.0.5

func (b *Accumulative) BytesCopy() []byte

BytesCopy returns copy of buffer contents.

func (*Accumulative) Cap added in v1.0.5

func (b *Accumulative) Cap() int

func (*Accumulative) Error added in v1.0.5

func (b *Accumulative) Error() error

Get last error caught in Write* methods.

func (*Accumulative) Grow added in v1.0.5

func (b *Accumulative) Grow(newLen int) *Accumulative

Grow increases length of the buffer.

func (*Accumulative) GrowDelta added in v1.0.5

func (b *Accumulative) GrowDelta(delta int) *Accumulative

GrowDelta increases length of the buffer to actual length + delta.

See Grow().

func (*Accumulative) Len added in v1.0.5

func (b *Accumulative) Len() int

func (*Accumulative) RangeBytes added in v1.0.5

func (b *Accumulative) RangeBytes(off, len int) []byte

RangeBytes returns buffer bytes from offset off with length len.

func (*Accumulative) RangeBytesCopy added in v1.0.5

func (b *Accumulative) RangeBytesCopy(off, len int) []byte

RangeBytesCopy copies result of RangeBytes().

func (*Accumulative) RangeString added in v1.0.5

func (b *Accumulative) RangeString(off, len int) string

RangeString returns buffer bytes as string from offset off with length len.

func (*Accumulative) RangeStringCopy added in v1.0.5

func (b *Accumulative) RangeStringCopy(off, len int) string

RangeStringCopy copies result of RangeString().

func (*Accumulative) Reduce added in v1.0.7

func (b *Accumulative) Reduce(delta int) *Accumulative

func (*Accumulative) Replace added in v1.0.5

func (b *Accumulative) Replace(old, new []byte, n int) *Accumulative

Replace replaces old bytes to new in buffer.

func (*Accumulative) ReplaceAll added in v1.0.5

func (b *Accumulative) ReplaceAll(old, new []byte) *Accumulative

ReplaceAll replace all occurrences of old bytes to new in buffer.

func (*Accumulative) ReplaceStr added in v1.0.5

func (b *Accumulative) ReplaceStr(old, new string, n int) *Accumulative

ReplaceStr replace old to new substrings in buffer. DEPRECATED: use ReplaceString() instead.

func (*Accumulative) ReplaceStrAll added in v1.0.5

func (b *Accumulative) ReplaceStrAll(old, new string) *Accumulative

ReplaceStrAll replaces all occurrences of old substrings to new in buffer. DEPRECATED: use ReplaceStringAll() instead.

func (*Accumulative) ReplaceString added in v1.0.5

func (b *Accumulative) ReplaceString(old, new string, n int) *Accumulative

ReplaceString replace old to new substrings in buffer.

func (*Accumulative) ReplaceStringAll added in v1.0.5

func (b *Accumulative) ReplaceStringAll(old, new string) *Accumulative

ReplaceStringAll replaces all occurrences of old substrings to new in buffer.

func (*Accumulative) Reset added in v1.0.5

func (b *Accumulative) Reset() *Accumulative

func (*Accumulative) StackedByteptr added in v1.1.0

func (b *Accumulative) StackedByteptr() (p byteptr.Byteptr)

StackedByteptr returns byteptr wrapper for stacked bytes.

func (*Accumulative) StackedEntry16 added in v1.1.0

func (b *Accumulative) StackedEntry16() (e entry.Entry16)

StackedEntry16 returns Entry16 encoded lo/hi offsets of stacked bytes.

func (*Accumulative) StackedEntry32 added in v1.1.0

func (b *Accumulative) StackedEntry32() (e entry.Entry32)

StackedEntry32 returns Entry32 encoded lo/hi offsets of stacked bytes.

func (*Accumulative) StackedEntry64 added in v1.1.0

func (b *Accumulative) StackedEntry64() (e entry.Entry64)

StackedEntry64 returns Entry64 encoded lo/hi offsets of stacked bytes.

func (*Accumulative) StakeOut added in v1.0.5

func (b *Accumulative) StakeOut() *Accumulative

StakeOut saves current offset for further use.

func (*Accumulative) StakedBytes added in v1.0.5

func (b *Accumulative) StakedBytes() []byte

StakedBytes returns accumulated bytes from staked offset.

func (*Accumulative) StakedBytesCopy added in v1.0.5

func (b *Accumulative) StakedBytesCopy() []byte

StakedBytesCopy returns copy of accumulated bytes since staked offset.

func (*Accumulative) StakedLen added in v1.0.5

func (b *Accumulative) StakedLen() int

StakedLen returns length of accumulated bytes since staked offset.

func (*Accumulative) StakedOffset added in v1.0.5

func (b *Accumulative) StakedOffset() int

StakedOffset returns staked offset.

func (*Accumulative) StakedString added in v1.0.5

func (b *Accumulative) StakedString() string

StakedString returns accumulated bytes as string.

func (*Accumulative) StakedStringCopy added in v1.0.5

func (b *Accumulative) StakedStringCopy() string

StakedStringCopy returns copy of accumulated bytes as string.

func (*Accumulative) String added in v1.0.5

func (b *Accumulative) String() string

Get contents of the buffer as string.

func (*Accumulative) StringCopy added in v1.0.5

func (b *Accumulative) StringCopy() string

StringCopy returns copy of the buffer contents as string.

func (*Accumulative) ToWriter added in v1.0.5

func (b *Accumulative) ToWriter() *AccumulativeWriter

ToWriter wraps buffer with class implementing IO interfaces.

func (*Accumulative) Write added in v1.0.5

func (b *Accumulative) Write(p []byte) *Accumulative

Write bytes to the buffer.

func (*Accumulative) WriteApplyFn added in v1.0.5

func (b *Accumulative) WriteApplyFn(p []byte, fn func(dst, p []byte) []byte) *Accumulative

WriteApplyFn applies fn to p and write result to the buffer.

func (*Accumulative) WriteApplyFnIf added in v1.0.6

func (b *Accumulative) WriteApplyFnIf(cond bool, p []byte, fn func(dst, p []byte) []byte) *Accumulative

func (*Accumulative) WriteApplyFnN added in v1.0.8

func (b *Accumulative) WriteApplyFnN(p []byte, fn func(dst, p []byte) []byte, n int) *Accumulative

WriteApplyFnN applies fn to p N times and write result to the buffer.

func (*Accumulative) WriteApplyFnNIf added in v1.0.8

func (b *Accumulative) WriteApplyFnNIf(cond bool, p []byte, fn func(dst, p []byte) []byte, n int) *Accumulative

func (*Accumulative) WriteApplyFnNString added in v1.0.8

func (b *Accumulative) WriteApplyFnNString(s string, fn func(dst, p []byte) []byte, n int) *Accumulative

WriteApplyFnNString applies fn to s and write result to the buffer.

func (*Accumulative) WriteApplyFnNStringIf added in v1.0.8

func (b *Accumulative) WriteApplyFnNStringIf(cond bool, s string, fn func(dst, p []byte) []byte, n int) *Accumulative

func (*Accumulative) WriteApplyFnStr added in v1.0.5

func (b *Accumulative) WriteApplyFnStr(s string, fn func(dst, p []byte) []byte) *Accumulative

WriteApplyFnStr applies fn to s and write result to the buffer. DEPRECATED: use WriteApplyFnString() instead.

func (*Accumulative) WriteApplyFnString added in v1.0.5

func (b *Accumulative) WriteApplyFnString(s string, fn func(dst, p []byte) []byte) *Accumulative

WriteApplyFnString applies fn to s and write result to the buffer.

func (*Accumulative) WriteApplyFnStringIf added in v1.0.6

func (b *Accumulative) WriteApplyFnStringIf(cond bool, s string, fn func(dst, p []byte) []byte) *Accumulative

func (*Accumulative) WriteBinary added in v1.1.2

func (b *Accumulative) WriteBinary(order binary.ByteOrder, x any) *Accumulative

WriteBinary writes binary representation of x with arbitrary type to the buffer in given byte order.

func (*Accumulative) WriteBinaryIf added in v1.1.2

func (b *Accumulative) WriteBinaryIf(cond bool, order binary.ByteOrder, x any) *Accumulative

func (*Accumulative) WriteBinaryN added in v1.1.2

func (b *Accumulative) WriteBinaryN(order binary.ByteOrder, x any, n int) *Accumulative

WriteBinaryN writes binary representation of x to buffer N times. See WriteBinary.

func (*Accumulative) WriteBool added in v1.0.5

func (b *Accumulative) WriteBool(v bool) *Accumulative

WriteBool writes boolean value to the buffer.

func (*Accumulative) WriteBoolIf added in v1.0.6

func (b *Accumulative) WriteBoolIf(cond bool, v bool) *Accumulative

func (*Accumulative) WriteBoolN added in v1.0.9

func (b *Accumulative) WriteBoolN(v bool, n int) *Accumulative

WriteBoolN writes v to buffer N times. See WriteBool.

func (*Accumulative) WriteByte added in v1.0.5

func (b *Accumulative) WriteByte(p byte) *Accumulative

WriteByte writes single byte.

func (*Accumulative) WriteByteIf added in v1.0.6

func (b *Accumulative) WriteByteIf(cond bool, p byte) *Accumulative

func (*Accumulative) WriteByteN added in v1.0.9

func (b *Accumulative) WriteByteN(p byte, n int) *Accumulative

WriteByteN writes p to buffer N times. See WriteByte.

func (*Accumulative) WriteFloat added in v1.0.5

func (b *Accumulative) WriteFloat(f float64) *Accumulative

WriteFloat writes float value to the buffer.

func (*Accumulative) WriteFloatIf added in v1.0.6

func (b *Accumulative) WriteFloatIf(cond bool, f float64) *Accumulative

func (*Accumulative) WriteFloatN added in v1.0.9

func (b *Accumulative) WriteFloatN(f float64, n int) *Accumulative

WriteFloatN writes f to buffer N times. See WriteFloat.

func (*Accumulative) WriteFormat added in v1.1.0

func (b *Accumulative) WriteFormat(format string, args ...any) *Accumulative

WriteFormat writes formatted string to the buffer.

func (*Accumulative) WriteIf added in v1.0.6

func (b *Accumulative) WriteIf(cond bool, p []byte) *Accumulative

func (*Accumulative) WriteInt added in v1.0.5

func (b *Accumulative) WriteInt(i int64) *Accumulative

WriteInt writes integer value to the buffer.

func (*Accumulative) WriteIntBase added in v1.0.7

func (b *Accumulative) WriteIntBase(i int64, base int) *Accumulative

WriteIntBase writes integer value in given base to the buffer.

func (*Accumulative) WriteIntBaseN added in v1.0.9

func (b *Accumulative) WriteIntBaseN(i int64, base, n int) *Accumulative

WriteIntBaseN writes i to buffer N times. See WriteIntBase.

func (*Accumulative) WriteIntIf added in v1.0.6

func (b *Accumulative) WriteIntIf(cond bool, i int64) *Accumulative

func (*Accumulative) WriteIntN added in v1.0.9

func (b *Accumulative) WriteIntN(i int64, n int) *Accumulative

WriteIntN writes i to buffer N times. See WriteInt.

func (*Accumulative) WriteMarshallerTo added in v1.0.5

func (b *Accumulative) WriteMarshallerTo(m MarshallerTo) *Accumulative

WriteMarshallerTo marshal data of struct implemented MarshallerTo interface and write it to the buffer.

func (*Accumulative) WriteMarshallerToIf added in v1.0.6

func (b *Accumulative) WriteMarshallerToIf(cond bool, m MarshallerTo) *Accumulative

func (*Accumulative) WriteN added in v1.0.9

func (b *Accumulative) WriteN(p []byte, n int) *Accumulative

WriteN writes p to buffer N times. See Write.

func (*Accumulative) WriteRune added in v1.1.0

func (b *Accumulative) WriteRune(r rune) *Accumulative

WriteRune writes rune to the buffer.

func (*Accumulative) WriteSLEB128 added in v1.1.2

func (b *Accumulative) WriteSLEB128(v int64) *Accumulative

WriteSLEB128 writes signed LEB128 representation of int64 value to the buffer.

func (*Accumulative) WriteSLEB128If added in v1.1.2

func (b *Accumulative) WriteSLEB128If(cond bool, v int64) *Accumulative

func (*Accumulative) WriteSLEB128N added in v1.1.2

func (b *Accumulative) WriteSLEB128N(v int64, n int) *Accumulative

WriteSLEB128N writes signed LEB128 representation of uint64 value to buffer N times. See WriteSLEB128.

func (*Accumulative) WriteStr added in v1.0.5

func (b *Accumulative) WriteStr(s string) *Accumulative

WriteStr writes string to the buffer. DEPRECATED: use WriteString() instead.

func (*Accumulative) WriteString added in v1.0.5

func (b *Accumulative) WriteString(s string) *Accumulative

WriteString writes string to the buffer.

func (*Accumulative) WriteStringIf added in v1.0.6

func (b *Accumulative) WriteStringIf(cond bool, s string) *Accumulative

func (*Accumulative) WriteStringN added in v1.0.9

func (b *Accumulative) WriteStringN(s string, n int) *Accumulative

WriteStringN writes s to buffer N times. See WriteString.

func (*Accumulative) WriteTime added in v1.0.7

func (b *Accumulative) WriteTime(format string, t time.Time) *Accumulative

WriteTime writes time t in given format to the buffer.

func (*Accumulative) WriteTimeIf added in v1.0.7

func (b *Accumulative) WriteTimeIf(cond bool, format string, t time.Time) *Accumulative

func (*Accumulative) WriteTimeN added in v1.1.2

func (b *Accumulative) WriteTimeN(format string, t time.Time, n int) *Accumulative

WriteTimeN writes time in given format to buffer N times. See WriteTime.

func (*Accumulative) WriteULEB128 added in v1.1.2

func (b *Accumulative) WriteULEB128(v uint64) *Accumulative

WriteULEB128 writes unsigned LEB128 representation of uint64 value to the buffer.

func (*Accumulative) WriteULEB128If added in v1.1.2

func (b *Accumulative) WriteULEB128If(cond bool, v uint64) *Accumulative

func (*Accumulative) WriteULEB128N added in v1.1.2

func (b *Accumulative) WriteULEB128N(v uint64, n int) *Accumulative

WriteULEB128N writes unsigned LEB128 representation of uint64 value to buffer N times. See WriteULEB128.

func (*Accumulative) WriteUint added in v1.0.5

func (b *Accumulative) WriteUint(u uint64) *Accumulative

WriteUint writes unsigned integer value to the buffer.

func (*Accumulative) WriteUintBase added in v1.0.7

func (b *Accumulative) WriteUintBase(u uint64, base int) *Accumulative

WriteUintBase writes unsigned integer value in given base to the buffer.

func (*Accumulative) WriteUintBaseN added in v1.0.9

func (b *Accumulative) WriteUintBaseN(u uint64, base, n int) *Accumulative

WriteUintBaseN writes u to buffer N times. See WriteUintBase.

func (*Accumulative) WriteUintIf added in v1.0.6

func (b *Accumulative) WriteUintIf(cond bool, u uint64) *Accumulative

func (*Accumulative) WriteUintN added in v1.0.9

func (b *Accumulative) WriteUintN(u uint64, n int) *Accumulative

WriteUintN writes u to buffer N times. See WriteUint.

func (*Accumulative) WriteX added in v1.0.5

func (b *Accumulative) WriteX(x any) *Accumulative

WriteX write v with arbitrary type to the buffer.

func (*Accumulative) WriteXIf added in v1.0.6

func (b *Accumulative) WriteXIf(cond bool, x any) *Accumulative

func (*Accumulative) WriteXN added in v1.0.9

func (b *Accumulative) WriteXN(x any, n int) *Accumulative

WriteXN writes x to buffer N times. See WriteX.

type AccumulativeBuf

type AccumulativeBuf = Accumulative

AccumulativeBuf is an alias of Accumulative type. DEPRECATED: use Accumulative instead. Kept for backward compatibility.

type AccumulativeWriter added in v1.0.5

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

AccumulativeWriter is a wrapper around Accumulative that implements IO writers interfaces.

func (AccumulativeWriter) Bytes added in v1.0.6

func (w AccumulativeWriter) Bytes() []byte

func (AccumulativeWriter) Cap added in v1.0.6

func (w AccumulativeWriter) Cap() int

func (AccumulativeWriter) Len added in v1.0.6

func (w AccumulativeWriter) Len() int

func (AccumulativeWriter) Reset added in v1.0.6

func (w AccumulativeWriter) Reset()

func (AccumulativeWriter) String added in v1.0.6

func (w AccumulativeWriter) String() string

func (AccumulativeWriter) Write added in v1.0.5

func (w AccumulativeWriter) Write(p []byte) (int, error)

func (AccumulativeWriter) WriteApplyFn added in v1.0.6

func (w AccumulativeWriter) WriteApplyFn(p []byte, fn func(dst, p []byte) []byte) (int, error)

func (AccumulativeWriter) WriteApplyFnN added in v1.0.8

func (w AccumulativeWriter) WriteApplyFnN(p []byte, fn func(dst, p []byte) []byte, n int) (int, error)

func (AccumulativeWriter) WriteApplyFnNString added in v1.0.8

func (w AccumulativeWriter) WriteApplyFnNString(s string, fn func(dst, p []byte) []byte, n int) (int, error)

func (AccumulativeWriter) WriteApplyFnString added in v1.0.6

func (w AccumulativeWriter) WriteApplyFnString(s string, fn func(dst, p []byte) []byte) (int, error)

func (AccumulativeWriter) WriteBinary added in v1.1.2

func (w AccumulativeWriter) WriteBinary(order binary.ByteOrder, x any) (int, error)

func (AccumulativeWriter) WriteBool added in v1.0.6

func (w AccumulativeWriter) WriteBool(b bool) (int, error)

func (AccumulativeWriter) WriteByte added in v1.0.5

func (w AccumulativeWriter) WriteByte(b byte) error

func (AccumulativeWriter) WriteFloat added in v1.0.6

func (w AccumulativeWriter) WriteFloat(f float64) (int, error)

func (AccumulativeWriter) WriteInt added in v1.0.6

func (w AccumulativeWriter) WriteInt(i int64) (int, error)

func (AccumulativeWriter) WriteMarshallerTo added in v1.0.6

func (w AccumulativeWriter) WriteMarshallerTo(m MarshallerTo) (int, error)

func (AccumulativeWriter) WriteSLEB128 added in v1.1.2

func (w AccumulativeWriter) WriteSLEB128(v int64) (int, error)

func (AccumulativeWriter) WriteString added in v1.0.5

func (w AccumulativeWriter) WriteString(s string) (int, error)

func (AccumulativeWriter) WriteTime added in v1.1.2

func (w AccumulativeWriter) WriteTime(format string, t time.Time) (int, error)

func (AccumulativeWriter) WriteULEB128 added in v1.1.2

func (w AccumulativeWriter) WriteULEB128(v uint64) (int, error)

func (AccumulativeWriter) WriteUint added in v1.0.6

func (w AccumulativeWriter) WriteUint(u uint64) (int, error)

func (AccumulativeWriter) WriteX added in v1.0.6

func (w AccumulativeWriter) WriteX(x any) (int, error)

type Chain added in v1.0.5

type Chain []byte

Chain is a primitive byte buffer with chain call support.

func AcquireChain added in v1.0.7

func AcquireChain() *Chain

AcquireChain gets Chain buffer instance from the pool.

func NewChain added in v1.0.7

func NewChain(buf []byte) *Chain

NewChain creates and initializes a new chain buffer instance using buf as its initial contents.

func NewChainSize added in v1.0.7

func NewChainSize(size int) *Chain

NewChainSize creates new chain buffer and initializes byte slice as an internal buffer.

func (*Chain) Bytes added in v1.0.5

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

Bytes returns contents of the buffer.

func (*Chain) BytesCopy added in v1.0.5

func (b *Chain) BytesCopy() []byte

BytesCopy returns copy of the buffer.

func (*Chain) Cap added in v1.0.5

func (b *Chain) Cap() int

func (*Chain) Grow added in v1.0.5

func (b *Chain) Grow(newLen int) *Chain

Grow increases length of the buffer.

func (*Chain) GrowDelta added in v1.0.5

func (b *Chain) GrowDelta(delta int) *Chain

GrowDelta increases length of the buffer to actual length + delta.

See Grow().

func (*Chain) Len added in v1.0.5

func (b *Chain) Len() int

func (*Chain) Reduce added in v1.0.7

func (b *Chain) Reduce(delta int) *Chain

Reduce decreases buffer length to delta.

func (*Chain) Replace added in v1.0.5

func (b *Chain) Replace(old, new []byte, n int) *Chain

Replace replaces old bytes to new in buffer.

func (*Chain) ReplaceAll added in v1.0.5

func (b *Chain) ReplaceAll(old, new []byte) *Chain

ReplaceAll replace all occurrences of old bytes to new in buffer.

func (*Chain) ReplaceStr added in v1.0.5

func (b *Chain) ReplaceStr(old, new string, n int) *Chain

ReplaceStr replace old to new substrings in buffer. DEPRECATED: use ReplaceString() instead.

func (*Chain) ReplaceStrAll added in v1.0.5

func (b *Chain) ReplaceStrAll(old, new string) *Chain

ReplaceStrAll replaces all occurrences of old substrings to new in buffer. DEPRECATED: use ReplaceStringAll() instead.

func (*Chain) ReplaceString added in v1.0.5

func (b *Chain) ReplaceString(old, new string, n int) *Chain

ReplaceString replace old to new substrings in buffer.

func (*Chain) ReplaceStringAll added in v1.0.5

func (b *Chain) ReplaceStringAll(old, new string) *Chain

ReplaceStringAll replaces all occurrences of old substrings to new in buffer.

func (*Chain) Reset added in v1.0.5

func (b *Chain) Reset() *Chain

func (*Chain) String added in v1.0.5

func (b *Chain) String() string

Get contents of the buffer as string.

func (*Chain) StringCopy added in v1.0.5

func (b *Chain) StringCopy() string

StringCopy returns copy of the buffer contents as string.

func (*Chain) ToWriter added in v1.1.2

func (b *Chain) ToWriter() *ChainWriter

ToWriter wraps buffer with class implementing IO interfaces.

func (*Chain) Write added in v1.0.5

func (b *Chain) Write(p []byte) *Chain

Write bytes to the buffer.

func (*Chain) WriteApplyFn added in v1.0.5

func (b *Chain) WriteApplyFn(p []byte, fn func(dst, p []byte) []byte) *Chain

WriteApplyFn applies fn to p and write result to the buffer.

func (*Chain) WriteApplyFnIf added in v1.0.6

func (b *Chain) WriteApplyFnIf(cond bool, p []byte, fn func(dst, p []byte) []byte) *Chain

func (*Chain) WriteApplyFnN added in v1.0.8

func (b *Chain) WriteApplyFnN(p []byte, fn func(dst, p []byte) []byte, n int) *Chain

WriteApplyFnN applies fn to p N times and write result to the buffer.

func (*Chain) WriteApplyFnNIf added in v1.0.8

func (b *Chain) WriteApplyFnNIf(cond bool, p []byte, fn func(dst, p []byte) []byte, n int) *Chain

func (*Chain) WriteApplyFnNString added in v1.0.8

func (b *Chain) WriteApplyFnNString(s string, fn func(dst, p []byte) []byte, n int) *Chain

WriteApplyFnNString applies fn to s N times and write result to the buffer.

func (*Chain) WriteApplyFnNStringIf added in v1.0.8

func (b *Chain) WriteApplyFnNStringIf(cond bool, s string, fn func(dst, p []byte) []byte, n int) *Chain

func (*Chain) WriteApplyFnStr added in v1.0.5

func (b *Chain) WriteApplyFnStr(s string, fn func(dst, p []byte) []byte) *Chain

WriteApplyFnStr applies fn to s and write result to the buffer. DEPRECATED: use WriteApplyFnString() instead.

func (*Chain) WriteApplyFnString added in v1.0.5

func (b *Chain) WriteApplyFnString(s string, fn func(dst, p []byte) []byte) *Chain

WriteApplyFnString applies fn to s and write result to the buffer.

func (*Chain) WriteApplyFnStringIf added in v1.0.6

func (b *Chain) WriteApplyFnStringIf(cond bool, s string, fn func(dst, p []byte) []byte) *Chain

func (*Chain) WriteBinary added in v1.1.2

func (b *Chain) WriteBinary(order binary.ByteOrder, x any) *Chain

WriteBinary writes binary representation of x with arbitrary type to the buffer in given byte order.

func (*Chain) WriteBinaryIf added in v1.1.2

func (b *Chain) WriteBinaryIf(cond bool, order binary.ByteOrder, x any) *Chain

func (*Chain) WriteBinaryN added in v1.1.2

func (b *Chain) WriteBinaryN(order binary.ByteOrder, x any, n int) *Chain

WriteBinaryN writes x to buffer N times. See WriteBinary.

func (*Chain) WriteBool added in v1.0.5

func (b *Chain) WriteBool(v bool) *Chain

WriteBool writes boolean value to the buffer.

func (*Chain) WriteBoolIf added in v1.0.6

func (b *Chain) WriteBoolIf(cond bool, v bool) *Chain

func (*Chain) WriteBoolN added in v1.0.9

func (b *Chain) WriteBoolN(v bool, n int) *Chain

WriteBoolN writes v to buffer N times. See WriteBool.

func (*Chain) WriteByte added in v1.0.5

func (b *Chain) WriteByte(p byte) *Chain

WriteByte writes single byte.

func (*Chain) WriteByteIf added in v1.0.6

func (b *Chain) WriteByteIf(cond bool, p byte) *Chain

func (*Chain) WriteByteN added in v1.0.9

func (b *Chain) WriteByteN(p byte, n int) *Chain

WriteByteN writes p to buffer N times. See WriteByte.

func (*Chain) WriteFloat added in v1.0.5

func (b *Chain) WriteFloat(f float64) *Chain

WriteFloat writes float value to the buffer.

func (*Chain) WriteFloatIf added in v1.0.6

func (b *Chain) WriteFloatIf(cond bool, f float64) *Chain

func (*Chain) WriteFloatN added in v1.0.9

func (b *Chain) WriteFloatN(f float64, n int) *Chain

WriteFloatN writes f to buffer N times. See WriteFloat.

func (*Chain) WriteFormat added in v1.1.0

func (b *Chain) WriteFormat(format string, args ...any) *Chain

WriteFormat writes formatted string to the buffer.

func (*Chain) WriteIf added in v1.0.6

func (b *Chain) WriteIf(cond bool, p []byte) *Chain

func (*Chain) WriteInt added in v1.0.5

func (b *Chain) WriteInt(i int64) *Chain

WriteInt writes integer value to the buffer.

func (*Chain) WriteIntBase added in v1.0.7

func (b *Chain) WriteIntBase(i int64, base int) *Chain

WriteIntBase writes integer value in given base to the buffer.

func (*Chain) WriteIntBaseIf added in v1.0.7

func (b *Chain) WriteIntBaseIf(cond bool, i int64, base int) *Chain

func (*Chain) WriteIntBaseN added in v1.0.9

func (b *Chain) WriteIntBaseN(i int64, base, n int) *Chain

WriteIntBaseN writes i to buffer N times. See WriteIntBase.

func (*Chain) WriteIntIf added in v1.0.6

func (b *Chain) WriteIntIf(cond bool, i int64) *Chain

func (*Chain) WriteIntN added in v1.0.9

func (b *Chain) WriteIntN(i int64, n int) *Chain

WriteIntN writes i to buffer N times. See WriteInt.

func (*Chain) WriteMarshallerTo added in v1.0.5

func (b *Chain) WriteMarshallerTo(m MarshallerTo) *Chain

WriteMarshallerTo marshal data of struct implemented MarshallerTo interface and write it to the buffer.

func (*Chain) WriteMarshallerToIf added in v1.0.6

func (b *Chain) WriteMarshallerToIf(cond bool, m MarshallerTo) *Chain

func (*Chain) WriteN added in v1.0.9

func (b *Chain) WriteN(p []byte, n int) *Chain

WriteN writes p to buffer N times. See Write.

func (*Chain) WriteRune added in v1.1.0

func (b *Chain) WriteRune(r rune) *Chain

WriteRune writes rune to the buffer.

func (*Chain) WriteSLEB128 added in v1.1.2

func (b *Chain) WriteSLEB128(v int64) *Chain

WriteSLEB128 writes signed LEB128 representation of int64 value.

func (*Chain) WriteSLEB128If added in v1.1.2

func (b *Chain) WriteSLEB128If(cond bool, v int64) *Chain

func (*Chain) WriteSLEB128N added in v1.1.2

func (b *Chain) WriteSLEB128N(v int64, n int) *Chain

WriteSLEB128N writes signed LEB128 representation of uint64 value to buffer N times. See WriteSLEB128.

func (*Chain) WriteStr added in v1.0.5

func (b *Chain) WriteStr(s string) *Chain

WriteStr writes string to the buffer. DEPRECATED: use WriteString() instead.

func (*Chain) WriteString added in v1.0.5

func (b *Chain) WriteString(s string) *Chain

WriteString writes string to the buffer.

func (*Chain) WriteStringIf added in v1.0.6

func (b *Chain) WriteStringIf(cond bool, s string) *Chain

func (*Chain) WriteStringN added in v1.0.9

func (b *Chain) WriteStringN(s string, n int) *Chain

WriteStringN writes s to buffer N times. See WriteString.

func (*Chain) WriteTime added in v1.0.7

func (b *Chain) WriteTime(format string, t time.Time) *Chain

WriteTime writes time t in given format to the buffer.

func (*Chain) WriteTimeIf added in v1.0.7

func (b *Chain) WriteTimeIf(cond bool, format string, t time.Time) *Chain

func (*Chain) WriteTimeN added in v1.1.2

func (b *Chain) WriteTimeN(format string, t time.Time, n int) *Chain

WriteTimeN writes time in given format to buffer N times. See WriteTime.

func (*Chain) WriteULEB128 added in v1.1.2

func (b *Chain) WriteULEB128(v uint64) *Chain

WriteULEB128 writes unsigned LEB128 representation of uint64 value.

func (*Chain) WriteULEB128If added in v1.1.2

func (b *Chain) WriteULEB128If(cond bool, v uint64) *Chain

func (*Chain) WriteULEB128N added in v1.1.2

func (b *Chain) WriteULEB128N(v uint64, n int) *Chain

WriteULEB128N writes unsigned LEB128 representation of uint64 value to buffer N times. See WriteULEB128.

func (*Chain) WriteUint added in v1.0.5

func (b *Chain) WriteUint(u uint64) *Chain

WriteUint writes unsigned integer value to the buffer.

func (*Chain) WriteUintBase added in v1.0.7

func (b *Chain) WriteUintBase(u uint64, base int) *Chain

WriteUintBase writes unsigned integer value in given base to the buffer.

func (*Chain) WriteUintBaseIf added in v1.0.7

func (b *Chain) WriteUintBaseIf(cond bool, u uint64, base int) *Chain

func (*Chain) WriteUintBaseN added in v1.0.9

func (b *Chain) WriteUintBaseN(u uint64, base, n int) *Chain

WriteUintBaseN writes u to buffer N times. See WriteUintBase.

func (*Chain) WriteUintIf added in v1.0.6

func (b *Chain) WriteUintIf(cond bool, u uint64) *Chain

func (*Chain) WriteUintN added in v1.0.9

func (b *Chain) WriteUintN(u uint64, n int) *Chain

WriteUintN writes u to buffer N times. See WriteUint.

func (*Chain) WriteX added in v1.0.5

func (b *Chain) WriteX(x any) *Chain

WriteX write x with arbitrary type to the buffer.

func (*Chain) WriteXIf added in v1.0.6

func (b *Chain) WriteXIf(cond bool, x any) *Chain

func (*Chain) WriteXN added in v1.0.9

func (b *Chain) WriteXN(x any, n int) *Chain

WriteXN writes x to buffer N times. See WriteX.

type ChainBuf

type ChainBuf = Chain

ChainBuf is an alias of Chain type. DEPRECATED: use Chain instead. Kept for backward compatibility.

type ChainWriter added in v1.1.2

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

ChainWriter is a wrapper around Chain that implements IO writers interfaces.

func (ChainWriter) Bytes added in v1.1.2

func (w ChainWriter) Bytes() []byte

func (ChainWriter) Cap added in v1.1.2

func (w ChainWriter) Cap() int

func (ChainWriter) Len added in v1.1.2

func (w ChainWriter) Len() int

func (ChainWriter) Reset added in v1.1.2

func (w ChainWriter) Reset()

func (ChainWriter) String added in v1.1.2

func (w ChainWriter) String() string

func (ChainWriter) Write added in v1.1.2

func (w ChainWriter) Write(p []byte) (int, error)

func (ChainWriter) WriteApplyFn added in v1.1.2

func (w ChainWriter) WriteApplyFn(p []byte, fn func(dst, p []byte) []byte) (int, error)

func (ChainWriter) WriteApplyFnN added in v1.1.2

func (w ChainWriter) WriteApplyFnN(p []byte, fn func(dst, p []byte) []byte, n int) (int, error)

func (ChainWriter) WriteApplyFnNString added in v1.1.2

func (w ChainWriter) WriteApplyFnNString(s string, fn func(dst, p []byte) []byte, n int) (int, error)

func (ChainWriter) WriteApplyFnString added in v1.1.2

func (w ChainWriter) WriteApplyFnString(s string, fn func(dst, p []byte) []byte) (int, error)

func (ChainWriter) WriteBinary added in v1.1.2

func (w ChainWriter) WriteBinary(order binary.ByteOrder, x any) (int, error)

func (ChainWriter) WriteBool added in v1.1.2

func (w ChainWriter) WriteBool(b bool) (int, error)

func (ChainWriter) WriteByte added in v1.1.2

func (w ChainWriter) WriteByte(b byte) error

func (ChainWriter) WriteFloat added in v1.1.2

func (w ChainWriter) WriteFloat(f float64) (int, error)

func (ChainWriter) WriteInt added in v1.1.2

func (w ChainWriter) WriteInt(i int64) (int, error)

func (ChainWriter) WriteMarshallerTo added in v1.1.2

func (w ChainWriter) WriteMarshallerTo(m MarshallerTo) (int, error)

func (ChainWriter) WriteSLEB128 added in v1.1.2

func (w ChainWriter) WriteSLEB128(v int64) (int, error)

func (ChainWriter) WriteString added in v1.1.2

func (w ChainWriter) WriteString(s string) (int, error)

func (ChainWriter) WriteTime added in v1.1.2

func (w ChainWriter) WriteTime(format string, t time.Time) (int, error)

func (ChainWriter) WriteULEB128 added in v1.1.2

func (w ChainWriter) WriteULEB128(v uint64) (int, error)

func (ChainWriter) WriteUint added in v1.1.2

func (w ChainWriter) WriteUint(u uint64) (int, error)

func (ChainWriter) WriteX added in v1.1.2

func (w ChainWriter) WriteX(x any) (int, error)

type MarshallerTo

type MarshallerTo interface {
	Size() int
	MarshalTo([]byte) (int, error)
}

MarshallerTo interface to write struct like Protobuf.

Jump to

Keyboard shortcuts

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