protoconv

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 16 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 protoconv converts between the runtime's values and instances and the protobuf messages of the API, for every frontend that emits that shape.

Index

Constants

View Source
const UnsupportedNullPrefix = "unsupported: "

UnsupportedNullPrefix opens the non-empty null arm a value without a wire form crosses as; the reason follows it.

Variables

View Source
var (
	// ErrQuantityNeedsIndex reports a quantity converted from the wire without
	// the model's symbols, which its base units can only be resolved against.
	ErrQuantityNeedsIndex = errors.New("a quantity needs the model's symbols to be converted from the wire")

	// ErrUnknownBaseUnit reports a base unit the model does not declare, so no
	// unit can be rebuilt from the reduction naming it.
	ErrUnknownBaseUnit = errors.New("unknown base unit")

	// ErrNotAMeasurementUnit reports a reduction naming a symbol that is not a
	// measurement unit, which nothing is measured in.
	ErrNotAMeasurementUnit = errors.New("not a measurement unit")

	// ErrScaleNotAFactor reports a reduction composing a measurement scale with
	// other factors, a scale or a power: a point on a scale is no unit to compose.
	ErrScaleNotAFactor = errors.New("measurement scale is not a unit factor")

	// ErrUnitScaleUnusable reports a unit reduction whose scale is zero, undefined
	// or not finite, which no magnitude can be converted through.
	ErrUnitScaleUnusable = errors.New("unit scale is not a usable ratio")

	// ErrUnitExponentUnusable reports a unit factor raised to a power that is not
	// a finite number, which measures no dimension.
	ErrUnitExponentUnusable = errors.New("unit exponent is not a finite number")

	// ErrUnitNotReduced reports a named unit sent without its reduction, over
	// which alone commensurability is decided.
	ErrUnitNotReduced = errors.New("unit carries no reduction to base units")

	// ErrUnitTextMismatch reports a unit whose text names units that do not
	// reduce to the unit_term sent with it, so the two describe different units.
	ErrUnitTextMismatch = errors.New("unit as written does not reduce to its unit_term")
	// ErrUnsetNotAccepted reports the unset arm arriving as an input. It reports
	// that a feature value holds no value, which is something to read, not to supply.
	ErrUnsetNotAccepted = errors.New("unset is not a value a caller can supply")
	// ErrUndeterminedNotAccepted reports the undetermined arm arriving as an input.
	// It reports that the model fixes no answer, which is something to read, not to supply.
	ErrUndeterminedNotAccepted = errors.New("undetermined is not a value a caller can supply")

	// ErrInfinityNotAsserted reports the infinity arm arriving as false. The arm
	// is the unbounded value itself, so false states no value at all.
	ErrInfinityNotAsserted = errors.New("the infinity arm states no value unless it is true")

	// ErrArrayDimensionNotPositive reports an array sent with a dimension of no
	// extent, which Collections::Array declares as dimensions: Positive.
	ErrArrayDimensionNotPositive = errors.New("array dimension is not positive")

	// ErrArrayShapeMismatch reports an array whose elements do not fill its
	// dimensions, so no row-major reading of them has that shape.
	ErrArrayShapeMismatch = errors.New("array elements do not fill its dimensions")

	// ErrVectorComponentNotNumeric reports a vector component sent as something
	// other than an Integer or a Real, which a numerical vector has none of.
	ErrVectorComponentNotNumeric = errors.New("vector component is not a number")

	// ErrBigIntegerNotDecimal reports a big_int_value or big_int_magnitude
	// that is not an optionally signed run of decimal digits.
	ErrBigIntegerNotDecimal = errors.New("big Integer is not decimal")

	// ErrRationalNotLowestTerms reports a rational_value or rational_magnitude
	// that is not in lowest terms over a positive denominator.
	ErrRationalNotLowestTerms = errors.New("rational is not in lowest terms over a positive denominator")

	// ErrVectorQuantityEmpty reports a vector quantity of no components, whose
	// num is Number[1..*].
	ErrVectorQuantityEmpty = errors.New("vector quantity has no components")

	// ErrMeasurementRefNeedsIndex reports a measurement reference converted from
	// the wire without the model's symbols, which its units resolve against.
	ErrMeasurementRefNeedsIndex = errors.New("a measurement reference needs the model's symbols to be converted from the wire")

	// ErrMeasurementRefEmpty reports a measurement reference sent with no unit
	// text, no reduction and no declaration: nothing it could refer to.
	ErrMeasurementRefEmpty = errors.New("measurement reference names no unit")

	// ErrUnknownMeasurementUnit reports a unit_id the model does not declare
	// uniquely, so no reference can name the declaration.
	ErrUnknownMeasurementUnit = errors.New("unknown measurement unit")

	// ErrUnitIDMismatch reports a unit_id whose declaration the unit text sent
	// with it does not spell, so the two name different units.
	ErrUnitIDMismatch = errors.New("unit as written does not spell unit_id")

	// ErrFunctionNeedsRuntime reports a Function read with no runtime to bind
	// its calc in: only a runtime can turn a calc's name into a callable value.
	ErrFunctionNeedsRuntime = errors.New("function needs a runtime to bind its calc")

	// ErrFunctionUnbound reports a Function naming no calc of the model read as
	// a function, or an object the runtime does not hold.
	ErrFunctionUnbound = errors.New("function names no calc of this model")

	// ErrMetaobjectUnbound reports a Metaobject naming no element of the model,
	// or one no reflective metaclass of the model's libraries classifies.
	ErrMetaobjectUnbound = errors.New("metaobject names no element of this model")

	// ErrMetaobjectAmbiguous reports a Metaobject whose element_id names more than
	// one element of the model, so it identifies none of them.
	ErrMetaobjectAmbiguous = errors.New("metaobject names more than one element of this model")

	// ErrMetaclassMismatch reports a Metaobject sent with a metaclass_id other
	// than the one the model classifies its element by.
	ErrMetaclassMismatch = errors.New("metaclass_id is not the element's metaclass")

	// ErrSetElementRepeated reports a set sent with an element twice, which a
	// set holds once; a sender meaning both meant a sequence.
	ErrSetElementRepeated = errors.New("set element is repeated")

	// ErrTensorDimensionNotPositive reports a tensor sent with a dimension of no
	// extent, which its TensorMeasurementReference declares as Positive.
	ErrTensorDimensionNotPositive = errors.New("tensor dimension is not positive")

	// ErrTensorShapeMismatch reports a tensor whose components do not fill its
	// dimensions, so no row-major reading of them has that shape.
	ErrTensorShapeMismatch = errors.New("tensor components do not fill its dimensions")

	// ErrTensorComponentMissing reports a tensor component sent as an empty
	// message, which carries no quantity.
	ErrTensorComponentMissing = errors.New("tensor component carries no quantity")
)

