zcode

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: BSD-3-Clause Imports: 6 Imported by: 6

Documentation

Overview

Package zcode implements serialization and deserialzation for ZNG values.

Values of primitive type are represented by an unsigned integer tag and an optional byte-sequence body. A tag of zero indicates that the value is null, and no body follows. A nonzero tag indicates that the value is set, and the value itself follows as a body of length tag-1.

Values of union type are represented similarly, with the body prefixed by an integer specifying the index determining the type of the value in reference to the union type.

Values of container type (record, set, or array) are represented similarly, with the body containing a sequence of zero or more serialized values.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSingleton = errors.New("value body has more than one encoded value")

Functions

func AppendCountedUvarint

func AppendCountedUvarint(dst []byte, u64 uint64) []byte

func AppendCountedVarint

func AppendCountedVarint(dst []byte, i int64) []byte

func DecodeCountedUvarint

func DecodeCountedUvarint(b []byte) uint64

func DecodeCountedVarint

func DecodeCountedVarint(b []byte) int64

func DecodeTagLength added in v1.0.0

func DecodeTagLength(b Bytes) int

func EncodeCountedUvarint

func EncodeCountedUvarint(dst []byte, u64 uint64) uint

func EncodeCountedVarint

func EncodeCountedVarint(dst []byte, i int64) uint

func ReadTag added in v1.0.0

func ReadTag(r io.ByteReader) (int, error)

func SizeOfUvarint added in v1.0.0

func SizeOfUvarint(u64 uint64) int

SizeOfUvarint returns the number of bytes required by binary.AppendUvarint to represent u64.

Types

type Builder

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

Builder provides an efficient API for constructing nested ZNG values.

func NewBuilder

func NewBuilder() *Builder

NewBuilder returns a new Builder.

func (*Builder) Append added in v1.0.0

func (b *Builder) Append(val []byte)

Append appends val.

func (*Builder) BeginContainer

func (b *Builder) BeginContainer()

BeginContainer opens a new container.

func (*Builder) Bytes

func (b *Builder) Bytes() Bytes

Bytes returns the constructed value. It panics if the receiver has an open container.

func (*Builder) EndContainer

func (b *Builder) EndContainer()

EndContainer closes the most recently opened container. It panics if the receiver has no open container.

func (*Builder) Grow

func (b *Builder) Grow(n int)

Grow guarantees that at least n bytes can be added to the Builder's underlying buffer without another allocation.

func (*Builder) Reset

func (b *Builder) Reset()

Reset resets the Builder to be empty.

func (*Builder) TransformContainer

func (b *Builder) TransformContainer(transform func(Bytes) Bytes)

TransformContainer calls transform, passing it the body of the most recently opened container and replacing the original body with the return value. It panics if the receiver has no open container.

func (*Builder) Truncate added in v1.0.0

func (b *Builder) Truncate()

Truncate resets the Builder to be empty, but unlike Reset, it retains the storage returned by Bytes.

type Bytes

type Bytes []byte

Bytes is the serialized representation of a sequence of ZNG values.

func Append added in v1.0.0

func Append(dst Bytes, val []byte) Bytes

Append appends val to dst as a tagged value and returns the extended buffer.

func (Bytes) Body added in v1.0.0

func (b Bytes) Body() Bytes

Body returns b's body.

func (Bytes) Iter

func (b Bytes) Iter() Iter

Iter returns an Iter for the receiver.

type Iter

type Iter Bytes

Iter iterates over the sequence of values encoded in Bytes.

func (*Iter) Done

func (i *Iter) Done() bool

Done returns true if no values remain.

func (*Iter) Next

func (i *Iter) Next() Bytes

Next returns the body of the next value along with a boolean that is true if the value is a container. It returns an empty slice for an empty or zero-length value and nil for a Zed null value. The container boolean is not meaningful if the returned Bytes slice is nil. Next panics if the next value is malformed.

func (*Iter) NextTagAndBody

func (i *Iter) NextTagAndBody() Bytes

NextTagAndBody returns the next value as a slice containing the value's undecoded tag followed by its body. NextTagAndBody panics if the next value is malformed.

Jump to

Keyboard shortcuts

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