Documentation
¶
Overview ¶
Package pack is the compact binary encoding the library snapshot is written in: a string table, then varint-packed scalars and string indices, one stream per kind so gzip sees like values together.
Index ¶
- Variables
- type Arena
- type Reader
- func (r *Reader) Bool() bool
- func (r *Reader) Done() bool
- func (r *Reader) Err() error
- func (r *Reader) Fail(what string)
- func (r *Reader) Float() float64
- func (r *Reader) Int() int64
- func (r *Reader) Len() int
- func (r *Reader) Section() *Reader
- func (r *Reader) String() string
- func (r *Reader) Uint() uint64
- type Writer
Constants ¶
This section is empty.
Variables ¶
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.
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 ¶
NewReader parses the string table of data and the lengths of the body's streams. The table's strings are substrings of one copy of the table's bytes.
func (*Reader) Fail ¶
Fail records a malformation the caller found in the decoded values, such as an index past a table it built.
func (*Reader) Len ¶
Len reads a slice length or count. A length beyond the bytes left is corrupt, since every element takes at least one byte.
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 NewDiscard ¶ added in v0.13.0
func NewDiscard() *Writer
NewDiscard returns a Writer that keeps nothing it is given, for a caller that runs an encoder only to learn what it visits.
func (*Writer) Bytes ¶
Bytes returns the stream: the string table (count, each length, the joined bytes) followed by the body (each stream's length, then the streams).
func (*Writer) Section ¶
Section writes what write produces as a section, which a Reader can decode apart from the rest; it shares the string table and is led by the lengths of its streams.