Documentation
¶
Overview ¶
Package graphcontract defines Spool's canonical graph object contract.
Index ¶
- Variables
- func MarshalEdge(e Edge) ([]byte, error)
- func MarshalNode(n Node) ([]byte, error)
- func MarshalPropertyValue(v PropertyValue) ([]byte, error)
- type Edge
- type Node
- type PropertyKind
- type PropertyValue
- func BoolPropertyValue(value bool) PropertyValue
- func FloatPropertyValue(value float64) PropertyValue
- func IntegerPropertyValue(value int64) PropertyValue
- func ListPropertyValue(value []PropertyValue) PropertyValue
- func MapPropertyValue(value map[string]PropertyValue) PropertyValue
- func NullPropertyValue() PropertyValue
- func StringPropertyValue(value string) PropertyValue
- func UnmarshalPropertyValue(data []byte) (PropertyValue, error)
- type PropertyValueKind
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidPropertyValue reports a property value with an unknown kind or a // non-finite floating-point value. ErrInvalidPropertyValue = errors.New("invalid property value") // ErrInvalidCanonicalCBOR reports CBOR that does not encode a normalized // graph contract value in its canonical representation. ErrInvalidCanonicalCBOR = errors.New("invalid canonical CBOR") )
Functions ¶
func MarshalEdge ¶
MarshalEdge returns the normalized, canonical CBOR encoding of e.
func MarshalNode ¶
MarshalNode returns the normalized, canonical CBOR encoding of n.
func MarshalPropertyValue ¶
func MarshalPropertyValue(v PropertyValue) ([]byte, error)
MarshalPropertyValue returns the normalized, canonical CBOR encoding of v.
Types ¶
type Edge ¶
type Edge struct {
// ID uniquely identifies the edge within a graph snapshot.
ID string `json:"id" cbor:"1,keyasint"`
// Source identifies the edge's originating node.
Source string `json:"source" cbor:"2,keyasint"`
// Target identifies the edge's destination node.
Target string `json:"target" cbor:"3,keyasint"`
// Type identifies the edge's relationship type.
Type string `json:"type,omitempty" cbor:"4,keyasint,omitempty"`
// Properties holds typed, recursively composable edge properties.
Properties map[string]PropertyValue `json:"properties" cbor:"5,keyasint"`
}
Edge is the immutable edge representation stored in a graph snapshot.
func NewEdge ¶
func NewEdge(id, source, target, edgeType string, properties map[string]PropertyValue) (Edge, error)
NewEdge constructs a normalized edge.
func UnmarshalEdge ¶
UnmarshalEdge decodes and verifies canonical CBOR for an edge.
func (Edge) MarshalCBOR ¶
MarshalCBOR returns the normalized, canonical CBOR encoding of e. Omitted and explicitly empty properties have one encoding.
type Node ¶
type Node struct {
// ID uniquely identifies the node within a graph snapshot.
ID string `json:"id" cbor:"1,keyasint"`
// Title is the node's display value and compatibility field.
Title string `json:"title" cbor:"2,keyasint"`
// Labels identifies the node's sorted, unique type labels.
Labels []string `json:"labels" cbor:"3,keyasint"`
// Properties holds typed, recursively composable node properties.
Properties map[string]PropertyValue `json:"properties" cbor:"4,keyasint"`
}
Node is the immutable node representation stored in a graph snapshot.
func UnmarshalNode ¶
UnmarshalNode decodes and verifies canonical CBOR for a node.
func (Node) MarshalCBOR ¶
MarshalCBOR returns the normalized, canonical CBOR encoding of n. Omitted and explicitly empty collections have one encoding.
type PropertyKind ¶
type PropertyKind string
PropertyKind identifies the concrete value carried by a PropertyValue.
const ( PropertyNull PropertyKind = "null" PropertyBool PropertyKind = "bool" PropertyInteger PropertyKind = "integer" PropertyFloat PropertyKind = "float" PropertyString PropertyKind = "string" PropertyList PropertyKind = "list" PropertyMap PropertyKind = "map" )
type PropertyValue ¶
type PropertyValue struct {
Kind PropertyKind `json:"kind" cbor:"1,keyasint"`
Bool bool `json:"bool,omitempty" cbor:"2,keyasint,omitempty"`
Integer int64 `json:"integer,omitempty" cbor:"3,keyasint,omitempty"`
Float float64 `json:"float,omitempty" cbor:"4,keyasint,omitempty"`
String string `json:"string,omitempty" cbor:"5,keyasint,omitempty"`
List []PropertyValue `json:"list,omitempty" cbor:"6,keyasint,omitempty"`
Map map[string]PropertyValue `json:"map,omitempty" cbor:"7,keyasint,omitempty"`
}
PropertyValue is a tagged, recursively composable graph property value. Only the field associated with Kind is significant.
func BoolPropertyValue ¶
func BoolPropertyValue(value bool) PropertyValue
BoolPropertyValue returns a boolean property value.
func FloatPropertyValue ¶
func FloatPropertyValue(value float64) PropertyValue
FloatPropertyValue returns a floating-point property value.
func IntegerPropertyValue ¶
func IntegerPropertyValue(value int64) PropertyValue
IntegerPropertyValue returns an integer property value.
func ListPropertyValue ¶
func ListPropertyValue(value []PropertyValue) PropertyValue
ListPropertyValue returns a list property value.
func MapPropertyValue ¶
func MapPropertyValue(value map[string]PropertyValue) PropertyValue
MapPropertyValue returns a string-keyed map property value.
func NullPropertyValue ¶
func NullPropertyValue() PropertyValue
NullPropertyValue returns the canonical null property value.
func StringPropertyValue ¶
func StringPropertyValue(value string) PropertyValue
StringPropertyValue returns a string property value.
func UnmarshalPropertyValue ¶
func UnmarshalPropertyValue(data []byte) (PropertyValue, error)
UnmarshalPropertyValue decodes and verifies canonical CBOR for a property value.
func (PropertyValue) Clone ¶
func (v PropertyValue) Clone() PropertyValue
Clone returns a deep copy of v.
func (PropertyValue) Equal ¶
func (v PropertyValue) Equal(other PropertyValue) bool
Equal reports semantic equality after canonical normalization.
func (PropertyValue) MarshalCBOR ¶
func (v PropertyValue) MarshalCBOR() ([]byte, error)
MarshalCBOR returns the normalized, canonical CBOR encoding of v.
func (PropertyValue) Normalize ¶
func (v PropertyValue) Normalize() (PropertyValue, error)
Normalize returns the canonical representation of v. It clears fields that do not belong to v.Kind, recursively normalizes values, and normalizes negative zero to zero. CBOR canonical encoding deterministically orders the resulting string-keyed maps.
type PropertyValueKind ¶
type PropertyValueKind = PropertyKind
PropertyValueKind is an alias retained for callers that prefer the explicit type name.