deixis

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2026 License: Apache-2.0 Imports: 7 Imported by: 3 modules, 1 package

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

deixis/core — finite keyed trees with one opaque value at every node.

Node[T] = T × FinMap[Bytes, Node[T]].

The payload carries no bounds. Equality is an optional caller-supplied relation over the entire T. A caller can choose an optional payload type; the core neither unwraps it nor assigns meaning to its absence tag. Own values and children are independent. Missing paths are distinct from existing nodes whose payload happens to be empty, null or an option. See docs/design/0010-mandatory-node-values.md, TREE.md and PATH.md. Parts, navigation and supplied equality are the public core; attachment, replacement, contexts, cuts and mapping are derivable through these parts.

Index

Constants

View Source
const AddressSpace = "dxl2"

AddressSpace is the address space of every deixis-codec-v2 address: "dxl2".

Variables

View Source
var ErrSlotCodecID = errors.New("deixis: not a well-formed v2 slot-codec-id")

ErrSlotCodecID is the local failure of an encoder handed a slot codec whose id is not a well-formed deixis-codec-v2 slot-codec-id of a defined form (§13). An encoder has no verdict channel (§2.1): it emits, or it fails with this.

Functions

func AppendCuvarint

func AppendCuvarint(dst []byte, v uint64) []byte

AppendCuvarint appends the cuvarint spelling of v to dst: unsigned LEB128 in its unique shortest form, at most ten octets.

func CheckClosure

func CheckClosure(root *Chunk, fetch Fetch, limits *Limits) error

CheckClosure is the closure-checker: every chunk reachable from root is present, matches the hash that reached it, is framed canonically, and carries root's slot-codec-id. It decodes no payload, so it never reports non_canonical_payload, and success certifies an opaque closure present — never a validated value (§15).

func EncodeFlat

func EncodeFlat[T any](n Node[T], c SlotCodec[T]) ([]byte, error)

EncodeFlat is the flat-encoder: the canonical dxf2 octets of n under the slot codec c. Every node's payload is c's encoding of its own value, framed by its length, and entries follow in ascending key order. It fails only locally, with ErrSlotCodecID, when c's id is not a well-formed id of a defined form.

func Flatten

func Flatten[T any](root *Chunk, fetch Fetch, registry Registry[T], limits *Limits) ([]byte, error)

Flatten is the bridge from the linked form to the flat one: the dxf2 artifact of the value the closure under root denotes, validated as Materialize validates it, within the explicit output budget limits.UnfoldedFlatOctets, which is checked against the DAG estimate before any octet is written. Payload octets are copied, not re-encoded: they were judged canonical.

func ReadCuvarint

func ReadCuvarint(b []byte) (uint64, int, error)

ReadCuvarint reads one cuvarint from the front of b, which is the whole remaining input, and returns its value and the number of octets it took. It enforces all three of §3's rules: an error is an *InvalidError with malformed_uvarint (more than ten octets, or input that ends while the continuation bit is set — §3 rule 2), uvarint_overflow, or non_shortest_uvarint; or unexpected_eof when b is empty.

Types

type Address

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

Address is a content address: the pair (address-space "dxl2", digest{32}), where the digest is the SHA-256 of a chunk's octets (§7). It is never a bare digest: the space travels with it in its String and in every constructor. Addresses are comparable.

Before v2 freezes a dxl2 address is not a stable identity (§16): a change to the candidate contract changes addresses.

func EncodeLinked

func EncodeLinked[T any](n Node[T], c SlotCodec[T]) (Address, map[Address][]byte, error)

EncodeLinked is the linked encoder: the address of n's root chunk under the slot codec c, and every chunk of n's closure by address, each once. Equal subtrees are one chunk, whatever the number of their occurrences. It fails only locally, with ErrSlotCodecID, when c's id is not a well-formed id of a defined form.

func NewAddress

func NewAddress(space string, digest []byte) (Address, error)

NewAddress is the address (space, digest). It fails unless space is "dxl2" and the digest is 32 octets.

func (Address) Digest

func (a Address) Digest() [32]byte

Digest is the SHA-256 digest.

func (Address) Space

func (a Address) Space() string

Space is the address space, "dxl2".

func (Address) String

func (a Address) String() string

