protomessage

package
v2.0.0-...-c9ae7ca Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[M PointerMessage[T], T any](msg proto.Message) (M, error)

As returns the given message as type M. If the given message is type M, it is returned as-is. Otherwise (like if the given message is a dynamic message), it will be marshalled to bytes and then unmarshalled into a value of type M. If M and msg do not share the same message type (e.g. same fully qualified message name), an error is returned.

func Walk

func Walk(root protoreflect.Message, action func(path []any, val protoreflect.Message) bool)

Walk traverses the given root messages, iterating through its fields and through all values in maps and lists, calling the given action for all message values encountered. The given action is called for root first before being called for any contained message values.

The path provided to the callback is the sequence of field numbers, map keys, and list indices that identifies the location of the given message. It is empty when called for the root message.

If the callback returns false, the traversal is terminated and the callback will not be invoked again.

Types

type PointerMessage

type PointerMessage[T any] interface {
	*T
	proto.Message
}

PointerMessage is a pointer type that implements proto.Message.

Jump to

Keyboard shortcuts

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