Documentation ¶
Index ¶
- Constants
- func IsDefaultScalar(v *protoreflect.Value) bool
- type KeyValue
- type MapFunc
- type MessageFunc
- type Option
- func OptionAddNameOverride(name string, v interface{}) Option
- func OptionAddScalarFunc(k protoreflect.Kind, v ScalarFunc) Option
- func OptionAddTypeOverride(type_ string, v MessageFunc) Option
- func OptionDefaultScalarFunc(fn ScalarFunc) Option
- func OptionKeepEmpty(v bool) Option
- func OptionKeepOrder(v bool) Option
- func OptionMapFunc(fn MapFunc) Option
- func OptionMaxDepth(v int) Option
- func OptionMaxDepthForName(name string, v int) Option
- func OptionMessageFunc(fn MessageFunc) Option
- func OptionRepeatedFunc(fn RepeatedFunc) Option
- type OptionType
- type OverrideFunc
- type RepeatedFunc
- type ScalarFunc
- type Walker
Constants ¶
const ( OptionTypeKeepEmpty = OptionType(1) + iota OptionTypeMaxDepth OptionTypeMaxDepthForName OptionTypeDefaultScalarFunc OptionTypeMapFunc OptionTypeMessageFunc OptionTypeRepeatedFunc OptionTypeKeepOrder OptionTypeAddOverride OptionTypeAddNameOverride OptionTypeAddScalarFunc )
TODO(hvl): OptionTypeMaxDepthForType
Variables ¶
This section is empty.
Functions ¶
func IsDefaultScalar ¶
func IsDefaultScalar(v *protoreflect.Value) bool
Types ¶
type MapFunc ¶
type MapFunc func(protoreflect.FieldDescriptor, map[interface{}]interface{}) interface{}
type MessageFunc ¶
type MessageFunc func(protoreflect.FieldDescriptor, []KeyValue) interface{}
type Option ¶
type Option interface { // Type returns the Option's type. Type() OptionType // Apply applies the Option to the Walker. Apply(w *walker) }
func OptionAddNameOverride ¶
OptionAddNameOverride defines a special (post-)processing for the given field. Except for scalar fields, processing occurs after the normal conversion. For scalar fields, it is applied instead of normal conversion.
The name is a chain of field names, separated by dots. Repeated fields and their subfields can be referenced (i.e. 'addresses.street'), but there is no support for indexing. The same goes for map fields.
An override on a repeated field will be applied to each element. There is no support for post-processing the converted list as a whole. Such behaviour can be achieved by overriding the containing message.
You can effectively use multiple instances of this option as long as their name differs - otherwise, earlier ones will be overwritten by later ones.
func OptionAddScalarFunc ¶
func OptionAddScalarFunc(k protoreflect.Kind, v ScalarFunc) Option
OptionAddScalarFunc adds a conversion function for a scalar kind. If no conversion function has been specified for a certain kind, the default function specified via SetDefaultFunc will be applied.
You can effectively use multiple instances of this option as long as their protoreflect.Kind differs - otherwise, earlier ones will be overwritten by later ones.
func OptionAddTypeOverride ¶
func OptionAddTypeOverride(type_ string, v MessageFunc) Option
OptionAddTypeOverride defines a special treatment for the given message type. The type name is expected to be the full name, i.e. 'acme.products.Anvil'.
You can effectively use multiple instances of this option as long as their type name differs - otherwise, earlier ones will be overwritten by later ones.
func OptionDefaultScalarFunc ¶
func OptionDefaultScalarFunc(fn ScalarFunc) Option
OptionDefaultScalarFunc sets the default scalar conversion function. When omitted, the default function is an identity function.
func OptionKeepEmpty ¶
func OptionKeepOrder ¶
OptionKeepOrder will cause the Walker to return a list of KeyValue structs if set to true, rather than an unordered map. This list will be ordered according to the fields' protocol buffer numbers.
func OptionMapFunc ¶
OptionMapFunc sets the map type conversion function. The default is an identity function.
func OptionMaxDepth ¶
OptionMaxDepth sets a maximum message recursion depth. This mitigates the impact of infinite recursion in recursive messages (like protobuf.Struct). Only traversed Message fields add to the recursion depth.
A depth of zero will return the root level fields. If depth is set to less than zero, the default recursion depth (99) will be used.
func OptionMaxDepthForName ¶
OptionMaxDepthForName sets a maximum message recursion depth starting from the given field. This mitigates the impact of infinite recursion in recursive messages (like protobuf.Struct). Only traversed Message fields add to the recursion depth.
A depth of zero will return the field. If depth is set to less than zero, the default recursion depth (99) will be used.
func OptionMessageFunc ¶
func OptionMessageFunc(fn MessageFunc) Option
OptionMessageFunc sets the message type conversion function. The default is an identity function. The top-level message will not be treated by this function; it has no FieldDescriptor.
func OptionRepeatedFunc ¶
func OptionRepeatedFunc(fn RepeatedFunc) Option
OptionRepeatedFunc sets the repeated field conversion function. The default is an identity function.
type OptionType ¶
type OptionType int
type OverrideFunc ¶
type OverrideFunc func(protoreflect.FieldDescriptor, interface{}) interface{}
func FromMapFunc ¶
func FromMapFunc(f MapFunc) OverrideFunc
func FromMessageFunc ¶
func FromMessageFunc(f MessageFunc) OverrideFunc
func FromScalarFunc ¶
func FromScalarFunc(f ScalarFunc) OverrideFunc
FromScalarFunc creates an OverrideFunc from a Scalar func.
type RepeatedFunc ¶
type RepeatedFunc func(protoreflect.FieldDescriptor, []interface{}) interface{}
type ScalarFunc ¶
type ScalarFunc func(protoreflect.FieldDescriptor, *protoreflect.Value) interface{}
type Walker ¶
type Walker interface { // Apply will apply this Walker to a Message. Apply(m proto.Message) interface{} // ApplyDesc will apply this Walker to a message Descriptor. ApplyDesc(d protoreflect.MessageDescriptor) interface{} }
A Walker walks over a Protocol Buffers message or message descriptor. Without additional configuration, it will return it as a map.