zcode

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2020 License: BSD-3-Clause Imports: 4 Imported by: 0

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 unset, 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 (
	ErrNotContainer = errors.New("not a container")
	ErrNotSingleton = errors.New("not a single container")
)

Functions

func AppendUvarint

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

AppendUvarint is like encoding/binary.PutUvarint but appends to dst instead of writing into it.

func DecodeCountedUvarint

func DecodeCountedUvarint(b []byte) uint64

func DecodeCountedVarint

func DecodeCountedVarint(b []byte) int64

func EncodeCountedUvarint

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

func EncodeCountedVarint

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

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) AppendContainer

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

AppendContainer appends val as a container value.

func (*Builder) AppendPrimitive

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

AppendPrimitive appends val as a primitive value.

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) Reset

func (b *Builder) Reset()

Reset resets the Builder to be empty.

func (*Builder) TransformContainer added in v0.2.0

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.

type Bytes

type Bytes []byte

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

func AppendContainer

func AppendContainer(dst Bytes, val Bytes) Bytes

AppendContainer appends val to dst as a container value and returns the extended buffer.

func AppendPrimitive

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

AppendPrimitive appends val to dst as a primitive value and returns the extended buffer.

func (Bytes) ContainerBody

func (b Bytes) ContainerBody() (Bytes, error)

ContainerBody returns the body of the receiver, which must hold a single container. If the receiver is not a container, ErrNotContainer is returned. If the receiver is not a single container, ErrNotSingleton is returned.

func (Bytes) Iter

func (b Bytes) Iter() Iter

Iter returns an Iter for the receiver.

func (Bytes) String

func (b Bytes) String() string

String returns a string representation of 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, bool, error)

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 an unset value.

func (*Iter) NextTagAndBody added in v0.2.0

func (i *Iter) NextTagAndBody() (Bytes, bool, error)

NextTagAndBody returns the next value as a slice containing the value's undecoded tag followed by its body along with a boolean that is true if the value is a container.

Jump to

Keyboard shortcuts

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