Functions

func BoundText

func BoundText(b semantics.Bound) string

BoundText renders a multiplicity bound; an unevaluable one renders empty.

func CheckArrayShape

func CheckArrayShape(dimensions []int64, count int) error

CheckArrayShape reports whether count elements fill dimensions in row-major order: every dimension positive and their product (one for rank 0) count.

func CheckTensorShape

func CheckTensorShape(dimensions []int64, count int) error

CheckTensorShape is CheckArrayShape for a tensor's components, reported as the tensor errors.

func ComplexToProto

func ComplexToProto(z complex128) *pb.Complex

ComplexToProto marshals a complex number as its rectangular parts.

func DocumentRationalAsReal added in v0.10.0

func DocumentRationalAsReal(dv *pb.DocumentValue)

DocumentRationalAsReal is RationalsAsReals for a document value.

func DocumentValueHoldsBigInt added in v0.10.0

func DocumentValueHoldsBigInt(dv *pb.DocumentValue) bool

DocumentValueHoldsBigInt reports whether a document value is an Integer beyond int64, a quantity whose magnitude is one, or an event row whose time is.

func DocumentValueHoldsRational added in v0.10.0

func DocumentValueHoldsRational(dv *pb.DocumentValue) bool

DocumentValueHoldsRational reports whether a document value is an exact Rational, a quantity whose magnitude is one, or an event row whose time is.

func MeasurementRefToProto

func MeasurementRefToProto(ref *runtime.MeasurementRef) *pb.MeasurementRef

MeasurementRefToProto marshals a bare reference: the unit as written, what it reduces to, and the one declaration it names when it names one.

func NestedValues

