wire

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 9 Imported by: 0

Documentation

Overview

Package wire reads and validates CEM 0.1/0.2 wire documents.

The reader is a strict JSON parser implementing interop/cem-0.1/ALGORITHMS.md "JSON and version dispatch": it rejects malformed UTF-8, duplicate object keys at any depth, non-integer or non-finite numbers, integers outside 0..9007199254740991, unpaired surrogates after JSON decoding, and inputs nested deeper than the documented operational depth bound.

Index

Constants

View Source
const (
	Spec01          = "cem/0.1"
	Spec02          = "cem/0.2"
	ExcludedCEMPath = ".corvint/change.cem.json"

	MaxMapBytes    = 4 << 20
	MaxEvidence    = 4096
	MaxHunks       = 2048
	MaxBases       = 32
	MaxPathBytes   = 512
	EvidencePrefix = "evidence:sha256:"
	HunkPrefix     = "hunk:sha256:"
)

Frozen wire constants.

View Source
const MaxWireInteger = 9007199254740991

MaxWireInteger is the largest integer a CEM wire document may carry.

Variables

View Source
var Relations = map[string]bool{
	"call-site": true, "decision": true, "dependency": true, "implementation": true,
	"incident": true, "specification": true, "test-claim": true,
}

Relations enumerates the frozen basis relations.

Functions

func CanonicalString

func CanonicalString(text string) string

CanonicalString encodes one JSON string with the frozen escape profile.

func CanonicalValue

func CanonicalValue(value Value) []byte

CanonicalValue encodes one strict JSON value in the frozen canonical form: UTF-8, lexicographically sorted object keys, minimal separators, shortest signed decimal integers, no terminal LF. It is the single implementation of the `canonical-json-value` primitive every content address in the workspace hashes over, so a second approximation would silently fork identity.

func EvidenceIdentity

func EvidenceIdentity(blobOid, path string, span Span, spanSha256 string) string

EvidenceIdentity derives the frozen evidence ID for one evidence record.

func HunkIdentity

func HunkIdentity(contentSha256 string, oldPath, newPath *string, oldRange, newRange Range) string

HunkIdentity derives the frozen hunk ID. oldPath and newPath are nil for the created-from and deleted-to sides respectively.

func IsGitOid

func IsGitOid(text string) bool

IsGitOid reports whether text is a full 40- or 64-hex lowercase Git OID.

func IsSha256

func IsSha256(text string) bool

IsSha256 reports whether text is exactly 64 lowercase hex bytes.

func ValidatePath

func ValidatePath(path string) error

ValidatePath enforces the frozen relative POSIX path grammar.

func WriteCanonicalValue

func WriteCanonicalValue(output *strings.Builder, value Value)

WriteCanonicalValue appends the canonical encoding of value to output.

Types

type Basis

type Basis struct {
	EvidenceID string
	Relation   string
}

Basis is one typed evidence reference.

type Evidence

type Evidence struct {
	ID         string
	BlobOid    string
	Path       string
	Span       Span
	SpanSha256 string
}

Evidence is one immutable evidence record.

type Hunk

type Hunk struct {
	ID          string
	Path        string
	OldRange    Range
	NewRange    Range
	Disposition string
	Reason      string
	Basis       []Basis
}

Hunk is one mapped patch hunk.

type Kind

type Kind int

Kind enumerates strict JSON value kinds.

const (
	KindNull Kind = iota
	KindBool
	KindInt
	KindString
	KindArray
	KindObject
)

type Map

type Map struct {
	Spec         string
	BaseRevision string
	PatchSha256  string
	ExcludedPath string // empty for 0.1; the frozen literal for 0.2
	Evidence     []Evidence
	Hunks        []Hunk
}

Map is a validated CEM 0.1 or 0.2 document.

func ParseMap

func ParseMap(data []byte) (*Map, error)

ParseMap reads and validates one CEM wire document with the frozen stage-2 precedence: JSON errors, root object and spec, missing required fields, unknown fields, then field values in normative wire order.

type Object

type Object struct {
	Keys   []string
	Values map[string]Value
}

Object preserves member order and rejects duplicate keys at insertion.

func (*Object) Get

func (o *Object) Get(key string) (Value, bool)

Get returns the member value and whether it is present.

type Range

type Range struct{ Start, Count int64 }

Range is a unified-diff line range.

type Span

type Span struct{ Start, End int64 }

Span is a zero-based half-open raw-byte range.

type Value

type Value struct {
	Kind Kind
	Bool bool
	Int  int64
	Str  string
	Arr  []Value
	Obj  *Object
}

Value is one strict JSON value.

func Parse

func Parse(data []byte) (Value, error)

Parse reads one strict JSON document occupying the entire input.

Jump to

Keyboard shortcuts

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