Documentation ¶
Overview ¶
Package util implements utlity functions not specific to any ygot package.
Index ¶
- Constants
- func ChildSchema(schema *yang.Entry, f reflect.StructField) (*yang.Entry, error)
- func ChildSchemaPreferShadow(schema *yang.Entry, f reflect.StructField) (*yang.Entry, error)
- func Children(e *yang.Entry) []*yang.Entry
- func DataSchemaTreesString(schema *yang.Entry, dataTree interface{}) string
- func DbgErr(err error) error
- func DbgPrint(v ...interface{})
- func DbgSchema(v ...interface{})
- func Dedent()
- func DeepEqualDerefPtrs(a, b interface{}) bool
- func DefiningType(subtype *yang.YangType, leafType *yang.YangType) (*yang.YangType, error)
- func EnumeratedUnionTypes(types []*yang.YangType) []*yang.YangType
- func FindFirstNonChoiceOrCase(e *yang.Entry) map[string]*yang.Entry
- func FindLeafRefSchema(schema *yang.Entry, pathStr string) (*yang.Entry, error)
- func FindModelData(mods []*yang.Entry) ([]*gpb.ModelData, error)
- func FindPathElemPrefix(paths []*gpb.Path) *gpb.Path
- func FirstChild(schema *yang.Entry, path []string) *yang.Entry
- func FlattenedTypes(types []*yang.YangType) []*yang.YangType
- func GetNodes(schema *yang.Entry, root interface{}, path *gpb.Path) ([]interface{}, []*yang.Entry, error)deprecated
- func HasOnlyChild(e *yang.Entry) bool
- func Indent()
- func InitializeStructField(parent interface{}, fieldName string, initializeLeafs bool) error
- func InsertIntoMap(parentMap interface{}, key interface{}, value interface{}) error
- func InsertIntoMapStructField(parentStruct interface{}, fieldName string, key, fieldValue interface{}) error
- func InsertIntoSlice(parentSlice interface{}, value interface{}) error
- func InsertIntoSliceStructField(parentStruct interface{}, fieldName string, fieldValue interface{}) error
- func InsertIntoStruct(parentStruct interface{}, fieldName string, fieldValue interface{}) error
- func IsAnydata(e *yang.Entry) bool
- func IsChoiceOrCase(e *yang.Entry) bool
- func IsCompressedSchema(s *yang.Entry) bool
- func IsConfig(e *yang.Entry) bool
- func IsConfigState(e *yang.Entry) bool
- func IsDirectEntryChild(p, c *yang.Entry, compressPaths bool) bool
- func IsEnumeratedType(t *yang.YangType) bool
- func IsFakeRoot(e *yang.Entry) bool
- func IsIdentityrefLeaf(e *yang.Entry) bool
- func IsKeyedList(e *yang.Entry) bool
- func IsLeafRef(schema *yang.Entry) bool
- func IsNilOrInvalidValue(v reflect.Value) bool
- func IsOCCompressedValidElement(e *yang.Entry) bool
- func IsRoot(e *yang.Entry) bool
- func IsSimpleEnumerationType(t *yang.YangType) bool
- func IsStructValueWithNFields(v reflect.Value, n int) bool
- func IsTypeInterface(t reflect.Type) bool
- func IsTypeMap(t reflect.Type) bool
- func IsTypeSlice(t reflect.Type) bool
- func IsTypeSliceOfInterface(t reflect.Type) bool
- func IsTypeSlicePtr(t reflect.Type) bool
- func IsTypeStruct(t reflect.Type) bool
- func IsTypeStructPtr(t reflect.Type) bool
- func IsUnionType(t *yang.YangType) bool
- func IsUnkeyedList(e *yang.Entry) bool
- func IsValueInterface(v reflect.Value) bool
- func IsValueInterfaceToStructPtr(v reflect.Value) bool
- func IsValueMap(v reflect.Value) bool
- func IsValueNil(value interface{}) bool
- func IsValueNilOrDefault(value interface{}) bool
- func IsValuePtr(v reflect.Value) bool
- func IsValueScalar(v reflect.Value) bool
- func IsValueSlice(v reflect.Value) bool
- func IsValueStruct(v reflect.Value) bool
- func IsValueStructPtr(v reflect.Value) bool
- func IsValueTypeCompatible(t reflect.Type, v reflect.Value) bool
- func IsYANGBaseType(t *yang.YangType) bool
- func IsYangPresence(s reflect.StructField) bool
- func IsYgotAnnotation(s reflect.StructField) bool
- func JoinPaths(prefix, suffix *gpb.Path) (*gpb.Path, error)
- func ListKeyFieldsMap(e *yang.Entry) map[string]bool
- func PathElemSlicesEqual(a, b []*gpb.PathElem) bool
- func PathElemsEqual(a, b *gpb.PathElem) bool
- func PathMatchesPathElemPrefix(path, prefix *gpb.Path) bool
- func PathMatchesPrefix(path *gpb.Path, prefix []string) bool
- func PathMatchesQuery(path, query *gpb.Path) bool
- func PathPartiallyMatchesPrefix(path *gpb.Path, prefix []string) bool
- func PathStringToElements(path string) []string
- func PopGNMIPath(path *gpb.Path) *gpb.Path
- func RelativeSchemaPath(f reflect.StructField) ([]string, error)
- func RelativeSchemaPathPreferShadow(f reflect.StructField) ([]string, error)
- func ReplacePathSuffix(name, newSuffix string) (string, error)
- func ResetIndent()
- func ResolveIfLeafRef(schema *yang.Entry) (*yang.Entry, error)
- func SanitizedPattern(t *yang.YangType) ([]string, bool)
- func SchemaEntryPathNoChoiceCase(elem *yang.Entry) []*yang.Entry
- func SchemaPathNoChoiceCase(elem *yang.Entry) []string
- func SchemaPaths(f reflect.StructField) ([][]string, error)
- func SchemaTreePath(e *yang.Entry) string
- func SchemaTreePathNoModule(e *yang.Entry) string
- func SchemaTreeString(schema *yang.Entry, prefix string) string
- func SchemaTypeStr(schema *yang.Entry) string
- func ShadowSchemaPaths(f reflect.StructField) [][]string
- func SlicePathToString(parts []string) string
- func SplitPath(path string) []string
- func StripModulePrefix(name string) string
- func StripModulePrefixesStr(in string) string
- func ToString(errors []error) string
- func TopLevelModule(schema *yang.Entry) *yang.Entry
- func TrimGNMIPathElemPrefix(path, prefix *gpb.Path) *gpb.Path
- func TrimGNMIPathPrefix(path *gpb.Path, prefix []string) *gpb.Path
- func UpdateField(parentStruct interface{}, fieldName string, fieldValue interface{}) error
- func ValueStr(value interface{}) string
- func ValueStrDebug(value interface{}) string
- func ValuesAreSameType(v1 reflect.Value, v2 reflect.Value) bool
- func YangIntTypeBits(t yang.TypeKind) (int, error)
- func YangTypeToDebugString(yt *yang.YangType) string
- type CompareRelation
- type DefaultWalkErrors
- type Errors
- func AppendErr(errors []error, err error) Errors
- func AppendErrs(errors []error, newErrs []error) Errors
- func ForEachDataField(value, in, out any, iterFunction FieldIteratorFunc) Errorsdeprecated
- func ForEachDataField2(value, in, out any, iterFunction FieldIteratorFunc2) Errors
- func ForEachField(schema *yang.Entry, value any, in, out any, iterFunction FieldIteratorFunc) Errors
- func NewErrs(err error) Errors
- func PrefixErrors(errs Errors, pfx string) Errors
- func UniqueErrors(errs Errors) Errors
- type FieldIteratorFunc
- type FieldIteratorFunc2
- type IterationAction
- type NodeInfo
- type PathQueryMemo
- type PathQueryNodeMemo
- type PathQueryResult
- type Visitor
- type WalkErrors
- type WalkNode
- type WalkOptions
Constants ¶
const ( // ContinueIteration means to continue the preorder traversal. ContinueIteration = IterationAction(iota) // DoNotIterateDescendants means to continue traversal but skip the // descendant elements of this subtree node. DoNotIterateDescendants )
const CompressedSchemaAnnotation string = "isCompressedSchema"
CompressedSchemaAnnotation stores the name of the annotation indicating whether a set of structs were built with -compress_path. It is appended to the yang.Entry struct of the root entity of the structs within the SchemaTree.
Variables ¶
This section is empty.
Functions ¶
func ChildSchema ¶
ChildSchema returns the schema for the struct field f, if f contains a valid path tag and the schema path is found in the schema tree. It returns an error if the struct tag is invalid, or nil if tag is valid but the schema is not found in the tree at the specified path.
func ChildSchemaPreferShadow ¶ added in v0.19.0
ChildSchemaPreferShadow returns the shadow schema (if exists) or schema for the struct field f, if f contains a valid "shadow-path" or "path" tag and the schema path is found in the schema tree. It returns an error if the struct tag is invalid, or nil if tag is valid but the schema is not found in the tree at the specified path.
func Children ¶ added in v0.7.0
Children returns all child elements of a directory element e that are not RPC entries.
func DataSchemaTreesString ¶
DataSchemaTreesString outputs a combined data/schema tree string where schema is displayed alongside the data tree e.g.
[device (container)] RoutingPolicy [routing-policy (container)] DefinedSets [defined-sets (container)] PrefixSet [prefix-set (list)] prefix1 prefix1 {255.255.255.0/20 20..24} IpPrefix : "255.255.255.0/20" [ip-prefix (leaf)] MasklengthRange : "20..24" [masklength-range (leaf)] PrefixSetName : "prefix1" [prefix-set-name (leaf)]
func DbgPrint ¶
func DbgPrint(v ...interface{})
DbgPrint prints v if the package global variable debugLibrary is set. v has the same format as Printf. A trailing newline is added to the output.
func DbgSchema ¶
func DbgSchema(v ...interface{})
DbgSchema prints v if the package global variable debugSchema is set. v has the same format as Printf.
func DeepEqualDerefPtrs ¶
func DeepEqualDerefPtrs(a, b interface{}) bool
DeepEqualDerefPtrs compares the values of a and b. If either value is a ptr, it is dereferenced prior to the comparison.
func DefiningType ¶ added in v0.8.3
DefiningType returns the type of definition of a subtype within a leaf type. In the trivial case that the subtype is the leaf type itself, the leaf type is returned; otherwise, subtype refers to a terminal union subtype within the leaf's union type. An error is returned if the type does not belong to the leaf type.
The "defining type" of a union subtype is the closest, or innermost defining type to which the subtype belongs. The "defining type" can either mean a typedef-defined type or a leaf-defined type.
Examples of the defining type of union subtypes within a top-level union used under a leaf: - a typedef within any kind or level of unions.
- defining type is the typedef itself -- the closest place of definition.
- a non-typedef within a non-typedef union.
- defining type is the union (i.e. type of the leaf, which defines it)
- a non-typedef within a non-typedef union within a non-typedef union.
- defining type is the outer union (i.e. type of the leaf, which defines it).
- a non-typedef within a typedef union within a non-typedef union.
- defining type is the (inner) typedef union.
func EnumeratedUnionTypes ¶ added in v0.7.0
EnumeratedUnionTypes recursively searches the set of yang.YangTypes supplied to extract the enumerated types that are within a union. The set of input yang.YangTypes is expected to be the slice of types of the union type. It returns the enumerated types in tree order of appearance.
func FindFirstNonChoiceOrCase ¶
FindFirstNonChoiceOrCase recursively traverses the schema tree and returns a map with the set of the first nodes in every path that are neither case nor choice nodes. The keys in the map are the paths from root to the matching elements. If the path to the parent data struct is needed, since it always has length 1, this is simply the last path element of the key.
func FindLeafRefSchema ¶ added in v0.7.0
FindLeafRefSchema returns a schema Entry at the path pathStr relative to schema if it exists, or an error otherwise. pathStr has either:
- the relative form "../a/b/../b/c", where ".." indicates the parent of the node, or
- the absolute form "/a/b/c", which indicates the absolute path from the root of the schema tree.
func FindModelData ¶ added in v0.7.0
FindModelData takes an input slice of yang.Entry pointers, which are assumed to represent YANG modules, and returns the gNMI ModelData that corresponds with each of the input modules.
func FindPathElemPrefix ¶ added in v0.6.0
FindPathElemPrefix finds the longest common prefix of the paths specified.
func FirstChild ¶ added in v0.7.0
FirstChild returns the first child entry that matches path from the given root. When comparing the path, only nodes that appear in the data tree are considered. It returns nil if no node matches the path.
func FlattenedTypes ¶ added in v0.8.3
FlattenedTypes returns in tree order (in-order) the subtypes of a union type.
func GetNodes
deprecated
func GetNodes(schema *yang.Entry, root interface{}, path *gpb.Path) ([]interface{}, []*yang.Entry, error)
GetNodes returns the nodes in the data tree at the indicated path, relative to the supplied root and their corresponding schemas at the same slice index. schema is the schema for root. If the key for a list node is missing, all values in the list are returned. If the key is partial, all nodes matching the values present in the key are returned. If the root is the tree root, the path may be absolute. GetNodes returns an error if the path is not found in the tree, or an element along the path is nil.
Deprecated: Use ytypes.GetNode with the option &ytypes.GetPartialKeyMatch{} and &ytypes.GetTolerateNil{} instead.
func HasOnlyChild ¶ added in v0.7.0
HasOnlyChild returns true if the directory passed to it only has a single element below it.
func InitializeStructField ¶ added in v0.6.0
InitializeStructField initializes the given field in the given struct. Only pointer fields and some of the composite types are initialized(Map). It initializes to zero value of the underlying type if the field is a pointer. If the field is a slice, no need to initialize as appending a new element will do the same thing. Note that if the field is initialized already, this function doesn't re-initialize it.
func InsertIntoMap ¶
func InsertIntoMap(parentMap interface{}, key interface{}, value interface{}) error
InsertIntoMap inserts value with key into parent which must be a map.
func InsertIntoMapStructField ¶
func InsertIntoMapStructField(parentStruct interface{}, fieldName string, key, fieldValue interface{}) error
InsertIntoMapStructField inserts fieldValue into a field of type map in parentStruct called fieldName (which must exist, but may be nil), using the given key. If the key already exists in the map, the corresponding value is updated.
func InsertIntoSlice ¶
func InsertIntoSlice(parentSlice interface{}, value interface{}) error
InsertIntoSlice inserts value into parent which must be a slice ptr.
func InsertIntoSliceStructField ¶
func InsertIntoSliceStructField(parentStruct interface{}, fieldName string, fieldValue interface{}) error
InsertIntoSliceStructField inserts fieldValue into a field of type slice in parentStruct called fieldName (which must exist, but may be nil).
func InsertIntoStruct ¶
InsertIntoStruct updates a field called fieldName (which must exist, but may be nil) in parentStruct, with value fieldValue. If the struct field type is a ptr and the value is non-ptr, the field is populated with the corresponding ptr type.
func IsChoiceOrCase ¶
IsChoiceOrCase returns true if the entry is either a 'case' or a 'choice' node within the schema. These are schema nodes only, and the code generation operates on data tree paths.
func IsCompressedSchema ¶ added in v0.6.0
IsCompressedSchema determines whether the yang.Entry s provided is part of a generated set of structs that have schema compression enabled. It traverses to the schema root, and determines the presence of an annotation with the name CompressedSchemaAnnotation which is added by ygen.
func IsConfig ¶ added in v0.7.0
IsConfig takes a yang.Entry and traverses up the tree to find the config state of that element. In YANG, if the config parameter is unset, then it is is inherited from the parent of the element - hence we must walk up the tree to find the state. If the element at the top of the tree does not have config set, then config is true. See https://tools.ietf.org/html/rfc6020#section-7.19.1.
func IsConfigState ¶ added in v0.7.0
IsConfigState returns true if the entry is an entity that represents a container called config or state.
func IsDirectEntryChild ¶ added in v0.7.0
IsDirectEntryChild determines whether the entry c is a direct child of the entry p within the output code. If compressPaths is set, a check to determine whether c would be a direct child after schema compression is performed.
func IsEnumeratedType ¶ added in v0.7.0
IsEnumeratedType returns true if the entry is an enumerated type within the YANG schema - i.e., an enumeration or identityref leaf.
func IsFakeRoot ¶
IsFakeRoot reports whether the supplied yang.Entry represents the synthesised root entity in the generated code.
func IsIdentityrefLeaf ¶ added in v0.7.0
IsIdentityrefLeaf returns true if the supplied yang.Entry represents an identityref.
func IsKeyedList ¶ added in v0.7.0
IsKeyedList returns true if the supplied yang.Entry represents a keyed list.
func IsNilOrInvalidValue ¶
IsNilOrInvalidValue reports whether v is nil or reflect.Zero.
func IsOCCompressedValidElement ¶ added in v0.7.0
IsOCCompressedValidElement returns true if the element would be output in the compressed YANG code.
func IsRoot ¶ added in v0.7.0
IsRoot returns true if the entry is an entity at the root of the tree.
func IsSimpleEnumerationType ¶ added in v0.7.0
IsSimpleEnumerationType returns true when the type supplied is a simple enumeration (i.e., a leaf that is defined as type enumeration { ... }, and is not a typedef that contains an enumeration, or a union that contains an enumeration which may have enum values specified. The type name enumeration is used in these cases by goyang.
func IsStructValueWithNFields ¶
IsStructValueWithNFields returns true if the reflect.Value representing a struct v has n fields.
func IsTypeInterface ¶
IsTypeInterface reports whether v is an interface.
func IsTypeSlice ¶
IsTypeSlice reports whether v is a slice type.
func IsTypeSliceOfInterface ¶
IsTypeSliceOfInterface reports whether v is a slice of interface.
func IsTypeSlicePtr ¶
IsTypeSlicePtr reports whether v is a slice ptr type.
func IsTypeStruct ¶
IsTypeStruct reports whether t is a struct type.
func IsTypeStructPtr ¶
IsTypeStructPtr reports whether v is a struct ptr type.
func IsUnionType ¶ added in v0.7.0
IsUnionType returns true if the entry is a union within the YANG schema, checked by determining the length of the Type slice within the YangType.
func IsUnkeyedList ¶
IsUnkeyedList reports whether e is an unkeyed list.
func IsValueInterface ¶
IsValueInterface reports whether v is an interface type.
func IsValueInterfaceToStructPtr ¶
IsValueInterfaceToStructPtr reports whether v is an interface that contains a pointer to a struct.
func IsValueNil ¶
func IsValueNil(value interface{}) bool
IsValueNil returns true if either value is nil, or has dynamic type {ptr, map, slice} with value nil.
func IsValueNilOrDefault ¶
func IsValueNilOrDefault(value interface{}) bool
IsValueNilOrDefault returns true if either IsValueNil(value) or the default value for the type.
func IsValueScalar ¶
IsValueScalar reports whether v is a scalar type.
func IsValueSlice ¶
IsValueSlice reports whether v is a slice type.
func IsValueStruct ¶
IsValueStruct reports whether v is a struct type.
func IsValueStructPtr ¶
IsValueStructPtr reports whether v is a struct ptr type.
func IsValueTypeCompatible ¶ added in v0.6.0
IsValueTypeCompatible reports whether f.Set(v) can be called successfully on a struct field f with type t. It is assumed that f is exported and addressable.
func IsYANGBaseType ¶ added in v0.7.0
IsYANGBaseType determines whether the supplied YangType is a built-in type in YANG, or a derived type (i.e., typedef).
func IsYangPresence ¶ added in v0.18.0
func IsYangPresence(s reflect.StructField) bool
IsYangPresence reports whether struct field s is a YANG presence container.
func IsYgotAnnotation ¶ added in v0.6.0
func IsYgotAnnotation(s reflect.StructField) bool
IsYgotAnnotation reports whether struct field s is an annotation field.
func JoinPaths ¶ added in v0.10.13
JoinPaths joins an prefix and suffix paths, returning an error if their target or origin fields are both non-empty but don't match.
func ListKeyFieldsMap ¶ added in v0.7.0
ListKeyFieldsMap returns a map[string]bool where the keys of the map are the fields that are the keys of the list described by the supplied yang.Entry. In the case the yang.Entry does not described a keyed list, an empty map is returned.
func PathElemSlicesEqual ¶ added in v0.8.12
PathElemSlicesEqual compares whether two PathElem slices are equal.
func PathElemsEqual ¶ added in v0.7.0
PathElemsEqual replaces the proto.Equal() check for PathElems. If a.Key["foo"] == "*" and b.Key["foo"] == "bar" func returns false. This significantly improves comparison speed.
func PathMatchesPathElemPrefix ¶ added in v0.6.0
PathMatchesPathElemPrefix checks whether prefix is a prefix of path. Both paths must use the gNMI >=0.4.0 PathElem path format. Note: Paths must match exactly, that is if path has a wildcard key, then the same key must also be a wildcard in the prefix. See PathMatchesQuery for comparing paths with wildcards.
func PathMatchesPrefix ¶ added in v0.6.0
PathMatchesPrefix reports whether prefix is a prefix of path.
func PathMatchesQuery ¶ added in v0.12.5
PathMatchesQuery returns whether query is prefix of path. Only the query may contain wildcard name or keys. TODO: Multilevel wildcards ("...") not supported. If either path and query contain nil elements func returns false. Both paths must use the gNMI >=0.4.0 PathElem path format.
func PathPartiallyMatchesPrefix ¶ added in v0.29.0
PathPartiallyMatchesPrefix reports whether the path partially or wholly matches the prefix. No keys from the path are compared.
e.g. a/b partially matches a/b/c or a/b, but doesn't match a/c.
func PathStringToElements ¶ added in v0.7.0
PathStringToElements splits the string s, which represents a gNMI string path into its constituent elements. It does not parse keys, which are left unchanged within the path - but removes escape characters from element names. The path returned omits any leading or trailing empty elements when splitting on the / character.
func PopGNMIPath ¶ added in v0.6.0
PopGNMIPath returns the supplied GNMI path with the first path element removed. If the path is empty, it returns an empty path.
func RelativeSchemaPath ¶ added in v0.7.0
func RelativeSchemaPath(f reflect.StructField) ([]string, error)
RelativeSchemaPath returns a path to the schema for the struct field f. Paths are embedded in the "path" struct tag and can be either simple:
e.g. "path:a"
or composite (if path compression is used) e.g.
e.g. "path:config/a|a"
In the latter case, this function returns {"config", "a"}, because only the longer path exists in the data tree and we want the schema for that node. This case is found in OpenConfig leaf-ref cases where the key of a list is a leafref; the schema *yang.Entry for the field is given by schema.Dir["config"].Dir["a"].
func RelativeSchemaPathPreferShadow ¶ added in v0.19.0
func RelativeSchemaPathPreferShadow(f reflect.StructField) ([]string, error)
RelativeSchemaPathPreferShadow returns a shadow path (if exists) or path to the schema for the struct field f.
Paths are embedded in the "shadow-path" and "path" struct tags and can be either simple:
e.g. "path:a"
or composite (if path compression is used) e.g.
e.g. "path:config/a|a"
In the latter case, this function returns {"config", "a"}, because only the longer path exists in the data tree and we want the schema for that node. This case is found in OpenConfig leaf-ref cases where the key of a list is a leafref; the schema *yang.Entry for the field is given by schema.Dir["config"].Dir["a"].
func ReplacePathSuffix ¶ added in v0.8.5
ReplacePathSuffix replaces the non-prefix part of a prefixed path name, or the whole path name otherwise. e.g. If replacing foo -> bar - "foo" becomes "bar" - "a:foo" becomes "a:bar"
func ResolveIfLeafRef ¶
ResolveIfLeafRef returns a ptr to the schema pointed to by the leaf-ref path in schema if it's a leafref, or schema itself if it's not.
func SanitizedPattern ¶ added in v0.8.10
SanitizedPattern returns the values of the posix-pattern extension statements for the YangType. If it's empty, then it returns the values from the pattern statements with anchors attached (if missing). It also returns whether the patterns are POSIX.
func SchemaEntryPathNoChoiceCase ¶ added in v0.12.0
SchemaEntryPathNoChoiceCase takes an input yang.Entry and walks up the tree to find its path, expressed as a slice of Entrys, which is returned.
func SchemaPathNoChoiceCase ¶ added in v0.7.0
SchemaPathNoChoiceCase takes an input yang.Entry and walks up the tree to find its path, expressed as a slice of strings, which is returned.
func SchemaPaths ¶
func SchemaPaths(f reflect.StructField) ([][]string, error)
SchemaPaths returns all the paths in the path tag.
func SchemaTreePath ¶ added in v0.7.0
SchemaTreePath returns the schema tree path of the supplied yang.Entry skipping any nodes that are themselves not in the path (e.g., choice and case). The path is returned as a string prefixed with the module name (similarly to the behaviour of (*yang.Entry).Path()).
func SchemaTreePathNoModule ¶ added in v0.7.0
SchemaTreePathNoModule takes an input yang.Entry, and returns its YANG schema path. The returned schema path does not include the root module name.
func SchemaTreeString ¶
SchemaTreeString returns the schema hierarchy tree as a string with node names and types only e.g.
clock (container) timezone (choice) timezone-name (case) timezone-name (leaf) timezone-utc-offset (case) timezone-utc-offset (leaf)
func SchemaTypeStr ¶
SchemaTypeStr returns a string representation of the type of element schema represents e.g. "container", "choice" etc.
func ShadowSchemaPaths ¶ added in v0.9.0
func ShadowSchemaPaths(f reflect.StructField) [][]string
ShadowSchemaPaths returns all the paths in the shadow-path tag. If the tag doesn't exist, a nil slice is returned.
func SlicePathToString ¶ added in v0.7.0
SlicePathToString concatenates a slice of strings into a / separated path. i.e., []string{"", "foo", "bar"} becomes "/foo/bar". Paths in YANG are generally represented in this return format, but the []string format is more flexible for internal use.
func SplitPath ¶ added in v0.7.0
SplitPath splits path across unescaped /. Any / inside square brackets are ignored.
func StripModulePrefix ¶
StripModulePrefix removes the prefix from a YANG path element, and the string format is invalid, simply returns the argument. For example, removing foo from "foo:bar". Such qualified paths are used in YANG modules where remote paths are referenced.
func StripModulePrefixesStr ¶
StripModulePrefixesStr returns "in" with each element with the format "A:B" changed to "B".
func ToString ¶
ToString returns a string representation of errors. Any nil errors in the slice are skipped.
func TopLevelModule ¶ added in v0.24.0
TopLevelModule returns the module in which the root node of the schema tree in which the input node was instantiated was declared. It returns nil if schema is nil.
In this example, container 'con' has TopLevelModule "openconfig-simple".
module openconfig-augment { import openconfig-simple { prefix "s"; } import openconfig-grouping { prefix "g"; } augment "/s:parent/child/state" { uses g:group; } } module openconfig-grouping { grouping group { container con { leaf zero { type string; } } } }
func TrimGNMIPathElemPrefix ¶ added in v0.6.0
TrimGNMIPathElemPrefix returns the path with the prefix trimmed. It returns the original path if the prefix does not match.
func TrimGNMIPathPrefix ¶ added in v0.6.0
TrimGNMIPathPrefix returns path with the prefix trimmed. It returns the original path if the prefix does not fully match.
func UpdateField ¶
UpdateField updates a field called fieldName (which must exist, but may be nil) in parentStruct, with value fieldValue. If the field is a slice, fieldValue is appended.
func ValueStr ¶
func ValueStr(value interface{}) string
ValueStr returns a string representation of value which may be a value, ptr, or struct type.
func ValueStrDebug ¶ added in v0.6.0
func ValueStrDebug(value interface{}) string
ValueStrDebug returns "<not calculated>" if the package global variable debugLibrary is not set. Otherwise, it is the same as ValueStr. Use this function instead of ValueStr for debugging purpose, e.g. when the output is passed to DbgPrint, because ValueStr calls can be the bottleneck for large input.
func ValuesAreSameType ¶ added in v0.6.0
ValuesAreSameType returns true if v1 and v2 has the same reflect.Type, otherwise it returns false.
func YangIntTypeBits ¶ added in v0.10.2
YangIntTypeBits returns the number of bits for a YANG int type. It returns an error if the type is not an int type.
func YangTypeToDebugString ¶
YangTypeToDebugString returns a debug string representation of a YangType.
Types ¶
type CompareRelation ¶ added in v0.25.7
type CompareRelation int
CompareRelation describes of the relation between to gNMI paths.
const ( // Equal means the paths are the same. Equal CompareRelation = iota // Disjoint means the paths do not overlap at all. Disjoint // Subset means a path is strictly smaller than the other. Subset // Superset means a path is strictly larger than the other. Superset // PartialIntersect means a path partial overlaps the other. PartialIntersect )
func ComparePaths ¶ added in v0.25.7
func ComparePaths(a, b *gpb.Path) CompareRelation
ComparePaths returns the set relation between two paths. It returns an error if the paths are invalid or not one of the relations.
type DefaultWalkErrors ¶ added in v0.29.1
type DefaultWalkErrors struct {
Errors
}
DefaultWalkErrors is the default WalkErrors used unless overwritten via WithWalkErrors.
func (*DefaultWalkErrors) Collect ¶ added in v0.29.1
func (e *DefaultWalkErrors) Collect(err error)
Collect is used by Walk to aggregate errors during the traversal.
type Errors ¶
type Errors []error
Errors is a slice of error.
func AppendErr ¶
AppendErr appends err to errors if it is not nil and returns the result. If err is nil, it is not appended.
func AppendErrs ¶
AppendErrs appends newErrs to errors and returns the result. If newErrs is empty, nothing is appended.
func ForEachDataField
deprecated
added in
v0.6.0
func ForEachDataField(value, in, out any, iterFunction FieldIteratorFunc) Errors
ForEachDataField iterates the value supplied and calls the iterFunction for each data tree node found in the supplied value. No schema information is required to perform the iteration. The in and out arguments are passed to the iterFunction without inspection by this function, and can be used by the caller to store input and output during the iteration through the data tree.
Deprecated: Use ForEachDataField2 or util.Walk instead.
func ForEachDataField2 ¶ added in v0.29.0
func ForEachDataField2(value, in, out any, iterFunction FieldIteratorFunc2) Errors
ForEachDataField2 is an improved ForEachDataField that allows iteration over the data tree in the supplied value with custom iteration behaviour at each iteration step.
ForEachDataField2 calls iterFunction for each data tree node found in the supplied value. No schema information is required to perform the iteration. The in and out arguments are passed to the iterFunction without inspection by this function, and can be used by the caller to store input and output during the iteration through the data tree.
See util.Walk if more dynamic control of the traversal is needed.
func ForEachField ¶
func ForEachField(schema *yang.Entry, value any, in, out any, iterFunction FieldIteratorFunc) Errors
ForEachField recursively iterates through the fields of value (which may be any Go type) and executes iterFunction on each field. Any nil fields (including value) are traversed in the schema tree only. This is done to support iterations that need to detect the absence of some data item e.g. leafref. Fields that are present in value that are explicitly noted not to have a corresponding schema (e.g., annotation/metadata fields added by ygen) are skipped during traversal.
- schema is the schema corresponding to value. - in, out are passed to the iterator function and can be used to carry state and return results from the iterator. - iterFunction is executed on each scalar field.
It returns a slice of errors encountered while processing the struct.
See util.Walk if more dynamic control of the traversal is needed.
func NewErrs ¶
NewErrs returns a slice of error with a single element err. If err is nil, returns nil.
func PrefixErrors ¶ added in v0.6.0
PrefixErrors prefixes each error within the supplied Errors slice with the string pfx.
func UniqueErrors ¶ added in v0.6.0
UniqueErrors returns the unique errors from the supplied Errors slice. Errors are considered equal if they have equal stringified values.
type FieldIteratorFunc ¶
FieldIteratorFunc is an iteration function for arbitrary field traversals. in, out are passed through from the caller to the iteration visitor function and can be used to pass state in and out. They are not otherwise touched. It returns a slice of errors encountered while processing the field.
type FieldIteratorFunc2 ¶ added in v0.29.0
type FieldIteratorFunc2 func(ni *NodeInfo, in, out any) (IterationAction, Errors)
FieldIteratorFunc2 is an iteration function for arbitrary field traversals. in, out are passed through from the caller to the iteration visitor function and can be used to pass state in and out. They are not otherwise touched. It returns what next iteration action to take as well as an error. TODO Deprecate the ForEachField and ForEachDataField functions in favor of Walk.
type IterationAction ¶ added in v0.29.0
type IterationAction uint
IterationAction is an enumeration representing different iteration actions.
func (IterationAction) String ¶ added in v0.29.0
func (i IterationAction) String() string
type NodeInfo ¶
type NodeInfo struct { // Schema is the schema for the node. Schema *yang.Entry // Path is the relative path from the parent to the current schema node. PathFromParent []string // Parent is a ptr to the containing node. Parent *NodeInfo // StructField is the StructField for the field being traversed. StructField reflect.StructField // FieldValue is the Value for the field being traversed. FieldValue reflect.Value // FieldKeys is the slice of keys in the map being traversed. nil if type // being traversed is not a map. FieldKeys []reflect.Value // FieldKey is the key of the map element being traversed. ValueOf(nil) if // type being traversed is not a map. FieldKey reflect.Value // Annotation is a field that can be populated by an iterFunction such that // context can be carried with a node throughout the iteration. Annotation []interface{} }
NodeInfo describes a node in a tree being traversed. It is passed to the iterator function supplied to a traversal driver function like ForEachField.
type PathQueryMemo ¶ added in v0.7.0
type PathQueryMemo map[string]PathQueryResult
PathQueryMemo caches nodes retrieved from (string) path queries. This memo may be useful if an algorithm may do multiple queries against the same path from the same node, any of which could be very expensive since the tree could be deep and wide.
type PathQueryNodeMemo ¶ added in v0.7.0
type PathQueryNodeMemo struct { Parent *PathQueryNodeMemo Memo PathQueryMemo }
PathQueryNodeMemo caches previous path queries done against a particular node. Parent pointer allows looking up the memos of its ancestor nodes.
func (*PathQueryNodeMemo) GetRoot ¶ added in v0.7.0
func (node *PathQueryNodeMemo) GetRoot() *PathQueryNodeMemo
GetRoot returns the PathQueryNodeMemo of the current node's tree's root.
type PathQueryResult ¶ added in v0.7.0
type PathQueryResult struct { Nodes []interface{} Err error }
PathQueryResult stores a datanode query result.
type Visitor ¶ added in v0.29.1
Visitor has a visit method that is invoked for each node encountered by Walk.
type WalkErrors ¶ added in v0.29.1
type WalkErrors interface {
Collect(error)
}
WalkErrors is an abstraction of collecting Errors during the util.Walk.
func Walk ¶ added in v0.29.1
func Walk(v Visitor, node WalkNode, o *WalkOptions) WalkErrors
Walk traverses the nodes with a customized visitor.
It traverses a GoStruct in depth-first order: It starts by calling v.Visit(node); node must not be nil. If the visitor w returned by v.Visit(node) is not nil, Walk is invoked recursively with visitor w for each of the non-nil children of node, followed by a call of w.Visit(nil).
By default, the traversal only visit existing GoStruct fields. If a customized schema is provided via WithSchema WalkOptions, then the traversal will visit the schema entry even if the GoStruct does not populate it.
The Visitor should handle its own error reporting and early termination. Any error during the traversal that is not part of Visitor will be aggregated into the returned WalkErrors. If not overwritten, the returned WalkErrors is of DefaultWalkErrors type, which is an alias of Errors.
type WalkNode ¶ added in v0.29.1
type WalkNode interface {
NodeInfo() *NodeInfo
}
WalkNode is an abstraction of NodeInfo during the util.Walk.
func WalkNodeFromGoStruct ¶ added in v0.29.1
WalkNodeFromGoStruct converts a GoStruct to WalkNode with empty schema.
func WalkNodeFromNodeInfo ¶ added in v0.29.1
WalkNodeFromNodeInfo converts a NodeInfo to WalkNode.
type WalkOptions ¶ added in v0.29.1
type WalkOptions struct { WalkErrors // contains filtered or unexported fields }
WalkOptions are configurations of the Walk function.
func DefaultWalkOptions ¶ added in v0.29.1
func DefaultWalkOptions() *WalkOptions
DefaultWalkOptions initialize a WalkOptions.
func (*WalkOptions) WithSchema ¶ added in v0.29.1
func (o *WalkOptions) WithSchema(schema *yang.Entry) *WalkOptions
WithSchema traverses schema entries even when a node is not populated with data.
func (*WalkOptions) WithWalkErrors ¶ added in v0.29.1
func (o *WalkOptions) WithWalkErrors(we WalkErrors) *WalkOptions
WithWalkErrors customizes the WalkErrors returned by the Walk function. If unspecified, the DefaultWalkErrors is used.