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 ¶
- Variables
- func Evaluate(root proto.Message, path protopath.Path) (protoreflect.Value, error)
- func Join[T protopath.Step, S ~[]T](a protopath.Path, b S) protopath.Path
- func Parse(pathStr string) (protopath.Path, error)
- func ParseFrom(root protoreflect.MessageDescriptor, pathStr string) (protopath.Path, error)
- func Slice(from protopath.Values, start, end int) protopath.Values
- func Split(pathStr string) iter.Seq[string]
- type Parser
- type Trie
- type TrieNode
Constants ¶
This section is empty.
Variables ¶
var ErrFieldNotFound = errors.New("field not found")
Functions ¶
func Evaluate ¶
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 ¶
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 ¶
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.
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) 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]) FindString ¶
func (*Trie[V]) Walk ¶
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)