Documentation ¶
Overview ¶
Package dynamicpb creates protocol buffer messages using runtime type information.
Index ¶
- func NewExtensionType(desc pref.ExtensionDescriptor) pref.ExtensionType
- func NewMessageType(desc pref.MessageDescriptor) pref.MessageType
- type Message
- func (m *Message) Clear(fd pref.FieldDescriptor)
- func (m *Message) Descriptor() pref.MessageDescriptor
- func (m *Message) Get(fd pref.FieldDescriptor) pref.Value
- func (m *Message) GetUnknown() pref.RawFields
- func (m *Message) Has(fd pref.FieldDescriptor) bool
- func (m *Message) Interface() pref.ProtoMessage
- func (m *Message) IsValid() bool
- func (m *Message) Mutable(fd pref.FieldDescriptor) pref.Value
- func (m *Message) New() pref.Message
- func (m *Message) NewField(fd pref.FieldDescriptor) pref.Value
- func (m *Message) ProtoMethods() *protoiface.Methods
- func (m *Message) ProtoReflect() pref.Message
- func (m *Message) Range(f func(pref.FieldDescriptor, pref.Value) bool)
- func (m *Message) Set(fd pref.FieldDescriptor, v pref.Value)
- func (m *Message) SetUnknown(r pref.RawFields)
- func (m *Message) String() string
- func (m *Message) Type() pref.MessageType
- func (m *Message) WhichOneof(od pref.OneofDescriptor) pref.FieldDescriptor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewExtensionType ¶
func NewExtensionType(desc pref.ExtensionDescriptor) pref.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 interface{}) protoreflect.Value { return protoreflect.ValueOf(iv) } func (xt extensionType) InterfaceOf(v protoreflect.Value) interface{} { 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 pref.MessageDescriptor) pref.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 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 pref.MessageDescriptor) *Message
NewMessage creates a new message with the provided descriptor.
func (*Message) Clear ¶
func (m *Message) Clear(fd pref.FieldDescriptor)
Clear clears a field. See protoreflect.Message for details.
func (*Message) Descriptor ¶
func (m *Message) Descriptor() pref.MessageDescriptor
Descriptor returns the message descriptor.
func (*Message) Get ¶
func (m *Message) Get(fd pref.FieldDescriptor) pref.Value
Get returns the value of a field. See protoreflect.Message for details.
func (*Message) GetUnknown ¶
GetUnknown returns the raw unknown fields. See protoreflect.Message for details.
func (*Message) Has ¶
func (m *Message) Has(fd pref.FieldDescriptor) bool
Has reports whether a field is populated. See protoreflect.Message for details.
func (*Message) Interface ¶
func (m *Message) Interface() pref.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 pref.FieldDescriptor) pref.Value
Mutable returns a mutable reference to a repeated, map, or message field. See protoreflect.Message for details.
func (*Message) New ¶
New returns a newly allocated empty message with the same descriptor. See protoreflect.Message for details.
func (*Message) NewField ¶
func (m *Message) NewField(fd pref.FieldDescriptor) pref.Value
NewField returns a new value for assignable to the field of a given descriptor. See protoreflect.Message for details.
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 ¶
ProtoReflect implements the protoreflect.ProtoMessage interface.
func (*Message) Range ¶
Range visits every populated field in undefined order. See protoreflect.Message for details.
func (*Message) Set ¶
func (m *Message) Set(fd pref.FieldDescriptor, v pref.Value)
Set stores a value in a field. See protoreflect.Message for details.
func (*Message) SetUnknown ¶
SetUnknown sets the raw unknown fields. See protoreflect.Message for details.
func (*Message) WhichOneof ¶
func (m *Message) WhichOneof(od pref.OneofDescriptor) pref.FieldDescriptor
WhichOneof reports which field in a oneof is populated, returning nil if none are populated. See protoreflect.Message for details.