func NestedValues(pv *pb.Value) []*pb.Value

NestedValues lists the Values a value holds directly: a sequence's or a set's elements, an array's elements and a vector's components.

func ProtoToBigInteger added in v0.10.0

func ProtoToBigInteger(text string) (semantics.Value, error)

ProtoToBigInteger reads the decimal a big_int_value or big_int_magnitude carries; one within int64 reads as the int64 Integer it equals.

func ProtoToComplex

func ProtoToComplex(pc *pb.Complex) complex128

ProtoToComplex is the complex number a Complex message carries; an empty message is zero, as every proto3 default is.

func ProtoToMeasurementRef

func ProtoToMeasurementRef(pm *pb.MeasurementRef, idx *symbols.Index, sem *semantics.Model) (runtime.Value, error)

ProtoToMeasurementRef rebuilds a bare reference from the wire: by the declaration unit_id names, checked against the unit text and reduction sent with it, or else by the unit text read exactly as a Quantity's is.

func ProtoToQuantity

func ProtoToQuantity(pq *pb.Quantity, idx *symbols.Index, sem *semantics.Model) (runtime.Value, error)

ProtoToQuantity rebuilds a quantity from the wire: the magnitude as sent, in the unit as written — read as the product of the named units it composes, so an operation over it cancels and merges them — over the base units idx resolves its reduction to.

func ProtoToRational added in v0.10.0

func ProtoToRational(pr *pb.Rational) (semantics.Value, error)

ProtoToRational reads a Rational in lowest terms over a positive denominator, one a double holds exactly included: a client sends every exact Rational so.

func ProtoToRuntimeValue

func ProtoToRuntimeValue(rt *runtime.Context, pv *pb.Value, idx *symbols.Index, sem *semantics.Model) (runtime.Value, error)

ProtoToRuntimeValue is ProtoToValueIn for a value bound for the runtime rt, which is what a function's calc is bound in and its object looked up in; rt may be nil for a value naming no function.

func ProtoToScalar

func ProtoToScalar(pv *pb.Value) runtime.Value

ProtoToScalar converts the arms of Value that name no symbol and hold no nested value.

func ProtoToValueIn

func ProtoToValueIn(pv *pb.Value, idx *symbols.Index, sem *semantics.Model) (runtime.Value, error)

ProtoToValueIn converts a protobuf Value to a runtime.Value in the model idx and sem describe, resolving a quantity's base units against them. Inverse of ValueToProto. A function, which only a runtime can bind, is refused: read one with ProtoToRuntimeValue.

func QuantityToProto

func QuantityToProto(q *runtime.Quantity) *pb.Quantity

QuantityToProto marshals a quantity: the magnitude in the unit written, plus what that unit reduces to. Reports nil for a magnitude that is not a number.

func RationalToProto added in v0.10.0

func RationalToProto(v semantics.Value) *pb.Rational

RationalToProto marshals an exact Rational no binary64 holds exactly.

func RationalsAsReals added in v0.10.0

func RationalsAsReals(pv *pb.Value)

RationalsAsReals rewrites in place each rational arm of pv, nested ones included, that a double holds exactly as that double: the form a service without rational_values reads. A Rational no double holds is left as it is.

func UnitTermToProto

func UnitTermToProto(term semantics.UnitTerm) *pb.UnitTerm

UnitTermToProto marshals a unit's reduction to base units, naming each base unit by qualified name: a symbol pointer means nothing to another process.

func UnsupportedReason

func UnsupportedReason(pv *pb.Value) (string, bool)

UnsupportedReason reads the non-empty null arm a value without a wire form crosses as; the SysML `null` is the empty one.

func UnsupportedSet

func UnsupportedSet(shown runtime.Value, reason string) *pb.Value

UnsupportedSet is the null arm a set holding a member without a wire form crosses as, naming the set and the member's reason.

func UnsupportedShown

func UnsupportedShown(shown runtime.Value) *pb.Value_Null

UnsupportedShown is the null arm a value of a kind the wire has no arm for crosses as, naming the kind and the value as the REPL shows it.

func ValueCarriesBigInt added in v0.10.0

func ValueCarriesBigInt(pv *pb.Value) bool

ValueCarriesBigInt reports whether a value, or any value nested in it, holds an Integer beyond int64: the arms the big_int_values capability governs.

