Documentation ¶
Index ¶
- Constants
- func AberrantDeriveFullName(t reflect.Type) protoreflect.FullName
- func EnableLazyUnmarshal(enable bool)
- func InitExtensionInfo(xi *ExtensionInfo, xd protoreflect.ExtensionDescriptor, goType reflect.Type)
- func IsLazy(m protoreflect.Message, fd protoreflect.FieldDescriptor) bool
- func LazyEnabled() bool
- func LegacyLoadEnumDesc(t reflect.Type) protoreflect.EnumDescriptor
- func LegacyLoadMessageDesc(t reflect.Type) protoreflect.MessageDescriptor
- func UnmarshalField(m interface{}, num protowire.Number)
- type Converter
- type EnumInfo
- type Export
- func (Export) AtomicCheckPointerIsNil(ptr any) bool
- func (Export) AtomicInitializePointer(ptr Pointer, dst Pointer)
- func (Export) AtomicLoadPointer(ptr Pointer, dst Pointer)
- func (Export) AtomicSetPointer(dstPtr, valPtr any)
- func (Export) ClearPresent(part *uint32, num uint32)
- func (Export) ClearWeak(w *WeakFields, num protoreflect.FieldNumber)
- func (Export) CompressGZIP(in []byte) (out []byte)
- func (Export) EnumDescriptorOf(e enum) protoreflect.EnumDescriptor
- func (Export) EnumOf(e enum) protoreflect.Enum
- func (Export) EnumStringOf(ed protoreflect.EnumDescriptor, n protoreflect.EnumNumber) string
- func (Export) EnumTypeOf(e enum) protoreflect.EnumType
- func (Export) GetWeak(w WeakFields, num protoreflect.FieldNumber, name protoreflect.FullName) protoreflect.ProtoMessage
- func (Export) HasWeak(w WeakFields, num protoreflect.FieldNumber) bool
- func (Export) LegacyEnumName(ed protoreflect.EnumDescriptor) string
- func (Export) LegacyMessageTypeOf(m protoiface.MessageV1, name protoreflect.FullName) protoreflect.MessageType
- func (Export) MessageDescriptorOf(m message) protoreflect.MessageDescriptor
- func (Export) MessageFieldStringOf(md protoreflect.MessageDescriptor, n protoreflect.FieldNumber) string
- func (Export) MessageOf(m message) protoreflect.Message
- func (Export) MessageStateOf(p Pointer) *messageState
- func (Export) MessageStringOf(m protoreflect.ProtoMessage) string
- func (Export) MessageTypeOf(m message) protoreflect.MessageType
- func (Export) NewError(f string, x ...any) error
- func (Export) Present(part *uint32, num uint32) bool
- func (Export) ProtoMessageV1Of(m message) protoiface.MessageV1
- func (Export) ProtoMessageV2Of(m message) protoreflect.ProtoMessage
- func (Export) SetPresent(part *uint32, num uint32, size uint32)
- func (Export) SetPresentNonAtomic(part *uint32, num uint32, size uint32)
- func (Export) SetWeak(w *WeakFields, num protoreflect.FieldNumber, name protoreflect.FullName, ...)
- func (Export) UnmarshalField(msg any, fieldNum int32)
- func (Export) UnmarshalJSONEnum(ed protoreflect.EnumDescriptor, b []byte) (protoreflect.EnumNumber, error)
- type ExtensionField
- type ExtensionFields
- type ExtensionInfo
- func (xi *ExtensionInfo) InterfaceOf(v protoreflect.Value) any
- func (xi *ExtensionInfo) IsValidInterface(v any) bool
- func (xi *ExtensionInfo) IsValidValue(v protoreflect.Value) bool
- func (xi *ExtensionInfo) New() protoreflect.Value
- func (xi *ExtensionInfo) TypeDescriptor() protoreflect.ExtensionTypeDescriptor
- func (xi *ExtensionInfo) ValueOf(v any) protoreflect.Value
- func (xi *ExtensionInfo) Zero() protoreflect.Value
- type MessageInfo
- func (mi *MessageInfo) Descriptor() protoreflect.MessageDescriptor
- func (mi *MessageInfo) Enum(i int) protoreflect.EnumType
- func (mi *MessageInfo) Message(i int) protoreflect.MessageType
- func (mi *MessageInfo) MessageOf(m any) protoreflect.Message
- func (mi *MessageInfo) New() protoreflect.Message
- func (mi *MessageInfo) Zero() protoreflect.Message
- type MessageState
- type Pointer
- type RaceDetectHookData
- type SizeCache
- type UnknownFields
- type ValidationStatus
- type WeakFields
Constants ¶
const UnsafeEnabled = true
Variables ¶
This section is empty.
Functions ¶
func AberrantDeriveFullName ¶
func AberrantDeriveFullName(t reflect.Type) protoreflect.FullName
AberrantDeriveFullName derives a fully qualified protobuf name for the given Go type The provided name is not guaranteed to be stable nor universally unique. It should be sufficiently unique within a program.
This is exported for testing purposes.
func EnableLazyUnmarshal ¶ added in v1.36.0
func EnableLazyUnmarshal(enable bool)
EnableLazyUnmarshal enables lazy unmarshaling.
func InitExtensionInfo ¶
func InitExtensionInfo(xi *ExtensionInfo, xd protoreflect.ExtensionDescriptor, goType reflect.Type)
func IsLazy ¶
func IsLazy(m protoreflect.Message, fd protoreflect.FieldDescriptor) bool
IsLazy reports whether a field is lazily encoded. It is exported for testing.
func LazyEnabled ¶ added in v1.36.0
func LazyEnabled() bool
LazyEnabled reports whether lazy unmarshalling is currently enabled.
func LegacyLoadEnumDesc ¶
func LegacyLoadEnumDesc(t reflect.Type) protoreflect.EnumDescriptor
LegacyLoadEnumDesc returns an EnumDescriptor derived from the Go type, which must be an int32 kind and not implement the v2 API already.
This is exported for testing purposes.
func LegacyLoadMessageDesc ¶
func LegacyLoadMessageDesc(t reflect.Type) protoreflect.MessageDescriptor
LegacyLoadMessageDesc returns an MessageDescriptor derived from the Go type, which should be a *struct kind and must not implement the v2 API already.
This is exported for testing purposes.
func UnmarshalField ¶ added in v1.36.0
UnmarshalField unmarshals a field in a message.
Types ¶
type Converter ¶
type Converter interface { // PBValueOf converts a reflect.Value to a protoreflect.Value. PBValueOf(reflect.Value) protoreflect.Value // GoValueOf converts a protoreflect.Value to a reflect.Value. GoValueOf(protoreflect.Value) reflect.Value // IsValidPB returns whether a protoreflect.Value is compatible with this type. IsValidPB(protoreflect.Value) bool // IsValidGo returns whether a reflect.Value is compatible with this type. IsValidGo(reflect.Value) bool // New returns a new field value. // For scalars, it returns the default value of the field. // For composite types, it returns a new mutable value. New() protoreflect.Value // Zero returns a new field value. // For scalars, it returns the default value of the field. // For composite types, it returns an immutable, empty value. Zero() protoreflect.Value }
A Converter coverts to/from Go reflect.Value types and protobuf protoreflect.Value types.
func NewConverter ¶
func NewConverter(t reflect.Type, fd protoreflect.FieldDescriptor) Converter
NewConverter matches a Go type with a protobuf field and returns a Converter that converts between the two. Enums must be a named int32 kind that implements protoreflect.Enum, and messages must be pointer to a named struct type that implements protoreflect.ProtoMessage.
This matcher deliberately supports a wider range of Go types than what protoc-gen-go historically generated to be able to automatically wrap some v1 messages generated by other forks of protoc-gen-go.
type EnumInfo ¶
type EnumInfo struct { GoReflectType reflect.Type // int32 kind Desc protoreflect.EnumDescriptor }
func (*EnumInfo) Descriptor ¶
func (t *EnumInfo) Descriptor() protoreflect.EnumDescriptor
func (*EnumInfo) New ¶
func (t *EnumInfo) New(n protoreflect.EnumNumber) protoreflect.Enum
type Export ¶
type Export struct{}
Export is a zero-length named type that exists only to export a set of functions that we do not want to appear in godoc.
func (Export) AtomicCheckPointerIsNil ¶ added in v1.36.0
AtomicCheckPointerIsNil takes an interface (which is a pointer to a pointer) and returns true if the pointed-to pointer is nil (using an atomic load). This function is inlineable and, on x86, just becomes a simple load and compare.
func (Export) AtomicInitializePointer ¶ added in v1.36.0
AtomicInitializePointer makes ptr and dst point to the same value.
If *ptr is a nil pointer, it sets *ptr = *dst.
If *ptr is a non-nil pointer, it sets *dst = *ptr.
func (Export) AtomicLoadPointer ¶ added in v1.36.0
AtomicLoadPointer loads the pointer at the location pointed at by src, and stores that pointer value into the location pointed at by dst.
func (Export) AtomicSetPointer ¶ added in v1.36.0
AtomicSetPointer takes two interfaces (first is a pointer to a pointer, second is a pointer) and atomically sets the second pointer into location referenced by first pointer. Unfortunately, atomicSetPointer() does not inline (even on x86), so this does not become a simple store on x86.
func (Export) ClearPresent ¶ added in v1.36.0
ClearPresence removes a field from the presence set. part is a pointer to the relevant element in the presence array and num is the field number unaltered.
func (Export) ClearWeak ¶ added in v1.22.0
func (Export) ClearWeak(w *WeakFields, num protoreflect.FieldNumber)
func (Export) CompressGZIP ¶
CompressGZIP compresses the input as a GZIP-encoded file. The current implementation does no compression.
func (Export) EnumDescriptorOf ¶
func (Export) EnumDescriptorOf(e enum) protoreflect.EnumDescriptor
EnumDescriptorOf returns the protoreflect.EnumDescriptor for e. It returns nil if e is nil.
func (Export) EnumOf ¶
func (Export) EnumOf(e enum) protoreflect.Enum
EnumOf returns the protoreflect.Enum interface over e. It returns nil if e is nil.
func (Export) EnumStringOf ¶
func (Export) EnumStringOf(ed protoreflect.EnumDescriptor, n protoreflect.EnumNumber) string
EnumStringOf returns the enum value as a string, either as the name if the number is resolvable, or the number formatted as a string.
func (Export) EnumTypeOf ¶
func (Export) EnumTypeOf(e enum) protoreflect.EnumType
EnumTypeOf returns the protoreflect.EnumType for e. It returns nil if e is nil.
func (Export) GetWeak ¶ added in v1.22.0
func (Export) GetWeak(w WeakFields, num protoreflect.FieldNumber, name protoreflect.FullName) protoreflect.ProtoMessage
func (Export) HasWeak ¶ added in v1.22.0
func (Export) HasWeak(w WeakFields, num protoreflect.FieldNumber) bool
func (Export) LegacyEnumName ¶
func (Export) LegacyEnumName(ed protoreflect.EnumDescriptor) string
LegacyEnumName returns the name of enums used in legacy code.
func (Export) LegacyMessageTypeOf ¶
func (Export) LegacyMessageTypeOf(m protoiface.MessageV1, name protoreflect.FullName) protoreflect.MessageType
LegacyMessageTypeOf returns the protoreflect.MessageType for m, with name used as the message name if necessary.
func (Export) MessageDescriptorOf ¶
func (Export) MessageDescriptorOf(m message) protoreflect.MessageDescriptor
MessageDescriptorOf returns the protoreflect.MessageDescriptor for m. It returns nil if m is nil.
func (Export) MessageFieldStringOf ¶ added in v1.36.0
func (Export) MessageFieldStringOf(md protoreflect.MessageDescriptor, n protoreflect.FieldNumber) string
MessageFieldStringOf returns the field formatted as a string, either as the field name if resolvable otherwise as a decimal string.
func (Export) MessageOf ¶
func (Export) MessageOf(m message) protoreflect.Message
MessageOf returns the protoreflect.Message interface over m. It returns nil if m is nil.
func (Export) MessageStateOf ¶
func (Export) MessageStringOf ¶
func (Export) MessageStringOf(m protoreflect.ProtoMessage) string
MessageStringOf returns the message value as a string, which is the message serialized in the protobuf text format.
func (Export) MessageTypeOf ¶
func (Export) MessageTypeOf(m message) protoreflect.MessageType
MessageTypeOf returns the protoreflect.MessageType for m. It returns nil if m is nil.
func (Export) NewError ¶ added in v1.25.0
NewError formats a string according to the format specifier and arguments and returns an error that has a "proto" prefix.
func (Export) Present ¶ added in v1.36.0
Present checks the presence set for a certain field number (zero based, ordered by appearance in original proto file). part is a pointer to the correct element in the bitmask array, num is the field number unaltered. Example (field number 70 -> part = &m.XXX_presence[1], num = 70)
func (Export) ProtoMessageV1Of ¶
func (Export) ProtoMessageV1Of(m message) protoiface.MessageV1
ProtoMessageV1Of converts either a v1 or v2 message to a v1 message. It returns nil if m is nil.
func (Export) ProtoMessageV2Of ¶
func (Export) ProtoMessageV2Of(m message) protoreflect.ProtoMessage
ProtoMessageV2Of converts either a v1 or v2 message to a v2 message. It returns nil if m is nil.
func (Export) SetPresent ¶ added in v1.36.0
SetPresent adds a field to the presence set. part is a pointer to the relevant element in the array and num is the field number unaltered. size is the number of fields in the protocol buffer.
func (Export) SetPresentNonAtomic ¶ added in v1.36.0
SetPresentNonAtomic is like SetPresent, but operates non-atomically. It is meant for use by builder methods, where the message is known not to be accessible yet by other goroutines.
func (Export) SetWeak ¶ added in v1.22.0
func (Export) SetWeak(w *WeakFields, num protoreflect.FieldNumber, name protoreflect.FullName, m protoreflect.ProtoMessage)
func (Export) UnmarshalField ¶ added in v1.36.0
func (Export) UnmarshalJSONEnum ¶
func (Export) UnmarshalJSONEnum(ed protoreflect.EnumDescriptor, b []byte) (protoreflect.EnumNumber, error)
UnmarshalJSONEnum unmarshals an enum from a JSON-encoded input. The input can either be a string representing the enum value by name, or a number representing the enum number itself.
type ExtensionField ¶
type ExtensionField struct {
// contains filtered or unexported fields
}
func (ExtensionField) IsSet ¶
func (f ExtensionField) IsSet() bool
IsSet returns whether the extension field is set. This may be called concurrently.
func (*ExtensionField) Set ¶
func (f *ExtensionField) Set(t protoreflect.ExtensionType, v protoreflect.Value)
Set sets the type and value of the extension field. This must not be called concurrently.
func (ExtensionField) Type ¶
func (f ExtensionField) Type() protoreflect.ExtensionType
Type returns the type of the extension field. This may be called concurrently.
func (*ExtensionField) Value ¶
func (f *ExtensionField) Value() protoreflect.Value
Value returns the value of the extension field. This may be called concurrently.
type ExtensionFields ¶
type ExtensionFields = map[int32]ExtensionField
type ExtensionInfo ¶
type ExtensionInfo struct { // ExtendedType is a typed nil-pointer to the parent message type that // is being extended. It is possible for this to be unpopulated in v2 // since the message may no longer implement the MessageV1 interface. // // Deprecated: Use the ExtendedType method instead. ExtendedType protoiface.MessageV1 // ExtensionType is the zero value of the extension type. // // For historical reasons, reflect.TypeOf(ExtensionType) and the // type returned by InterfaceOf may not be identical. // // Deprecated: Use InterfaceOf(xt.Zero()) instead. ExtensionType any // Field is the field number of the extension. // // Deprecated: Use the Descriptor().Number method instead. Field int32 // Name is the fully qualified name of extension. // // Deprecated: Use the Descriptor().FullName method instead. Name string // Tag is the protobuf struct tag used in the v1 API. // // Deprecated: Do not use. Tag string // Filename is the proto filename in which the extension is defined. // // Deprecated: Use Descriptor().ParentFile().Path() instead. Filename string // contains filtered or unexported fields }
ExtensionInfo implements ExtensionType.
This type contains a number of exported fields for legacy compatibility. The only non-deprecated use of this type is through the methods of the ExtensionType interface.
func (*ExtensionInfo) InterfaceOf ¶
func (xi *ExtensionInfo) InterfaceOf(v protoreflect.Value) any
func (*ExtensionInfo) IsValidInterface ¶
func (xi *ExtensionInfo) IsValidInterface(v any) bool
func (*ExtensionInfo) IsValidValue ¶
func (xi *ExtensionInfo) IsValidValue(v protoreflect.Value) bool
func (*ExtensionInfo) New ¶
func (xi *ExtensionInfo) New() protoreflect.Value
func (*ExtensionInfo) TypeDescriptor ¶
func (xi *ExtensionInfo) TypeDescriptor() protoreflect.ExtensionTypeDescriptor
func (*ExtensionInfo) ValueOf ¶
func (xi *ExtensionInfo) ValueOf(v any) protoreflect.Value
func (*ExtensionInfo) Zero ¶
func (xi *ExtensionInfo) Zero() protoreflect.Value
type MessageInfo ¶
type MessageInfo struct { // GoReflectType is the underlying message Go type and must be populated. GoReflectType reflect.Type // pointer to struct // Desc is the underlying message descriptor type and must be populated. Desc protoreflect.MessageDescriptor // Deprecated: Exporter will be removed the next time we bump // protoimpl.GenVersion. See https://github.com/golang/protobuf/issues/1640 Exporter exporter // OneofWrappers is list of pointers to oneof wrapper struct types. OneofWrappers []any // contains filtered or unexported fields }
MessageInfo provides protobuf related functionality for a given Go type that represents a message. A given instance of MessageInfo is tied to exactly one Go type, which must be a pointer to a struct type.
The exported fields must be populated before any methods are called and cannot be mutated after set.
func (*MessageInfo) Descriptor ¶
func (mi *MessageInfo) Descriptor() protoreflect.MessageDescriptor
func (*MessageInfo) Enum ¶ added in v1.26.0
func (mi *MessageInfo) Enum(i int) protoreflect.EnumType
func (*MessageInfo) Message ¶ added in v1.26.0
func (mi *MessageInfo) Message(i int) protoreflect.MessageType
func (*MessageInfo) MessageOf ¶
func (mi *MessageInfo) MessageOf(m any) protoreflect.Message
MessageOf returns a reflective view over a message. The input must be a pointer to a named Go struct. If the provided type has a ProtoReflect method, it must be implemented by calling this method.
func (*MessageInfo) New ¶
func (mi *MessageInfo) New() protoreflect.Message
func (*MessageInfo) Zero ¶
func (mi *MessageInfo) Zero() protoreflect.Message
type MessageState ¶
type MessageState struct { pragma.NoUnkeyedLiterals pragma.DoNotCompare pragma.DoNotCopy // contains filtered or unexported fields }
MessageState is a data structure that is nested as the first field in a concrete message. It provides a way to implement the ProtoReflect method in an allocation-free way without needing to have a shadow Go type generated for every message type. This technique only works using unsafe.
Example generated code:
type M struct { state protoimpl.MessageState Field1 int32 Field2 string Field3 *BarMessage ... } func (m *M) ProtoReflect() protoreflect.Message { mi := &file_fizz_buzz_proto_msgInfos[5] if protoimpl.UnsafeEnabled && m != nil { ms := protoimpl.X.MessageStateOf(Pointer(m)) if ms.LoadMessageInfo() == nil { ms.StoreMessageInfo(mi) } return ms } return mi.MessageOf(m) }
The MessageState type holds a *MessageInfo, which must be atomically set to the message info associated with a given message instance. By unsafely converting a *M into a *MessageState, the MessageState object has access to all the information needed to implement protobuf reflection. It has access to the message info as its first field, and a pointer to the MessageState is identical to a pointer to the concrete message value.
Requirements:
- The type M must implement protoreflect.ProtoMessage.
- The address of m must not be nil.
- The address of m and the address of m.state must be equal, even though they are different Go types.
type RaceDetectHookData ¶ added in v1.36.0
type RaceDetectHookData struct{}
There is no additional data as we're not running under race detector.
type UnknownFields ¶
type UnknownFields = unknownFieldsA // TODO: switch to unknownFieldsB
type ValidationStatus ¶
type ValidationStatus int
ValidationStatus is the result of validating the wire-format encoding of a message.
const ( // ValidationUnknown indicates that unmarshaling the message might succeed or fail. // The validator was unable to render a judgement. // // The only causes of this status are an aberrant message type appearing somewhere // in the message or a failure in the extension resolver. ValidationUnknown ValidationStatus = iota + 1 // ValidationInvalid indicates that unmarshaling the message will fail. ValidationInvalid // ValidationValid indicates that unmarshaling the message will succeed. ValidationValid // ValidationWrongWireType indicates that a validated field does not have // the expected wire type. ValidationWrongWireType )
func Validate ¶
func Validate(mt protoreflect.MessageType, in protoiface.UnmarshalInput) (out protoiface.UnmarshalOutput, _ ValidationStatus)
Validate determines whether the contents of the buffer are a valid wire encoding of the message type.
This function is exposed for testing.
func (ValidationStatus) String ¶
func (v ValidationStatus) String() string
type WeakFields ¶
type WeakFields = map[int32]protoreflect.ProtoMessage
Source Files ¶
- api_export.go
- api_export_opaque.go
- bitmap.go
- checkinit.go
- codec_extension.go
- codec_field.go
- codec_field_opaque.go
- codec_gen.go
- codec_map.go
- codec_map_go112.go
- codec_message.go
- codec_message_opaque.go
- codec_messageset.go
- codec_tables.go
- codec_unsafe.go
- convert.go
- convert_list.go
- convert_map.go
- decode.go
- encode.go
- enum.go
- equal.go
- extension.go
- lazy.go
- legacy_enum.go
- legacy_export.go
- legacy_extension.go
- legacy_file.go
- legacy_message.go
- merge.go
- merge_gen.go
- message.go
- message_opaque.go
- message_opaque_gen.go
- message_reflect.go
- message_reflect_field.go
- message_reflect_field_gen.go
- message_reflect_gen.go
- pointer_unsafe.go
- pointer_unsafe_opaque.go
- presence.go
- validate.go
- weak.go