String is "dxl2:" followed by the digest in lowercase hex.

type Child

type Child[T any] struct {
	Key  Key
	Tree DeixisNode[T]
}

Child binds an exact byte key to a complete child tree.

type Chunk

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

Chunk is one chunk of a linked closure: its octets verified against the address by which it was reached, and its framing judged canonical under §6 — links header and body. Its payload has been judged by no slot codec. A Chunk is immutable.

func ResolveRoot

func ResolveRoot(root Address, fetch Fetch, limits *Limits) (*Chunk, error)

ResolveRoot is resolve-root (§14): the chunk at the address the caller asks for, fetched, verified against that address, and framing-judged. It is the only place a caller's question enters a traversal, so it is what establishes that a closure is the value that was asked for.

A fault of the store is a *StoreError (missing_chunk, hash_mismatch); a fault of the octets is a Refusal. A nil limits means DefaultLimits.

A chunk's size is met when it is fetched, before the hash check and the parse (§12): chunk_octets, and — the root being the first chunk of any closure it anchors — its share of unique_chunks and unique_octets. No fault inside the chunk precedes them.

func (*Chunk) Address

func (c *Chunk) Address() Address

Address is the address this chunk was verified against.

func (*Chunk) Children

func (c *Chunk) Children() []ChunkEntry

Children is the entries in ascending key order, each key with the address its link names. Keys are copies. Nothing is fetched: ResolveChild is what verifies a child.

func (*Chunk) Keys

func (c *Chunk) Keys() [][]byte

Keys is the entries' keys in ascending order. Keys are copies.

func (*Chunk) Len

func (c *Chunk) Len() int

Len is the number of entries.

func (*Chunk) Payload

func (c *Chunk) Payload() []byte

Payload is the chunk's payload octets, framed but not decoded: no slot codec has judged them. The octets are a copy.

func (*Chunk) ResolveChild

func (c *Chunk) ResolveChild(key []byte, fetch Fetch, limits *Limits) (*Chunk, bool, error)

ResolveChild is resolve-child (§14): the child under key, fetched by the hash in this chunk's links header and verified against it, framing-judged, and refused as slot_codec_mismatch if its slot-codec-id differs from this chunk's. It reports false when key is not one of this chunk's keys. What it establishes is only that the child is the one this chunk references; it cannot anchor a closure.

func (*Chunk) SlotCodecID

func (c *Chunk) SlotCodecID() []byte

SlotCodecID is the chunk's slot-codec-id. The octets are a copy.

type ChunkEntry

type ChunkEntry struct {
	Key   []byte
	Child Address
}

ChunkEntry is one entry of a chunk: its key, and the address its link names.

type Class

type Class string

Class is one of §9's four non-acceptance classes, which license different actions and are never collapsed — or ClassStore, which groups the store-layer codes and is not a decoder class at all.

const (
	// ClassInvalid: these octets are not a value, now or ever.
	ClassInvalid Class = "invalid"
	// ClassUnsupported: the octets may be a value; this reader cannot say.
	ClassUnsupported Class = "unsupported"
	// ClassIncomplete: streaming, and more input may arrive.
	ClassIncomplete Class = "incomplete"
	// ClassResourceRefused: valid so far, beyond a local limit.
	ClassResourceRefused Class = "resource-refused"
	// ClassStore is the store / traversal layer of §9: not a decoder verdict.
	ClassStore Class = "store"
)

type Code

type Code string

Code is a stable result identifier of deixis-codec-v2 (CODEC.md §9): the code of a decoder verdict, need_more_input for a streaming decoder's non-terminal state, or a store-layer code. The spelling is the one the vectors pin.

const (
	CodeMalformedUvarint     Code = "malformed_uvarint"
	CodeNonShortestUvarint   Code = "non_shortest_uvarint"
	CodeUvarintOverflow      Code = "uvarint_overflow"
	CodeUnknownMagic         Code = "unknown_magic"
	CodeDuplicateKey         Code = "duplicate_key"
	CodeUnsortedKeys         Code = "unsorted_keys"
	CodeTrailingBytes        Code = "trailing_bytes"
	CodeUnexpectedEOF        Code = "unexpected_eof"
	CodeBadLinkIndex         Code = "bad_link_index"
	CodeUnusedLink           Code = "unused_link"
	CodeDuplicateLinkHash    Code = "duplicate_link_hash"
	CodeLinksOutOfOrder      Code = "links_out_of_order"
	CodeSlotCodecMismatch    Code = "slot_codec_mismatch"
	CodeMalformedSlotCodecID Code = "malformed_slot_codec_id"
	CodeNonCanonicalPayload  Code = "non_canonical_payload"
)

