protopath

package
v0.0.0-...-bb96f36 Latest Latest
Warning

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

Go to latest
Published: May 11, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package protopath provides functionality for representing a sequence of protobuf reflection operations on a message.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Path

type Path []Step

Path is a sequence of protobuf reflection steps applied to some root protobuf message value to arrive at the current value. The first step must be a Root step.

func (Path) Index

func (p Path) Index(i int) Step

Index returns the ith step in the path and supports negative indexing. A negative index starts counting from the tail of the Path such that -1 refers to the last step, -2 refers to the second-to-last step, and so on. It returns a zero Step value if the index is out-of-bounds.

func (Path) String

func (p Path) String() string

String returns a structured representation of the path by concatenating the string representation of every path step.

type Step

type Step struct {
	// contains filtered or unexported fields
}

Step is a union where only one step operation may be specified at a time. The different kinds of steps are specified by the constants defined for the StepKind type.

func AnyExpand

func AnyExpand(md protoreflect.MessageDescriptor) Step

AnyExpand describes expansion of a google.protobuf.Any message into a structured representation of the underlying message.

Within the context of Values, the type of the previous step value is always a google.protobuf.Any message, and the type of the current step value is always a message.

func FieldAccess

func FieldAccess(fd protoreflect.FieldDescriptor) Step

FieldAccess describes access of a field within a message. Extension field accesses are also represented using a FieldAccess and must be provided with a protoreflect.FieldDescriptor

Within the context of Values, the type of the previous step value is always a message, and the type of the current step value is determined by the field descriptor.

func ListIndex

func ListIndex(i int) Step

ListIndex describes index of an element within a list.

Within the context of Values, the type of the previous, previous step value is always a message, the type of the previous step value is always a list, and the type of the current step value is determined by the field descriptor.

func MapIndex

func MapIndex(k protoreflect.MapKey) Step

MapIndex describes index of an entry within a map. The key type is determined by field descriptor that the map belongs to.

Within the context of Values, the type of the previous previous step value is always a message, the type of the previous step value is always a map, and the type of the current step value is determined by the field descriptor.

func Root

Root indicates the root message that a path is relative to. It should always (and only ever) be the first step in a path.

func UnknownAccess

func UnknownAccess() Step

UnknownAccess describes access to the unknown fields within a message.

Within the context of Values, the type of the previous step value is always a message, and the type of the current step value is always a bytes type.

func (Step) FieldDescriptor

func (s Step) FieldDescriptor() protoreflect.FieldDescriptor

FieldDescriptor returns the field descriptor for FieldAccess steps, otherwise it returns nil.

func (Step) Kind

func (s Step) Kind() StepKind

Kind reports which kind of step this is.

func (Step) ListIndex

func (s Step) ListIndex() int

ListIndex returns the list index for ListIndex steps, otherwise it returns 0.

func (Step) MapIndex

func (s Step) MapIndex() protoreflect.MapKey

MapIndex returns the map key for MapIndex steps, otherwise it returns an invalid map key.

func (Step) MessageDescriptor

func (s Step) MessageDescriptor() protoreflect.MessageDescriptor

MessageDescriptor returns the message descriptor for Root or AnyExpand steps, otherwise it returns nil.

func (Step) String

func (s Step) String() string

type StepKind

type StepKind int

StepKind identifies the kind of step operation. Each kind of step corresponds with some protobuf reflection operation.

const (

	// RootStep identifies a step as the Root step operation.
	RootStep StepKind
	// FieldAccessStep identifies a step as the FieldAccess step operation.
	FieldAccessStep
	// UnknownAccessStep identifies a step as the UnknownAccess step operation.
	UnknownAccessStep
	// ListIndexStep identifies a step as the ListIndex step operation.
	ListIndexStep
	// MapIndexStep identifies a step as the MapIndex step operation.
	MapIndexStep
	// AnyExpandStep identifies a step as the AnyExpand step operation.
	AnyExpandStep
)

func (StepKind) String

func (k StepKind) String() string

type Values

type Values struct {
	Path   Path
	Values []protoreflect.Value
}

Values is a Path paired with a sequence of values at each step. The lengths of Path and Values must be identical. The first step must be a Root step and the first value must be a concrete message value.

func (Values) Index

func (p Values) Index(i int) (out struct {
	Step  Step
	Value protoreflect.Value
})

Index returns the ith step and value and supports negative indexing. A negative index starts counting from the tail of the Values such that -1 refers to the last pair, -2 refers to the second-to-last pair, and so on.

func (Values) Len

func (p Values) Len() int

Len reports the length of the path and values. If the path and values have differing length, it returns the minimum length.

func (Values) String

func (p Values) String() string

String returns a humanly readable representation of the path and last value. Do not depend on the output being stable.

For example:

(path.to.MyMessage).list_field[5].map_field["hello"] = {hello: "world"}

Jump to

Keyboard shortcuts

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