Documentation ¶
Overview ¶
Package dynamicpb creates protocol buffer messages using runtime type information.
Index ¶
- func NewEnumType(desc protoreflect.EnumDescriptor) protoreflect.EnumType
- func NewExtensionType(desc protoreflect.ExtensionDescriptor) protoreflect.ExtensionType
- func NewMessageType(desc protoreflect.MessageDescriptor) protoreflect.MessageType
- type Message
- func (m *Message) Clear(fd protoreflect.FieldDescriptor)
- func (m *Message) Descriptor() protoreflect.MessageDescriptor
- func (m *Message) Get(fd protoreflect.FieldDescriptor) protoreflect.Value
- func (m *Message) GetUnknown() protoreflect.RawFields
- func (m *Message) Has(fd protoreflect.FieldDescriptor) bool
- func (m *Message) Interface() protoreflect.ProtoMessage
- func (m *Message) IsValid() bool
- func (m *Message) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value
- func (m *Message) New() protoreflect.Message
- func (m *Message) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value
- func (m *Message) ProtoMessage()
- func (m *Message) ProtoMethods() *protoiface.Methods
- func (m *Message) ProtoReflect() protoreflect.Message
- func (m *Message) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool)
- func (m *Message) Reset()
- func (m *Message) Set(fd protoreflect.FieldDescriptor, v protoreflect.Value)
- func (m *Message) SetUnknown(r protoreflect.RawFields)
- func (m *Message) String() string
- func (m *Message) Type() protoreflect.MessageType
- func (m *Message) WhichOneof(od protoreflect.OneofDescriptor) protoreflect.FieldDescriptor
- type Types
- func (t *Types) FindEnumByName(name protoreflect.FullName) (protoreflect.EnumType, error)
- func (t *Types) FindExtensionByName(name protoreflect.FullName) (protoreflect.ExtensionType, error)
- func (t *Types) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error)
- func (t *Types) FindMessageByName(name protoreflect.FullName) (protoreflect.MessageType, error)
- func (t *Types) FindMessageByURL(url string) (protoreflect.MessageType, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewEnumType ¶ added in v1.25.0
func NewEnumType(desc protoreflect.EnumDescriptor) protoreflect.EnumType
NewEnumType creates a new EnumType with the provided descriptor.
EnumTypes created by this package are equal if their descriptors are equal. That is, if ed1 == ed2, then NewEnumType(ed1) == NewEnumType(ed2).
Enum values created by the EnumType are equal if their numbers are equal.
func NewExtensionType ¶
func NewExtensionType(desc protoreflect.ExtensionDescriptor) protoreflect.ExtensionType
NewExtensionType creates a new ExtensionType with the provided descriptor.
Dynamic ExtensionTypes with the same descriptor compare as equal. That is, if xd1 == xd2, then NewExtensionType(xd1) == NewExtensionType(xd2).
The InterfaceOf and ValueOf methods of the extension type are defined as:
func (xt extensionType) ValueOf(iv any) protoreflect.Value { return protoreflect.ValueOf(iv) } func (xt extensionType) InterfaceOf(v protoreflect.Value) any { return v.Interface() }
The Go type used by the proto.GetExtension and proto.SetExtension functions is determined by these methods, and is therefore equivalent to the Go type used to represent a protoreflect.Value. See the protoreflect.Value documentation for more details.
func NewMessageType ¶
func NewMessageType(desc protoreflect.MessageDescriptor) protoreflect.MessageType
NewMessageType creates a new MessageType with the provided descriptor.
MessageTypes created by this package are equal if their descriptors are equal. That is, if md1 == md2, then NewMessageType(md1) == NewMessageType(md2).
Types ¶
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
A Message is a dynamically constructed protocol buffer message.
Message implements the google.golang.org/protobuf/proto.Message interface, and may be used with all standard proto package functions such as Marshal, Unmarshal, and so forth.
Message also implements the protoreflect.Message interface. See the protoreflect package documentation for that interface for how to get and set fields and otherwise interact with the contents of a Message.
Reflection API functions which construct messages, such as NewField, return new dynamic messages of the appropriate type. Functions which take messages, such as Set for a message-value field, will accept any message with a compatible type.
Operations which modify a Message are not safe for concurrent use.
func NewMessage ¶
func NewMessage(desc protoreflect.MessageDescriptor) *Message
NewMessage creates a new message with the provided descriptor.
func (*Message) Clear ¶
func (m *Message) Clear(fd protoreflect.FieldDescriptor)
Clear clears a field. See protoreflect.Message for details.
func (*Message) Descriptor ¶
func (m *Message) Descriptor() protoreflect.MessageDescriptor
Descriptor returns the message descriptor.
func (*Message) Get ¶
func (m *Message) Get(fd protoreflect.FieldDescriptor) protoreflect.Value
Get returns the value of a field. See protoreflect.Message for details.
func (*Message) GetUnknown ¶
func (m *Message) GetUnknown() protoreflect.RawFields
GetUnknown returns the raw unknown fields. See protoreflect.Message for details.
func (*Message) Has ¶
func (m *Message) Has(fd protoreflect.FieldDescriptor) bool
Has reports whether a field is populated. See protoreflect.Message for details.
func (*Message) Interface ¶
func (m *Message) Interface() protoreflect.ProtoMessage
Interface returns the message. See protoreflect.Message for details.
func (*Message) IsValid ¶
IsValid reports whether the message is valid. See protoreflect.Message for details.
func (*Message) Mutable ¶
func (m *Message) Mutable(fd protoreflect.FieldDescriptor) protoreflect.Value
Mutable returns a mutable reference to a repeated, map, or message field. See protoreflect.Message for details.
func (*Message) New ¶
func (m *Message) New() protoreflect.Message
New returns a newly allocated empty message with the same descriptor. See protoreflect.Message for details.
func (*Message) NewField ¶
func (m *Message) NewField(fd protoreflect.FieldDescriptor) protoreflect.Value
NewField returns a new value for assignable to the field of a given descriptor. See protoreflect.Message for details.
func (*Message) ProtoMessage ¶ added in v1.21.0
func (m *Message) ProtoMessage()
ProtoMessage implements the legacy message interface.
func (*Message) ProtoMethods ¶
func (m *Message) ProtoMethods() *protoiface.Methods
ProtoMethods is an internal detail of the protoreflect.Message interface. Users should never call this directly.
func (*Message) ProtoReflect ¶
func (m *Message) ProtoReflect() protoreflect.Message
ProtoReflect implements the protoreflect.ProtoMessage interface.
func (*Message) Range ¶
func (m *Message) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool)
Range visits every populated field in undefined order. See protoreflect.Message for details.
func (*Message) Reset ¶ added in v1.21.0
func (m *Message) Reset()
Reset clears the message to be empty, but preserves the dynamic message type.
func (*Message) Set ¶
func (m *Message) Set(fd protoreflect.FieldDescriptor, v protoreflect.Value)
Set stores a value in a field. See protoreflect.Message for details.
func (*Message) SetUnknown ¶
func (m *Message) SetUnknown(r protoreflect.RawFields)
SetUnknown sets the raw unknown fields. See protoreflect.Message for details.
func (*Message) Type ¶
func (m *Message) Type() protoreflect.MessageType
Type returns the message type.
func (*Message) WhichOneof ¶
func (m *Message) WhichOneof(od protoreflect.OneofDescriptor) protoreflect.FieldDescriptor
WhichOneof reports which field in a oneof is populated, returning nil if none are populated. See protoreflect.Message for details.
type Types ¶ added in v1.31.0
type Types struct {
// contains filtered or unexported fields
}
A Types is a collection of dynamically constructed descriptors. Its methods are safe for concurrent use.
Types implements protoregistry.MessageTypeResolver and protoregistry.ExtensionTypeResolver. A Types may be used as a google.golang.org/protobuf/proto.UnmarshalOptions.Resolver.
func NewTypes ¶ added in v1.31.0
func NewTypes(f *protoregistry.Files) *Types
NewTypes creates a new Types registry with the provided files. The Files registry is retained, and changes to Files will be reflected in Types. It is not safe to concurrently change the Files while calling Types methods.
func (*Types) FindEnumByName ¶ added in v1.31.0
func (t *Types) FindEnumByName(name protoreflect.FullName) (protoreflect.EnumType, error)
FindEnumByName looks up an enum by its full name; e.g., "google.protobuf.Field.Kind".
This returns (nil, protoregistry.NotFound) if not found.
func (*Types) FindExtensionByName ¶ added in v1.31.0
func (t *Types) FindExtensionByName(name protoreflect.FullName) (protoreflect.ExtensionType, error)
FindExtensionByName looks up an extension field by the field's full name. Note that this is the full name of the field as determined by where the extension is declared and is unrelated to the full name of the message being extended.
This returns (nil, protoregistry.NotFound) if not found.
func (*Types) FindExtensionByNumber ¶ added in v1.31.0
func (t *Types) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error)
FindExtensionByNumber looks up an extension field by the field number within some parent message, identified by full name.
This returns (nil, protoregistry.NotFound) if not found.
func (*Types) FindMessageByName ¶ added in v1.31.0
func (t *Types) FindMessageByName(name protoreflect.FullName) (protoreflect.MessageType, error)
FindMessageByName looks up a message by its full name; e.g. "google.protobuf.Any".
This returns (nil, protoregistry.NotFound) if not found.
func (*Types) FindMessageByURL ¶ added in v1.31.0
func (t *Types) FindMessageByURL(url string) (protoreflect.MessageType, error)
FindMessageByURL looks up a message by a URL identifier. See documentation on google.protobuf.Any.type_url for the URL format.
This returns (nil, protoregistry.NotFound) if not found.