codec

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: Apache-2.0 Imports: 2 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 codec is the ontos canonical binary codec — ontos-codec-v1 (frozen).

Atom(bytes)   = 0x00 || uvarint(len(bytes)) || bytes
Tuple(values) = 0x01 || uvarint(arity)      || encode(each child)

uvarint is unsigned LEB128 in shortest/canonical form over the u64 domain [0, 2^64-1] (spec: docs/spec/ontos-codec.md §3.1). The decoder rejects unknown tags, trailing bytes, non-canonical uvarints, uvarints whose value is >= 2^64 (uvarint_overflow), and inputs exceeding the configured safety limits or this implementation's native materialization width (limit_exceeded).

This codec is kept beside the model (it imports core, never the reverse). Conformance is pinned by vectors/codec.json (codec id: ontos-codec-v1) and specified normatively in docs/spec/ontos-codec.md.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(input []byte) (core.Value, error)

Decode decodes one value with default limits, rejecting trailing bytes.

func DecodeWithLimits

func DecodeWithLimits(input []byte, limits Limits) (core.Value, error)

DecodeWithLimits decodes one value with explicit limits, rejecting trailing bytes.

func Encode

func Encode(v core.Value) []byte

Encode returns the canonical ontos-codec-v1 bytes of v.

func EncodeUvarint

func EncodeUvarint(n int) []byte

EncodeUvarint returns the shortest-form LEB128 encoding of n. It is part of the public codec API (the canonical uvarint exposed for callers and pinned by the uvarint conformance vectors); the encoder internals use the private appendUvarint.

Types

type DecodeError

type DecodeError struct {
	Code    string
	Message string
}

DecodeError carries a stable, cross-language rejection Code (matching vectors/codec.json). The Message is diagnostic only.

func (*DecodeError) Error

func (e *DecodeError) Error() string

type Limits

type Limits struct {
	MaxDepth      int
	MaxAtomBytes  int
	MaxTupleArity int
}

Limits bounds decoding of untrusted input. Operational policy, not value semantics. A zero value means "use defaults"; use DefaultLimits for clarity.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns the standard decode limits.

Jump to

Keyboard shortcuts

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