pack

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pack is the compact binary encoding the library snapshot is written in: a string table, then a body of varint-packed scalars and string indices.

Index

Constants

This section is empty.

Variables

View Source
var ErrCorrupt = errors.New("pack: corrupt stream")

ErrCorrupt reports a stream that does not decode: a truncated body, an index past a table, or a length past the end of the data.

Functions

This section is empty.

Types

type Arena

type Arena[T any] struct {
	// contains filtered or unexported fields
}

Arena hands out slices of T carved from larger chunks, so that decoding many small slices costs a few allocations rather than one each. A slice's capacity is its length, so appending to one never overwrites its neighbour.

func (*Arena[T]) Take

func (a *Arena[T]) Take(n int) []T

Take returns a zeroed slice of n elements, or nil for n == 0.

type Reader

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

Reader decodes a stream written by Writer. A malformed stream sets a sticky error and later reads return zero values, so a caller checks Err at the end.

func NewReader

func NewReader(data []byte) (*Reader, error)

NewReader parses the string table of data and positions the reader at the body. The table's strings are substrings of one copy of the table's bytes.

func (*Reader) Bool

func (r *Reader) Bool() bool

Bool reads one byte.

func (*Reader) Done

func (r *Reader) Done() bool

Done reports whether the whole stream has been read without error.

func (*Reader) Err

func (r *Reader) Err() error

Err reports the first malformation met, or nil.

func (*Reader) Fail

func (r *Reader) Fail(what string)

Fail records a malformation the caller found in the decoded values, such as an index past a table it built.

func (*Reader) Float

func (r *Reader) Float() float64

Float reads a little-endian IEEE-754 value.

func (*Reader) Int

func (r *Reader) Int() int64

Int reads a signed varint.

func (*Reader) Len

func (r *Reader) Len() int

Len reads a slice length or count. A length beyond the bytes left is corrupt, since every element takes at least one byte.

func (*Reader) Section

func (r *Reader) Section() *Reader

Section returns a Reader over the next length-prefixed section, which the receiver skips; the two keep separate errors and may be read concurrently.

func (*Reader) String

func (r *Reader) String() string

String reads a string-table index.

func (*Reader) Uint

func (r *Reader) Uint() uint64

Uint reads an unsigned varint.

type Writer

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

Writer accumulates a stream. Strings are interned into the table as they are written, so a stream's bytes depend only on the sequence of writes.

func NewWriter

func NewWriter() *Writer

NewWriter returns an empty Writer.

func (*Writer) Bool

func (w *Writer) Bool(b bool)

Bool writes one byte.

func (*Writer) Bytes

func (w *Writer) Bytes() []byte

Bytes returns the stream: the string table (count, each length, the joined bytes) followed by the body.

func (*Writer) Float

func (w *Writer) Float(f float64)

Float writes the IEEE-754 bits of f, little-endian.

func (*Writer) Int

func (w *Writer) Int(v int64)

Int writes a signed varint (zigzag).

func (*Writer) Len

func (w *Writer) Len(n int)

Len writes a slice length or a count.

func (*Writer) Section

func (w *Writer) Section(write func(*Writer))

Section writes what write produces as a length-prefixed section, which a Reader can decode apart from the rest; it shares the string table.

func (*Writer) String

func (w *Writer) String(s string)

String writes s as its string-table index, interning it on first use.

func (*Writer) Uint

func (w *Writer) Uint(v uint64)

Uint writes an unsigned varint.

Jump to

Keyboard shortcuts

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