paths

package
v0.0.0-...-616c413 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Copyright 2024 Joe Kralicky

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

View Source
var ErrFieldNotFound = errors.New("field not found")

Functions

func Evaluate

func Evaluate(root proto.Message, path protopath.Path) (protoreflect.Value, error)

Evaluate returns the value within a message referenced by the given path, or an invalid value if the path could not be resolved for any reason.

The path may, but is not required to, contain a root step. If the path does contain a root step, and the root step does not match the provided message, this function will panic.

A non-nil error can be returned if the wrong message type is given in an any-expand expression. Otherwise, the message not containing a value at the path is not treated as an error.

func Join

func Join[T protopath.Step, S ~[]T](a protopath.Path, b S) protopath.Path

Join returns a new path constructed by appending the steps of 'b' to 'a'. The first step in 'b' is skipped; it is assumed (but not checked for) that 'b' starts with a Root step matching the message type of the last step in path 'a'.

func Parse

func Parse(pathStr string) (protopath.Path, error)

Parses a protopath string as given by the protopath.Path.String method.

Repeated calls to this method with the same string will return the previous cached result. If the previous result returned an error, the same error will be returned. Thus, care should be taken to avoid directly modifying the underlying elements of the returned path.

func ParseFrom

func ParseFrom(root protoreflect.MessageDescriptor, pathStr string) (protopath.Path, error)

Parses a path string with an implied root given by the message descriptor.

The path string itself should not contain the root step; it should instead begin with the '.' character that would usually follow it. To parse a full path string containing the root step, use Parse instead.

func Slice

func Slice(from protopath.Values, start, end int) protopath.Values

Slice returns a new path with both its path and values resliced by the given range. It is assumed that both slices are of the same length.

func Split

func Split(pathStr string) iter.Seq[string]

Split returns an iterator that yields each segment of a protopath string in order. It splits the path by '.' or '[' except within parentheses or quotes.

Types

type Parser

type Parser struct {

	// Custom message type resolver. If nil, uses protoregistry.GlobalTypes.
	Resolver protoregistry.MessageTypeResolver
	// contains filtered or unexported fields
}

A Parser contains a cache and an optional custom resolver. The methods Parse and ParseFrom operate on a global instance of the parser, but separate Parser instances can be used instead for specific use cases.

func (*Parser) Parse

func (p *Parser) Parse(pathStr string) (protopath.Path, error)

func (*Parser) ParseFrom

func (p *Parser) ParseFrom(root protoreflect.MessageDescriptor, pathStr string) (protopath.Path, error)

type Trie

type Trie[V any] struct {
	// contains filtered or unexported fields
}

func NewTrie

func NewTrie[V any](desc protoreflect.MessageDescriptor, newV func() V) *Trie[V]

func (*Trie[V]) Find

func (t *Trie[V]) Find(path protopath.Path) *TrieNode[V]

func (*Trie[V]) FindString

func (t *Trie[V]) FindString(pathStr string) *TrieNode[V]

func (*Trie[V]) Walk

func (t *Trie[V]) Walk(fn func(*TrieNode[V]))

Walk performs a depth-first post-order traversal of the trie, calling fn for each node. The root node is visited last.

func (*Trie[V]) WalkValues

func (t *Trie[V]) WalkValues(fn func(node *TrieNode[V], value protoreflect.Value), rootValue protoreflect.Value)

type TrieNode

type TrieNode[V any] struct {
	protopath.Path
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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