The invalid codes: the octets are not canonical deixis-codec-v2, now or ever.

const (
	// CodeUnsupportedSlotCodec is the only unsupported code: well-formed framing, and
	// an id this reader does not hold.
	CodeUnsupportedSlotCodec Code = "unsupported_slot_codec"
	// CodeNeedMoreInput is a streaming decoder's non-terminal state (§14).
	CodeNeedMoreInput Code = "need_more_input"
	// CodeLimitExceeded is a refusal on resource, naming a §12 dimension. It is never
	// invalidity.
	CodeLimitExceeded Code = "limit_exceeded"
)

The codes of the other three decoder classes.

const (
	CodeMissingChunk    Code = "missing_chunk"
	CodeHashMismatch    Code = "hash_mismatch"
	CodeAddressConflict Code = "address_conflict"
)

The store / traversal layer's codes. They are facts about a store, not about octets, so no decoder reports them as a verdict (§2.1, §9); see StoreError.

func (Code) Class

func (c Code) Class() Class

Class is the class a code belongs to, or "" for a string that is not a v2 code.

type Decoded

type Decoded[T any] struct {
	Node  Node[T]
	Codec SlotCodec[T]
}

Decoded is a value decoded from an artifact together with the slot codec it was decoded under (§4: a decoded artifact retains its codec context). Compare decoded nodes with Node.EqualBy(other, Codec.Equal).

func DecodeFlat

func DecodeFlat[T any](data []byte, registry Registry[T], limits *Limits) (Decoded[T], error)

DecodeFlat is the flat-decoder over a whole artifact: the value data spells, under the slot codec registry holds for its id, with every §5 rule checked at every node.

A refusal is a Refusal: an *InvalidError for malformed octets; an *UnsupportedError when the framing is well formed and the codec is not held (a nil or empty registry is codec-blind, and never yields a value); a *LimitError when a limit was reached first. A nil limits means DefaultLimits.

func DecodeLinked

func DecodeLinked[T any](root Address, fetch Fetch, registry Registry[T], limits *Limits) (Decoded[T], error)

DecodeLinked resolves the value at root: ResolveRoot, then Materialize.

func Materialize

func Materialize[T any](root *Chunk, fetch Fetch, registry Registry[T], limits *Limits) (Decoded[T], error)

Materialize is the linked-resolver's materialization: the whole closure under root validated, then the tree it denotes built, within the explicit budget of limits (§12). The unfolded node count and flat octets are estimated over the DAG first and a budget they exceed is refused before any node is built. Every occurrence of a shared chunk is decoded separately, so the result shares no payload between positions. A nil limits means DefaultLimits.

type DeixisNode

type DeixisNode[T any] interface {
	Own() T
	Children() []Child[T]
	At(TreePath) (DeixisNode[T], bool)
	Decompose() (T, []Child[T])
}

DeixisNode is the shared structural binding for every opaque payload. Implementations owe a finite, well-founded tree, complete child maps, copied keys, and the selection and reconstruction laws in docs/TREE.md. The interface alone cannot establish these laws for arbitrary implementations.

func AsTree

func AsTree[T any](node Node[T]) DeixisNode[T]

AsTree exposes a native Node through the shared structural binding. Go does not allow Node.At's concrete return type to satisfy an interface return type, so this adapter leaves existing native and codec operations concrete.

func ComposeTree

func ComposeTree[T any](own T, children []Child[T]) (DeixisNode[T], error)

ComposeTree reconstructs the shared structural interface from complete parts. Children must obey DeixisNode's laws. Keys and the collection are copied; payloads and child trees remain opaque. Duplicate keys and nil children fail.

type Dimension

type Dimension string

Dimension is a resource dimension of §12, spelled by its stable token.

