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, whose DecodeError.LimitKind names the bound; spec §4.2).
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 DecodeWithLimits ¶
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 ¶
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
// LimitKind names the bound that stopped decoding when Code is "limit_exceeded",
// and is empty for every other code. It is observational: it identifies the check
// that stopped this decode, and another implementation may name a different
// bound for the same input (spec §4.2). An empty or unrecognized kind carries no
// more than the generic "limit_exceeded".
LimitKind DecodeLimitKind
}
DecodeError carries a cross-language rejection Code (docs/spec/ontos-codec.md §4). The five byte-contract codes (unexpected_eof, unknown_tag, non_canonical_uvarint, uvarint_overflow, trailing_bytes) are normative and pinned by vectors/codec.json. "limit_exceeded" is different: it reports that decoding stopped at an operational bound, so it is not vector-pinned and says nothing about whether the input is a valid encoding. For it, LimitKind names the bound responsible (spec §4.2). The Message is diagnostic only.
Construct a DecodeError with field names. Since LimitKind was added (ontos-internal#352), an unkeyed composite literal such as DecodeError{code, msg} no longer compiles.
func (*DecodeError) Error ¶
func (e *DecodeError) Error() string
type DecodeLimitKind ¶
type DecodeLimitKind string
DecodeLimitKind names an operational decode bound (docs/spec/ontos-codec.md §4.2). The vocabulary is append-only: a name never changes meaning, but a later version may add names, so a switch over it needs a default case.
const ( // LimitDecodeDepth: the value about to be read is nested deeper than // Limits.MaxDepth, counting the root as depth 0. LimitDecodeDepth DecodeLimitKind = "decode_depth" // LimitAtomBytes: a declared atom byte length exceeds Limits.MaxAtomBytes. LimitAtomBytes DecodeLimitKind = "atom_bytes" // LimitTupleArity: a declared tuple arity exceeds Limits.MaxTupleArity. LimitTupleArity DecodeLimitKind = "tuple_arity" // LimitNativeWidth: a valid uvarint length or arity does not fit in Go's int // (above 2^63-1, or 2^31-1 on a 32-bit build). LimitNativeWidth DecodeLimitKind = "native_width" )
type Limits ¶
Limits bounds decoding of untrusted input. Operational policy, not value semantics. Every field is enforced exactly as given, so a zero field is a bound of zero, not a request for the default: Limits{} admits only an empty atom or an empty tuple at the root. Start from DefaultLimits and override the fields you mean to set.