func ValueCarriesComplex

func ValueCarriesComplex(pv *pb.Value) bool

ValueCarriesComplex reports whether a value, or any value nested in it, is a Complex: the kind the complex_values capability governs.

func ValueCarriesFunction

func ValueCarriesFunction(pv *pb.Value) bool

ValueCarriesFunction reports whether a value, or any value nested in it, is a Function: the kind function_values governs.

func ValueCarriesInfinity

func ValueCarriesInfinity(pv *pb.Value) bool

ValueCarriesInfinity reports whether a value, or any value nested in it, is the unbounded value: the kind infinity_value governs.

func ValueCarriesMeasurementRef

func ValueCarriesMeasurementRef(pv *pb.Value) bool

ValueCarriesMeasurementRef reports whether a value, or any value nested in it, is a MeasurementRef: the kind measurement_refs governs.

func ValueCarriesMetaobject

func ValueCarriesMetaobject(pv *pb.Value) bool

ValueCarriesMetaobject reports whether a value, or any value nested in it, is a Metaobject: the kind metaobject_values governs.

func ValueCarriesRational added in v0.10.0

func ValueCarriesRational(pv *pb.Value) bool

ValueCarriesRational reports whether a value, or any value nested in it, holds an exact Rational: the arms the rational_values capability governs.

func ValueCarriesSet

func ValueCarriesSet(pv *pb.Value) bool

ValueCarriesSet reports whether a value, or any value nested in it, is a ValueSet: the kind set_values governs.

func ValueCarriesStructured

func ValueCarriesStructured(pv *pb.Value) bool

ValueCarriesStructured reports whether a value, or any value nested in it, is an Array, a Vector or a VectorQuantity: the kinds structured_values governs.

func ValueCarriesTensor

func ValueCarriesTensor(pv *pb.Value) bool

ValueCarriesTensor reports whether a value, or any value nested in it, is a TensorQuantity: the kind tensor_values governs.

func ValueHoldsBigInt added in v0.10.0

func ValueHoldsBigInt(pv *pb.Value) bool

ValueHoldsBigInt reports whether a value is itself an Integer beyond int64 or carries one as a vector component or a quantity magnitude, its own or a component's; a collection's elements are values of their own, which it leaves to the caller.

func ValueHoldsRational added in v0.10.0

func ValueHoldsRational(pv *pb.Value) bool

ValueHoldsRational reports whether a value is itself an exact Rational or carries one as a vector component or a quantity magnitude, its own or a component's; a collection's elements are left to the caller.

func ValueToProto

func ValueToProto(val runtime.Value, idx *symbols.Index) *pb.Value

ValueToProto converts runtime.Value to protobuf Value. An enumeration literal is named by its declaration, which idx supplies the qualified name of.

func ValueToProtoIn

func ValueToProtoIn(rt *runtime.Context, val runtime.Value, idx *symbols.Index) *pb.Value

ValueToProtoIn converts a value read from a live context, which is what tells an object holding no value from one with features: the former crosses as the unset arm, as every other surface reads it. rt may be nil for a value no context materialized.

Types

type GraphBounds

type GraphBounds struct {
	Depth     int
	Instances int
}

GraphBounds is how far InstanceGraphToProtoWithin expands an object graph: nested objects to Depth, and Instances objects in all.

func DefaultGraphBounds

func DefaultGraphBounds() GraphBounds

DefaultGraphBounds are the bounds the service serializes an instance graph under.

type InstanceGraph

type InstanceGraph struct {
	Root *pb.Instance
	All  []*pb.Instance // the root first
	// Truncated reports that the instance bound cut the graph short.
	Truncated bool
	// Errors are the typed failures behind every FeatureValue.Error in All.
	Errors []error
}

InstanceGraph is an object graph serialized by InstanceGraphToProtoWithin.

func InstanceGraphToProtoWithin

func InstanceGraphToProtoWithin(rt *runtime.Context, inst *runtime.Instance, idx *symbols.Index, bounds GraphBounds) InstanceGraph

InstanceGraphToProtoWithin converts inst and every instance reachable from it, root first, stopping at bounds and at a type already on the path; an unexpanded child stays a bare id.

Jump to

Keyboard shortcuts

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