const (
	DimensionVarintValue        Dimension = "varint_value"
	DimensionSlotCodecIDLength  Dimension = "slot_codec_id_length"
	DimensionKeyLength          Dimension = "key_length"
	DimensionPayloadLength      Dimension = "payload_length"
	DimensionEntriesPerNode     Dimension = "entries_per_node"
	DimensionLinksPerChunk      Dimension = "links_per_chunk"
	DimensionFlatArtifactOctets Dimension = "flat_artifact_octets"
	DimensionChunkOctets        Dimension = "chunk_octets"
	DimensionUniqueChunks       Dimension = "unique_chunks"
	DimensionUniqueOctets       Dimension = "unique_octets"
	DimensionLogicalDepth       Dimension = "logical_depth"
	DimensionUnfoldedNodeCount  Dimension = "unfolded_node_count"
	DimensionUnfoldedFlatOctets Dimension = "unfolded_flat_octets"
)

The thirteen dimensions of §12's envelope.

type DuplicateKeyError

type DuplicateKeyError struct {
	// Key is the key that appeared more than once.
	Key []byte
}

DuplicateKeyError reports that Compose was given the same key twice. The stable rejection code for this condition is "duplicate_key".

func (*DuplicateKeyError) Error

func (e *DuplicateKeyError) Error() string

type Entry

type Entry[T any] struct {
	Key  []byte
	Node Node[T]
}

Entry is one child: a byte key bound to a child node.

type Fetch

type Fetch func(Address) ([]byte, bool)

Fetch retrieves a chunk's octets by address from a store, which is untrusted: every chunk is verified against the address it was fetched by. False means the store has no chunk at that address.

type FlatDecoder

type FlatDecoder[T any] struct {
	// contains filtered or unexported fields
}

FlatDecoder is the streaming flat-decoder (§14). Feed it the octets of one artifact in pieces, then call Finish to declare the end of input. For every split of an artifact, Finish returns the verdict DecodeFlat returns for the whole of it.

func NewFlatDecoder

func NewFlatDecoder[T any](registry Registry[T], limits *Limits) *FlatDecoder[T]

NewFlatDecoder is a streaming flat-decoder holding registry. A nil limits means DefaultLimits.

func (*FlatDecoder[T]) Feed

func (d *FlatDecoder[T]) Feed(octets []byte) error

Feed appends the next octets of the artifact. It returns an *IncompleteError (need_more_input) while no verdict is certain — which includes a complete root, since trailing octets may still arrive — or the final Refusal once one is: a framing fault already in view, trailing_bytes, or limit_exceeded. A final refusal is returned again by every later call. After Finish, Feed ignores its octets and reports Finish's verdict, nil for an accepted value.

func (*FlatDecoder[T]) Finish

func (d *FlatDecoder[T]) Finish() (Decoded[T], error)

Finish declares the end of input and returns the verdict: the value, or a Refusal. need_more_input never survives Finish: input that ends mid-structure is unexpected_eof, and input that ends inside a cuvarint is malformed_uvarint (§3 rule 2), exactly as for the whole buffer.

type FlatHeaderValidator

type FlatHeaderValidator[T any] struct {
	// contains filtered or unexported fields
}

FlatHeaderValidator is the streaming flat-header-validator: it reads the magic and the slot-codec-id and decides as soon as they are complete, whatever follows.

func NewFlatHeaderValidator

func NewFlatHeaderValidator[T any](registry Registry[T], limits *Limits) *FlatHeaderValidator[T]

NewFlatHeaderValidator is a streaming header validator holding registry. A nil limits means DefaultLimits.

func (*FlatHeaderValidator[T]) Feed

func (v *FlatHeaderValidator[T]) Feed(octets []byte) error

Feed appends the next octets. It returns an *IncompleteError until the header is decided, then the header's verdict at once and on every later call: nil when the id is held, or a Refusal.

func (*FlatHeaderValidator[T]) Finish

func (v *FlatHeaderValidator[T]) Finish() (SlotCodec[T], error)

Finish declares the end of input and returns the held codec, or the refusal.

type IncompleteError

type IncompleteError struct{}

IncompleteError is the incomplete class: a streaming decoder has not reached a verdict and more input may arrive. It is non-terminal; see FlatDecoder.

func (*IncompleteError) Class

func (e *IncompleteError) Class() Class

Class is ClassIncomplete.

