buffer

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package buffer implements a buffer for serialization, consisting of a chain of []byte-s to reduce copying and to allow reuse of individual chunks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(cfg PoolConfig)

Init sets up a non-default pooling and allocation strategy. Should be run before serialization is done.

Types

type Buffer

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

Buffer is a buffer optimized for serialization without extra copying.

func (*Buffer) AppendByte

func (b *Buffer) AppendByte(data byte)

AppendByte appends a single byte to buffer.

func (*Buffer) AppendBytes

func (b *Buffer) AppendBytes(data []byte)

AppendBytes appends a byte slice to buffer.

func (*Buffer) AppendFloat32 added in v0.8.6

func (b *Buffer) AppendFloat32(f float32, dataSize int)

func (*Buffer) AppendFloat64 added in v0.8.6

func (b *Buffer) AppendFloat64(f float64, dataSize int)

func (*Buffer) AppendInt added in v0.8.6

func (b *Buffer) AppendInt(n int64, dataSize int)

func (*Buffer) AppendString

func (b *Buffer) AppendString(data string)

func (*Buffer) AppendUint added in v0.8.6

func (b *Buffer) AppendUint(n uint64, dataSize int)

func (*Buffer) BuildBytes

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

func (*Buffer) Close added in v0.8.4

func (b *Buffer) Close() error

func (*Buffer) DumpTo

func (b *Buffer) DumpTo(w io.Writer) (int, error)

DumpTo outputs the contents of a buffer to a writer and resets the buffer.

func (*Buffer) EnsureSpace

func (b *Buffer) EnsureSpace(s int)

EnsureSpace makes sure that the current chunk contains at least s free bytes, possibly creating a new chunk.

func (*Buffer) Size

func (b *Buffer) Size() int

Size computes the size of a buffer by adding sizes of every chunk.

type PoolConfig

type PoolConfig struct {
	PooledSize int // Minimum chunk size that is reused, reusing chunks too small will result in overhead.
}

PoolConfig contains configuration for the allocation and reuse strategy.

Jump to

Keyboard shortcuts

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