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 ¶
- Variables
- func AppendCountedUvarint(dst []byte, u64 uint64) []byte
- func AppendCountedVarint(dst []byte, i int64) []byte
- func DecodeCountedUvarint(b []byte) uint64
- func DecodeCountedVarint(b []byte) int64
- func DecodeTagLength(b Bytes) int
- func EncodeCountedUvarint(dst []byte, u64 uint64) uint
- func EncodeCountedVarint(dst []byte, i int64) uint
- func ReadTag(r io.ByteReader) (int, error)
- func SizeOfUvarint(u64 uint64) int
- type Builder
- type Bytes
- type Iter
Constants ¶
This section is empty.
Variables ¶
var ErrNotSingleton = errors.New("value body has more than one encoded value")
Functions ¶
func AppendCountedUvarint ¶
func AppendCountedVarint ¶
func DecodeCountedUvarint ¶
func DecodeCountedVarint ¶
func DecodeTagLength ¶ added in v1.0.0
func EncodeCountedUvarint ¶
func EncodeCountedVarint ¶
func SizeOfUvarint ¶ added in v1.0.0
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 (*Builder) BeginContainer ¶
func (b *Builder) BeginContainer()
BeginContainer opens a new container.
func (*Builder) 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 ¶
Grow guarantees that at least n bytes can be added to the Builder's underlying buffer without another allocation.
func (*Builder) TransformContainer ¶
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.
type Iter ¶
type Iter Bytes
Iter iterates over the sequence of values encoded in Bytes.
func (*Iter) Next ¶
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 ¶
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.