func (*IncompleteError) Code

func (e *IncompleteError) Code() Code

Code is CodeNeedMoreInput.

func (*IncompleteError) Error

func (e *IncompleteError) Error() string

type InvalidError

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

InvalidError is the invalid class: the octets are not canonical deixis-codec-v2.

func (*InvalidError) Class

func (e *InvalidError) Class() Class

Class is ClassInvalid.

func (*InvalidError) Code

func (e *InvalidError) Code() Code

Code is the invalid code.

func (*InvalidError) Error

func (e *InvalidError) Error() string

type Key

type Key = []byte

Key is an exact byte-string key, without text or separator interpretation.

type LimitError

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

LimitError is the resource-refused class: nothing failed up to where the reader declined to spend beyond one of its Limits. It is never invalidity (§9, §12): the octets may be a value.

func (*LimitError) Class

func (e *LimitError) Class() Class

Class is ClassResourceRefused.

func (*LimitError) Code

func (e *LimitError) Code() Code

Code is CodeLimitExceeded.

func (*LimitError) Dimension

func (e *LimitError) Dimension() Dimension

Dimension is the §12 dimension whose limit was exceeded.

func (*LimitError) Error

func (e *LimitError) Error() string

type Limits

type Limits struct {
	VarintValue uint64 // the largest cuvarint value read anywhere
	// SlotCodecIDLength bounds a slot-codec-id's octets. Its floor is §13's validity
	// bound — a longer id is malformed_slot_codec_id — so at the floor it never refuses.
	SlotCodecIDLength uint64
	// KeyLength, PayloadLength, EntriesPerNode and LinksPerChunk bound declared lengths
	// and counts, each met at its field, before the octets it announces (§12).
	KeyLength      uint64
	PayloadLength  uint64
	EntriesPerNode uint64
	LinksPerChunk  uint64
	// FlatArtifactOctets bounds the octets a flat reader will look at: it refuses when
	// it needs an octet at this offset or beyond and that octet is present. A remainder
	// is noticed without being read: an octet after a complete root is trailing_bytes
	// wherever it lies, at the limit's own offset included (§12).
	FlatArtifactOctets uint64
	// ChunkOctets bounds one chunk, and UniqueOctets the distinct chunks of one closure,
	// the root included. A chunk's size is met at its fetch, before its hash check and
	// its parse, so no fault inside it precedes either (§12).
	ChunkOctets  uint64
	UniqueChunks uint64 // distinct chunks of one closure, the root included
	UniqueOctets uint64
	// LogicalDepth bounds depth, which counts edges (§12): the root is at depth 0 and a
	// child is one deeper than its parent, so at the floor of 256 a node with 256
	// ancestors is within the limit and one with 257 is refused.
	LogicalDepth uint64
	// UnfoldedNodeCount and UnfoldedFlatOctets bound materialization and flattening of
	// a linked closure: the node occurrences of the tree it denotes, and the octets of
	// that tree's flat artifact, header included. Both are estimated with saturating
	// arithmetic over the DAG before anything is materialized. §12 lets a flat decoder
	// refuse on them too; this one does not, since FlatArtifactOctets already bounds a
	// flat artifact's length and so its node count.
	UnfoldedNodeCount  uint64
	UnfoldedFlatOctets uint64
}

Limits are a reader's resource limits, one per §12 dimension. Exceeding one refuses with a *LimitError naming it. DefaultLimits are exactly the §12 floors; a caller may raise any of them, and may lower one as a service policy — which is not a codec validity limit and makes the reader refuse inputs the floor says to accept.

Wherever a function takes a *Limits, nil means DefaultLimits.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits are the §12 MUST-accept floors.

func (*Limits) Set

func (l *Limits) Set(d Dimension, limit uint64) bool

Set sets the limit for the dimension d, reporting false if d is not a §12 token.

type Node

type Node[T any] struct {
	// contains filtered or unexported fields
}

Node is a node: an opaque own value and a finite map from byte keys to nodes. Structure is immutable once constructed; payloads may be mutable. The zero Node has the zero value of T and no children.

deixis does not define identity, it lifts one from the slot, and the slot is not required to have a good equality — or any particular equality. Compare nodes with Node.EqualBy, passing the relation explicitly; native == over Node values is not the lifted identity.

