Documentation
¶
Index ¶
- Variables
- func AppendListItem(li List, new any) error
- func AppendMessageFieldListItem(parentMessage protoreflect.Message, listField protoreflect.FieldDescriptor, ...) error
- func AreProtoFieldsMatch(x, y protoreflect.FieldDescriptor) bool
- func AreValueTypesMatch(x, y reflect.Value) bool
- func FieldDescriptorInMessageDescriptor(desc protoreflect.MessageDescriptor, name string) protoreflect.FieldDescriptor
- func InsertListItem(li List, index int, new any) error
- func InsertMessageFieldListItem(parentMessage protoreflect.Message, listField protoreflect.FieldDescriptor, ...) error
- func InterfaceOfListItem(listField protoreflect.FieldDescriptor, value protoreflect.Value) any
- func InterfaceOfMapItem(mapField protoreflect.FieldDescriptor, value protoreflect.Value) any
- func InterfaceOfMessageField(field protoreflect.FieldDescriptor, value protoreflect.Value) any
- func InterfaceValue(i any) protoreflect.Value
- func IsTypeMapOfProtoMessageInterfaces(t reflect.Type) bool
- func IsTypeMatchesProtoScalarKind(kind protoreflect.Kind, t reflect.Type) bool
- func IsTypeSliceOfProtoMessageInterfaces(t reflect.Type) bool
- func IsValueTypeMatchesProtoField(field protoreflect.FieldDescriptor, v reflect.Value) bool
- func MessageDescriptorFromType(t reflect.Type) protoreflect.MessageDescriptor
- func MessageDescriptorFromValue(v reflect.Value) protoreflect.MessageDescriptor
- func MessageDescriptorFromValueOfMapOfProtoMessages(v reflect.Value) protoreflect.MessageDescriptor
- func MessageDescriptorFromValueOfSliceOfProtoMessages(v reflect.Value) protoreflect.MessageDescriptor
- func NewProtoreflectOfMessage(m proto.Message) protoreflect.Message
- func ParseListIndex(name string) (int, bool)
- func ParseMapKey(keyType protoreflect.FieldDescriptor, name string) protoreflect.MapKey
- func ParsedIndexInList(len int, name string) int
- func ParsedKeyInMap(m protoreflect.Map, keyType protoreflect.FieldDescriptor, name string) protoreflect.MapKey
- func ProtoreflectOfAny(v any) protoreflect.Message
- func ProtoreflectOfMessage(m proto.Message) protoreflect.Message
- func SetListItem(li List, index int, to any) error
- func SetMapItem(ma Map, key protoreflect.MapKey, to any) error
- func SetMessageField(m protoreflect.Message, field protoreflect.FieldDescriptor, to any) error
- func SetMessageFieldListItem(parentMessage protoreflect.Message, listField protoreflect.FieldDescriptor, ...) error
- func SetMessageFieldMapItem(parentMessage protoreflect.Message, mapField protoreflect.FieldDescriptor, ...) error
- type List
- type Map
Constants ¶
This section is empty.
Variables ¶
var (
ErrMismatchingType = errors.New("mismatching type")
)
Functions ¶
func AppendListItem ¶
AppendListItem appends the provided value to end of the provided list. It may panic if the provided list is invalid or is read only. It returns ErrMismatchingType error when value type do not matches any of types that would allow appending.
func AppendMessageFieldListItem ¶
func AppendMessageFieldListItem(parentMessage protoreflect.Message, listField protoreflect.FieldDescriptor, new any) error
AppendMessageFieldListItem appends the provided value to end of the list value from a list field within the given message. It may panic if the provided parent message is invalid, the list field descriptor do not belongs to the message. It returns ErrMismatchingType error when value type do not matches any of types that would allow appending.
func AreProtoFieldsMatch ¶
func AreProtoFieldsMatch(x, y protoreflect.FieldDescriptor) bool
AreProtoFieldsMatch reports if tow provided protoreflect.FieldDescriptors match. If the field descriptors match, any of their value can be assigned to any of the fields using standard proto and protopatch rules for assignment.
func AreValueTypesMatch ¶
AreValueTypesMatch reports if types of two provided values match or if one can be set from the other using standard proto and protopatch rules for assignment.
func FieldDescriptorInMessageDescriptor ¶
func FieldDescriptorInMessageDescriptor(desc protoreflect.MessageDescriptor, name string) protoreflect.FieldDescriptor
FieldDescriptorInMessageDescriptor parses the provided name as field name. It returns nil field descriptor if the associated field cannot be found.
func InsertListItem ¶
InsertListItem insert the provided value at specified index into the provided list, by expanding list, moving necessary items and setting value under the specified index according to proto and protopatch assignment rules. It may panic if the provided list is invalid or is read only or the given index is out of bounds of the list. It returns ErrMismatchingType error when value type do not matches any of types that would allow appending. Note thet when the index is exactly equal to the length of the list, insert behaves like append and do not panics due to out of bound index.
func InsertMessageFieldListItem ¶
func InsertMessageFieldListItem(parentMessage protoreflect.Message, listField protoreflect.FieldDescriptor, index int, new any) error
InsertMessageFieldListItem insert the provided value at specified index into the list value inside a list field within the given message, by expanding list, moving necessary items and setting value under the specified index according to proto and protopatch assignment rules. It may panic if the provided parent message is invalid, the list field descriptor do not belongs to the message or the given index is out of bounds of the list. It returns ErrMismatchingType error when value type do not matches any of types that would allow appending. Note thet when the index is exactly equal to the length of the list, insert behaves like append and do not panics due to out of bound index.
func InterfaceOfListItem ¶
func InterfaceOfListItem(listField protoreflect.FieldDescriptor, value protoreflect.Value) any
InterfaceOfListItem returns an interface value associated with the given list item value. It may panic or return invalid result if the field descriptor do not describes the list that the given item value belongs to. For scalar types and messages it returns its value.
func InterfaceOfMapItem ¶
func InterfaceOfMapItem(mapField protoreflect.FieldDescriptor, value protoreflect.Value) any
InterfaceOfMapItem returns an interface value associated with the given map item value. It may panic or return invalid result if the field descriptor do not describes the map that the given item value belongs to. For scalar types and messages it returns its value.
func InterfaceOfMessageField ¶
func InterfaceOfMessageField(field protoreflect.FieldDescriptor, value protoreflect.Value) any
InterfaceOfMessageField returns an interface value associated with the given field value. It may panic or return invalid result if the field descriptor do not describes the provided value. For scalar types and messages it returns its value. For lists and maps it returns List and Map interfaces accordingly.
func InterfaceValue ¶
func InterfaceValue(i any) protoreflect.Value
InterfaceValue returns an protoreflect.Value associated with the given list item interface value. It may panic or return invalid result if the provided value cannot be represented as protoreflect.Value.
func IsTypeMapOfProtoMessageInterfaces ¶
IsTypeMapOfProtoMessageInterfaces reports weather the provided type is a map of proto message interfaces, that means it is map[K]proto.Message or map[K]protoreflace.Message where K is any valid map key type.
func IsTypeMatchesProtoScalarKind ¶
func IsTypeMatchesProtoScalarKind(kind protoreflect.Kind, t reflect.Type) bool
IsTypeMatchesProtoScalarKind reports is the provided protoreflect.Kind matches the given type. Check is only valid for scalar protoreflect types, that is: protoreflect.BoolKind, protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind, protoreflect.EnumKind, protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind, protoreflect.Uint32Kind, protoreflect.Fixed32Kind, protoreflect.Uint64Kind, protoreflect.Fixed64Kind, protoreflect.FloatKind, protoreflect.DoubleKind, protoreflect.StringKind, protoreflect.BytesKind.
func IsTypeSliceOfProtoMessageInterfaces ¶
IsTypeSliceOfProtoMessageInterfaces reports weather the provided type is a slice of proto message interfaces, that means it is []proto.Message or []protoreflace.Message.
func IsValueTypeMatchesProtoField ¶
func IsValueTypeMatchesProtoField(field protoreflect.FieldDescriptor, v reflect.Value) bool
IsValueTypeMatchesProtoField reports if type of the provided value matches the given protoreflect.FieldDescriptor. If the type matches it can be assigned to field using standard proto and protopatch rules for assignment.
func MessageDescriptorFromType ¶
func MessageDescriptorFromType(t reflect.Type) protoreflect.MessageDescriptor
MessageDescriptorFromType retrieves protoreflect.MessageDescriptor if the provided type contains an implementation of proto.Message or protoreflect.Message. Otherwise it returns nil.
func MessageDescriptorFromValue ¶
func MessageDescriptorFromValue(v reflect.Value) protoreflect.MessageDescriptor
MessageDescriptorFromType retrieves protoreflect.MessageDescriptor if the provided value contains an implementation of proto.Message or protoreflect.Message. Otherwise it returns nil.
func MessageDescriptorFromValueOfMapOfProtoMessages ¶
func MessageDescriptorFromValueOfMapOfProtoMessages(v reflect.Value) protoreflect.MessageDescriptor
MessageDescriptorFromValueOfMapOfProtoMessages returns common message descriptor form the provided map of proto message. If the given value does not contain a slice of proto messages or proto messages interfaces, if the there is more than one descriptor or if descriptor cannot be determined, function returns nil.
func MessageDescriptorFromValueOfSliceOfProtoMessages ¶
func MessageDescriptorFromValueOfSliceOfProtoMessages(v reflect.Value) protoreflect.MessageDescriptor
MessageDescriptorFromValueOfSliceOfProtoMessages returns common message descriptor form the provided slice of proto message. If the given value does not contain a slice of proto messages or proto messages interfaces, if the there is more than one descriptor or if descriptor cannot be determined, function returns nil.
func NewProtoreflectOfMessage ¶
func NewProtoreflectOfMessage(m proto.Message) protoreflect.Message
NewProtoreflectOfMessage returns new mutable protoreflect.Message value having a type like the provided proto.Message or nil if the message is invalid.
func ParseListIndex ¶
ParseListIndex parses the provided name as list index. It returns o and false if the provided name cannot be parsed. Note, the index can be negative, indicating reverse list counting.
func ParseMapKey ¶
func ParseMapKey(keyType protoreflect.FieldDescriptor, name string) protoreflect.MapKey
ParseMapKey parses the provided name as map key. It returns invalid map key if the provided name cannot be parsed.
func ParsedIndexInList ¶
ParsedIndexInList parses the provided name as list index based on the given list length. It returns -1 if the provided name cannot be parsed or index is outside the bounds of list. Otherwise the function never returns negative indexes as negative indexes are normalized.
func ParsedKeyInMap ¶
func ParsedKeyInMap(m protoreflect.Map, keyType protoreflect.FieldDescriptor, name string) protoreflect.MapKey
ParsedKeyInMap parses the provided name as map key. It returns invalid map key if the provided name cannot be parsed or was not found in map.
func ProtoreflectOfAny ¶
func ProtoreflectOfAny(v any) protoreflect.Message
ProtoreflectOfAny returns protoreflect.Message value of the provided proto.Message or protoreflect.Message. If the provided value does not contains a valid proto.Message or protoreflect.Message function returns nil.
func ProtoreflectOfMessage ¶
func ProtoreflectOfMessage(m proto.Message) protoreflect.Message
ProtoreflectOfMessage returns protoreflect.Message value of the provided proto.Message or nil if the message is invalid.
func SetListItem ¶
SetListItem assigns the provided value to the list index inside the given list, by setting value under the specified index according to proto and protopatch assignment rules. It may panic if the provided list is invalid or is read only, the given index is out of bounds of the list. It returns ErrMismatchingType error when value type do not matches any of types that allows assignment.
func SetMapItem ¶
func SetMapItem(ma Map, key protoreflect.MapKey, to any) error
SetMapItem assigns the provided value to the map key inside the given map, by setting value under the specified map key according to proto and protopatch assignment rules. It may panic if the provided map is invalid or read only, map key is invalid or its type do not matches map key type. It returns ErrMismatchingType error when value type do not matches any of types that allows assignment.
func SetMessageField ¶
func SetMessageField(m protoreflect.Message, field protoreflect.FieldDescriptor, to any) error
SetMessageField assigns the provided value to message field, by setting field value according to proto and protopatch assignment rules. It may panic if the provided message is invalid or the field descriptor do not belongs to the message. It returns ErrMismatchingType error when value type do not matches any of types that allows assignment.
func SetMessageFieldListItem ¶
func SetMessageFieldListItem(parentMessage protoreflect.Message, listField protoreflect.FieldDescriptor, index int, to any) error
SetMessageFieldListItem assigns the provided value to the list index inside a list field within the given message, by setting value under the specified index according to proto and protopatch assignment rules. It may panic if the provided parent message is invalid, the list field descriptor do not belongs to the message, list is not mutable or the given index is out of bounds of the list. It returns ErrMismatchingType error when value type do not matches any of types that allows assignment.
func SetMessageFieldMapItem ¶
func SetMessageFieldMapItem(parentMessage protoreflect.Message, mapField protoreflect.FieldDescriptor, key protoreflect.MapKey, to any) error
SetMessageFieldMapItem assigns the provided value to the map key inside a map field within the given message, by setting value under the specified map key according to proto and protopatch assignment rules. It may panic if the provided parent message is invalid, the map field descriptor does not describes a map field or does not belongs to the message, map key is invalid or its type do not matches map key type. It returns ErrMismatchingType error when value type do not matches any of types that allows assignment.
Types ¶
type List ¶
type List interface {
protoreflect.List
Iter() iter.Seq2[int, protoreflect.Value]
ParentFieldDescriptor() protoreflect.FieldDescriptor
AsGoSlice() any
}
List represents a protocol buffer list value.
func NewList ¶
func NewList(parentField protoreflect.FieldDescriptor, li protoreflect.List) List
type Map ¶
type Map interface {
protoreflect.Map
Iter() iter.Seq2[protoreflect.MapKey, protoreflect.Value]
ParentFieldDescriptor() protoreflect.FieldDescriptor
AsGoMap() any
}
Map represents a protocol buffer map value.
func NewMap ¶
func NewMap(parentField protoreflect.FieldDescriptor, ma protoreflect.Map) Map