Documentation ¶
Index ¶
- Constants
- Variables
- func ChildrenCount(n Node) int
- func Count(root External, kinds Kind) int
- func Equal(n1, n2 External) bool
- func NodeEqual(n1, n2 Node) bool
- func Same(n1, n2 External) bool
- func ToString(v Value) string
- func WalkPreOrder(root Node, walk func(Node) bool)
- func WalkPreOrderExt(root External, walk func(External) bool)
- type Array
- func (m Array) Clone() Node
- func (m Array) CloneList() Array
- func (m Array) Equal(n External) bool
- func (m Array) EqualArray(m2 Array) bool
- func (Array) Kind() Kind
- func (m Array) Native() interface{}
- func (m Array) SameAs(n External) bool
- func (m *Array) SetNode(n Node) error
- func (m Array) Size() int
- func (Array) Value() Value
- func (m Array) ValueAt(i int) External
- type Bool
- type Comparable
- type Empty
- type External
- type ExternalArray
- type ExternalObject
- type Float
- type Hash
- type Hasher
- type Int
- type IterOrder
- type Iterator
- type Kind
- type Node
- type NodePtr
- type Object
- func (m Object) Clone() Node
- func (m Object) CloneObject() Object
- func (m Object) Equal(n External) bool
- func (m Object) EqualObject(m2 Object) bool
- func (m Object) Keys() []string
- func (Object) Kind() Kind
- func (m Object) Native() interface{}
- func (m Object) SameAs(n External) bool
- func (m Object) Set(k string, v Node) Object
- func (m *Object) SetNode(n Node) error
- func (m Object) Size() int
- func (Object) Value() Value
- func (m Object) ValueAt(k string) (External, bool)
- type String
- type ToNodeFunc
- type Uint
- type Value
Constants ¶
const ( IterAny = IterOrder(iota) PreOrder PostOrder LevelOrder )
const ( KindNil = Kind(1 << iota) KindObject KindArray KindString KindInt KindUint KindFloat KindBool )
const ( KindsValues = KindString | KindInt | KindUint | KindFloat | KindBool KindsComposite = KindObject | KindArray KindsNotNil = KindsComposite | KindsValues KindsAny = KindNil | KindsNotNil )
const HashSize = sha256.Size
HashSize is the size of hash used for nodes.
Variables ¶
var DefaultHasher = NewHasher()
Functions ¶
func ChildrenCount ¶
ChildrenCount reports the number of immediate children of n. If n is an Array this is the length of the array. If n is an Object, each object in a field of n counts as one child and each array is counted as its length.
func NodeEqual ¶
NodeEqual compares two subtrees. Equality is checked by value (deep), not by reference.
func Same ¶
Same check if two nodes represent exactly the same node. This usually means compare nodes by pointers.
func WalkPreOrder ¶
WalkPreOrder visits all nodes of the tree in pre-order.
func WalkPreOrderExt ¶
WalkPreOrderExt visits all nodes of the tree in pre-order.
Types ¶
type Array ¶
type Array []Node
Array is an ordered list of nodes.
func (Array) EqualArray ¶
type Comparable ¶
type Comparable interface {
// contains filtered or unexported methods
}
Comparable is an interface for comparable values that are guaranteed to be safely used as map keys.
func UniqueKey ¶
func UniqueKey(n Node) Comparable
UniqueKey returns a unique key of the node in the current tree. The key can be used in maps.
type External ¶
type External interface { // Kind returns a node kind. Kind() Kind // Value returns a primitive value of the node or nil if node is not a value. Value() Value // SameAs check if the node is exactly the same node as n2. This usually means checking node pointers. SameAs(n2 External) bool }
External is a node interface that can be implemented by other packages.
type ExternalArray ¶
type ExternalArray interface { External // Size returns the number of child nodes. Size() int // ValueAt returns a array value by an index. ValueAt(i int) External }
ExternalArray is an analog of Array type.
type ExternalObject ¶
type ExternalObject interface { External // Size returns the number of fields in an object. Size() int // Keys returns a sorted list of keys (object field names). Keys() []string // ValueAt returns an object field by key. It returns false if key does not exist. ValueAt(key string) (External, bool) }
ExternalObject is an analog of Object type.
type Hasher ¶
type Hasher struct { // KeyFilter allows to skip field in objects by returning false from the function. // Hash will still reflect the presence or absence of these key, but it won't hash a value of that field. KeyFilter func(key string) bool }
Hasher allows to configure node hashing.
func NewHasher ¶
func NewHasher() *Hasher
NewHasher creates a new hashing config with default options.
type Iterator ¶
type Iterator interface { // Next advances an iterator. Next() bool // Node returns a current node. Node() External }
func NewIterator ¶
type Node ¶
type Node interface { External // Clone creates a deep copy of the node. Clone() Node // Native returns a native Go type for this node. Native() interface{} // Equal checks if the node is equal to another node. // Equality is checked by value (deep), not by reference. Equal(n2 External) bool // contains filtered or unexported methods }
Node is a generic interface for a tree structure.
Can be one of:
- Object
- Array
- Value
func Apply ¶
Apply takes a root node and applies callback to each node of the tree recursively. Apply returns an old or a new node and a flag that indicates if node was changed or not. If callback returns true and a new node, Apply will make a copy of parent node and will replace an old value with a new one. It will make a copy of all parent nodes recursively in this case.
func ToNode ¶
func ToNode(o interface{}, fallback ToNodeFunc) (Node, error)
ToNode converts objects returned by schema-less encodings such as JSON to Node objects.
type Object ¶
Object is a representation of generic node with fields.
func (Object) CloneObject ¶
CloneObject clones this node only, without deep copy of field values.
func (Object) EqualObject ¶
func (Object) Native ¶
func (m Object) Native() interface{}
Native converts an object to a generic Go map type (map[string]interface{}).
type ToNodeFunc ¶
type Value ¶
type Value interface { Node Comparable // contains filtered or unexported methods }
Value is a generic interface for primitive values.
Can be one of:
- String
- Int
- Uint
- Float
- Bool
Directories ¶
Path | Synopsis |
---|---|
Package nodesproto is a generated protocol buffer package.
|
Package nodesproto is a generated protocol buffer package. |