func Compose

func Compose[T any](own T, children []Entry[T]) (Node[T], error)

Compose is Node(own, children), from children in any order.

Keys are copied; the caller's slice and key bytes are never retained. Children are sorted, so insertion order is not observable — sibling order is not part of a node. Returns a DuplicateKeyError if two children share a key: a finite map has one child per key, and deixis has no policy for which would win, so it declines to choose.

func (Node[T]) At

func (n Node[T]) At(path [][]byte) (Node[T], bool)

At is n / path — resolve a path, a sequence of byte keys. See docs/PATH.md.

The empty path resolves to n itself. A miss is false: resolution never creates, never defaults, and never searches, and it walks children only — it never enters an own value, whatever that value holds. The own value at a path is read off the node found there: At, then Node.Own.

A path is not a string. Keys may contain any bytes, including separators and no bytes at all, so there is no delimited spelling to accept here — a caller wanting one owes a separator and escaping profile of its own.

func (Node[T]) Decompose

func (n Node[T]) Decompose() (T, []Entry[T])

Decompose is the node's parts, (own, children): its own value, and every child under its exact key as a whole subtree, in unsigned-octet lexicographic key order. A node without children returns an empty map, never a missing one. Composing the parts again gives the node back, and nothing about the node is outside them.

func (Node[T]) Entries

func (n Node[T]) Entries() []Entry[T]

Entries is the children in unsigned-octet lexicographic key order. Keys are copies; mutating them does not touch the node.

func (Node[T]) EqualBy

func (n Node[T]) EqualBy(other Node[T], eq func(a, b T) bool) bool

EqualBy is identity, lifted from the slot equality eq supplied by the caller.

Node(o, m) = Node(o', m')   iff  o ≈ o'  and  dom m = dom m'  and  m(k) = m'(k) for every k

The result is an equivalence relation exactly when eq is one. Pass a relation that is not reflexive — IEEE == over floats, say, where NaN != NaN — and a node stops being equal to itself. deixis lifts what it is given and makes no attempt to repair it.

func (Node[T]) Get

func (n Node[T]) Get(key []byte) (Node[T], bool)

Get is the child at key, or false if the key is not in the domain. Key equality is octet equality.

func (Node[T]) Keys

func (n Node[T]) Keys() [][]byte

Keys is the domain in order. Keys are copies.

func (Node[T]) Len

func (n Node[T]) Len() int

Len is the number of children.

func (Node[T]) Own

func (n Node[T]) Own() T

Own is the node's own value.

type Option

type Option[T any] struct {
	// contains filtered or unexported fields
}

Option is an opt-in payload type. Node does not interpret it. Its zero value is None.

The value is boxed rather than represented by a sentinel of T, so every T — pointers, interfaces and empty values included — is a legal Some.

func None

func None[T any]() Option[T]

None constructs the absent alternative of a caller-chosen optional payload.

func Some

func Some[T any](value T) Option[T]

Some is Some(value).

func (Option[T]) Get

func (o Option[T]) Get() (T, bool)

Get is the value and true for Some, or the zero T and false for None.

func (Option[T]) IsSome

func (o Option[T]) IsSome() bool

IsSome reports whether this is Some.

type Refusal

type Refusal interface {
	error
	Class() Class
	Code() Code
}

Refusal is a decoder's verdict other than accepted: exactly one class and one code. Each class has its own type — *InvalidError, *UnsupportedError, *IncompleteError and *LimitError — so the four are distinct to errors.As as well as to Class (§14: they are never collapsed into one error type). A store fault is a *StoreError and is deliberately not a Refusal.

type Registry

type Registry[T any] func(id []byte) (SlotCodec[T], bool)

Registry is what a decoder holds (§2.1's codec-holding modifier): the slot codec it resolves for a slot-codec-id, or false where it is codec-blind. A nil Registry holds nothing. It is consulted only after all framing is judged, with the octets of a well-formed id of a defined form, and a codec whose own ID differs from the id asked for is treated as not held. Being in the public registry is never being held (§13: registered is never authorized).

func Holding

func Holding[T any](codecs ...SlotCodec[T]) Registry[T]

Holding is the registry holding exactly the given codecs, matched by the exact octets of their ids. It panics if two codecs share an id or an id is not a well-formed id of a defined form, since such a registry could not answer unambiguously.

type SlotCodec

type SlotCodec[T any] interface {
	// ID is the slot-codec-id (§13), which travels in every artifact's octets.
	ID() []byte
	// Equal is the slot's equivalence ≈, which node identity lifts.
	Equal(a, b T) bool
	// Encode is e: the canonical payload octets of a value.
	Encode(value T) []byte
	// Decode is D: the value a payload spells, or false outside the image of Encode.
	Decode(payload []byte) (T, bool)
}

SlotCodec is a slot codec for the payload type T: SlotCodec(T) = {id, ≈, e, D} of CODEC.md §4. The four travel as one unit and are used together.

The supplier's whole obligation is lawfulness: Equal(x, y) ⟺ Encode(x) = Encode(y). Decode is an exact partial inverse — defined exactly on the image of Encode, where Encode(Decode(b)) = b — and refuses a non-canonical spelling rather than repair it. Decode may keep the octets it is given but must not modify them; Encode's result is only read.

func IdentityBytes

func IdentityBytes() SlotCodec[[]byte]

IdentityBytes is deixis/identity-bytes, public id 00 01: the carrier is Bytes, ≈ is octet equality, and e and D are the identity. Every octet string is canonical.

func OptionOf

func OptionOf[T any](c SlotCodec[T]) SlotCodec[Option[T]]

OptionOf is option-of(c), id 0x02 ‖ id(c) (§13): the carrier is Option[T]; None ≈ None, Some(x) ≈ Some(y) iff x ≈ y under c, and None ≉ Some; e(None) = 0x00 and e(Some(x)) = 0x01 ‖ e_c(x); D accepts exactly 0x00 and 0x01 ‖ b with b decodable by c. No self-delimitation is needed of c, because every payload is framed by its length.

func ReadFlatHeader

func ReadFlatHeader[T any](data []byte, registry Registry[T], limits *Limits) (SlotCodec[T], error)

ReadFlatHeader is the flat-header-validator: it reads the magic and the slot-codec-id and nothing after them, and returns the codec registry holds for that id. Its refusals are those §2.1 lets it observe: unknown_magic, unexpected_eof, the §3 faults of the id length and inside the id, malformed_slot_codec_id, unsupported_slot_codec, and limit_exceeded.

type StoreError

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

StoreError is a fault of the store a linked closure was fetched from, not of any octets: missing_chunk, or hash_mismatch when the octets a store returned do not hash to the address they were fetched by. It is not a Refusal.

func (*StoreError) Address

func (e *StoreError) Address() Address

Address is the address that was requested.

func (*StoreError) Code

func (e *StoreError) Code() Code

Code is CodeMissingChunk or CodeHashMismatch.

func (*StoreError) Error

func (e *StoreError) Error() string

type TreePath

type TreePath = [][]byte

TreePath is a relative sequence of keys. An empty path selects the current node.

type Unfolded

type Unfolded struct {
	Nodes      uint64 // node occurrences
	FlatOctets uint64 // octets of the flat artifact, header included
}

Unfolded measures the tree a linked closure denotes, computed over the DAG with saturating arithmetic: at most 2^64 − 1, whatever the sharing.

func EstimateUnfolded

func EstimateUnfolded(root *Chunk, fetch Fetch, limits *Limits) (Unfolded, error)

EstimateUnfolded validates the closure under root as CheckClosure does and measures the tree it denotes, without materializing anything.

type UnsupportedError

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

UnsupportedError is the unsupported class: the framing is well formed — every framing question was judged before this was reported (§11) — and the reader does not hold the slot codec the id names, or the id's form is reserved. The octets may be a value.

func (*UnsupportedError) Class

func (e *UnsupportedError) Class() Class

Class is ClassUnsupported.

func (*UnsupportedError) Code

func (e *UnsupportedError) Code() Code

Code is CodeUnsupportedSlotCodec.

func (*UnsupportedError) Error

func (e *UnsupportedError) Error() string

func (*UnsupportedError) SlotCodecID

func (e *UnsupportedError) SlotCodecID() []byte

SlotCodecID is the id that was not held. The octets are a copy.

Jump to

Keyboard shortcuts

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