protobuf: Index | Files

package impl

import ""


Package Files

api_export.go checkinit.go codec_extension.go codec_field.go codec_gen.go codec_map.go codec_map_go112.go codec_message.go codec_messageset.go codec_tables.go codec_unsafe.go convert.go convert_list.go convert_map.go decode.go encode.go enum.go extension.go legacy_enum.go legacy_export.go legacy_extension.go legacy_file.go legacy_message.go merge.go merge_gen.go message.go message_reflect.go message_reflect_field.go message_reflect_gen.go pointer_unsafe.go validate.go weak.go


const UnsafeEnabled = true

func AberrantDeriveFullName Uses

func AberrantDeriveFullName(t reflect.Type) pref.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 InitExtensionInfo Uses

func InitExtensionInfo(xi *ExtensionInfo, xd pref.ExtensionDescriptor, goType reflect.Type)

func IsLazy Uses

func IsLazy(m pref.Message, fd pref.FieldDescriptor) bool

IsLazy reports whether a field is lazily encoded. It is exported for testing.

func LegacyLoadEnumDesc Uses

func LegacyLoadEnumDesc(t reflect.Type) pref.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 Uses

func LegacyLoadMessageDesc(t reflect.Type) pref.MessageDescriptor

LegacyLoadMessageDesc returns an MessageDescriptor derived from the Go type, which must be a *struct kind and not implement the v2 API already.

This is exported for testing purposes.

type Converter Uses

type Converter interface {
    // PBValueOf converts a reflect.Value to a protoreflect.Value.
    PBValueOf(reflect.Value) pref.Value

    // GoValueOf converts a protoreflect.Value to a reflect.Value.
    GoValueOf(pref.Value) reflect.Value

    // IsValidPB returns whether a protoreflect.Value is compatible with this type.
    IsValidPB(pref.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() pref.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() pref.Value

A Converter coverts to/from Go reflect.Value types and protobuf protoreflect.Value types.

func NewConverter Uses

func NewConverter(t reflect.Type, fd pref.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 Uses

type EnumInfo struct {
    GoReflectType reflect.Type // int32 kind
    Desc          pref.EnumDescriptor

func (*EnumInfo) Descriptor Uses

func (t *EnumInfo) Descriptor() pref.EnumDescriptor

func (*EnumInfo) New Uses

func (t *EnumInfo) New(n pref.EnumNumber) pref.Enum

type Export Uses

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) ClearWeak Uses

func (Export) ClearWeak(w *WeakFields, num pref.FieldNumber)

func (Export) CompressGZIP Uses

func (Export) CompressGZIP(in []byte) (out []byte)

CompressGZIP compresses the input as a GZIP-encoded file. The current implementation does no compression.

func (Export) EnumDescriptorOf Uses

func (Export) EnumDescriptorOf(e enum) pref.EnumDescriptor

EnumDescriptorOf returns the protoreflect.EnumDescriptor for e. It returns nil if e is nil.

func (Export) EnumOf Uses

func (Export) EnumOf(e enum) pref.Enum

EnumOf returns the protoreflect.Enum interface over e. It returns nil if e is nil.

func (Export) EnumStringOf Uses

func (Export) EnumStringOf(ed pref.EnumDescriptor, n pref.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 Uses

func (Export) EnumTypeOf(e enum) pref.EnumType

EnumTypeOf returns the protoreflect.EnumType for e. It returns nil if e is nil.

func (Export) GetWeak Uses

func (Export) GetWeak(w WeakFields, num pref.FieldNumber, name pref.FullName) pref.ProtoMessage

func (Export) HasWeak Uses

func (Export) HasWeak(w WeakFields, num pref.FieldNumber) bool

func (Export) LegacyEnumName Uses

func (Export) LegacyEnumName(ed pref.EnumDescriptor) string

LegacyEnumName returns the name of enums used in legacy code.

func (Export) LegacyMessageTypeOf Uses

func (Export) LegacyMessageTypeOf(m piface.MessageV1, name pref.FullName) pref.MessageType

LegacyMessageTypeOf returns the protoreflect.MessageType for m, with name used as the message name if necessary.

func (Export) MessageDescriptorOf Uses

func (Export) MessageDescriptorOf(m message) pref.MessageDescriptor

MessageDescriptorOf returns the protoreflect.MessageDescriptor for m. It returns nil if m is nil.

func (Export) MessageOf Uses

func (Export) MessageOf(m message) pref.Message

MessageOf returns the protoreflect.Message interface over m. It returns nil if m is nil.

func (Export) MessageStateOf Uses

func (Export) MessageStateOf(p Pointer) *messageState

func (Export) MessageStringOf Uses

func (Export) MessageStringOf(m pref.ProtoMessage) string

MessageStringOf returns the message value as a string, which is the message serialized in the protobuf text format.

func (Export) MessageTypeOf Uses

func (Export) MessageTypeOf(m message) pref.MessageType

MessageTypeOf returns the protoreflect.MessageType for m. It returns nil if m is nil.

func (Export) NewError Uses

func (Export) NewError(f string, x ...interface{}) error

NewError formats a string according to the format specifier and arguments and returns an error that has a "proto" prefix.

func (Export) ProtoMessageV1Of Uses

func (Export) ProtoMessageV1Of(m message) piface.MessageV1

ProtoMessageV1Of converts either a v1 or v2 message to a v1 message. It returns nil if m is nil.

func (Export) ProtoMessageV2Of Uses

func (Export) ProtoMessageV2Of(m message) pref.ProtoMessage

ProtoMessageV2Of converts either a v1 or v2 message to a v2 message. It returns nil if m is nil.

func (Export) SetWeak Uses

func (Export) SetWeak(w *WeakFields, num pref.FieldNumber, name pref.FullName, m pref.ProtoMessage)

func (Export) UnmarshalJSONEnum Uses

func (Export) UnmarshalJSONEnum(ed pref.EnumDescriptor, b []byte) (pref.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 Uses

type ExtensionField struct {
    // contains filtered or unexported fields

func (ExtensionField) IsSet Uses

func (f ExtensionField) IsSet() bool

IsSet returns whether the extension field is set. This may be called concurrently.

func (*ExtensionField) Set Uses

func (f *ExtensionField) Set(t pref.ExtensionType, v pref.Value)

Set sets the type and value of the extension field. This must not be called concurrently.

func (*ExtensionField) SetLazy Uses

func (f *ExtensionField) SetLazy(t pref.ExtensionType, fn func() pref.Value)

SetLazy sets the type and a value that is to be lazily evaluated upon first use. This must not be called concurrently.

func (ExtensionField) Type Uses

func (f ExtensionField) Type() pref.ExtensionType

Type returns the type of the extension field. This may be called concurrently.

func (*ExtensionField) Value Uses

func (f *ExtensionField) Value() pref.Value

Value returns the value of the extension field. This may be called concurrently.

type ExtensionFields Uses

type ExtensionFields = map[int32]ExtensionField

type ExtensionInfo Uses

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 piface.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 interface{}

    // 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 Uses

func (xi *ExtensionInfo) InterfaceOf(v pref.Value) interface{}

func (*ExtensionInfo) IsValidInterface Uses

func (xi *ExtensionInfo) IsValidInterface(v interface{}) bool

func (*ExtensionInfo) IsValidValue Uses

func (xi *ExtensionInfo) IsValidValue(v pref.Value) bool

func (*ExtensionInfo) New Uses

func (xi *ExtensionInfo) New() pref.Value

func (*ExtensionInfo) TypeDescriptor Uses

func (xi *ExtensionInfo) TypeDescriptor() pref.ExtensionTypeDescriptor

func (*ExtensionInfo) ValueOf Uses

func (xi *ExtensionInfo) ValueOf(v interface{}) pref.Value

func (*ExtensionInfo) Zero Uses

func (xi *ExtensionInfo) Zero() pref.Value

type MessageInfo Uses

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 pref.MessageDescriptor

    // Exporter must be provided in a purego environment in order to provide
    // access to unexported fields.
    Exporter exporter

    // OneofWrappers is list of pointers to oneof wrapper struct types.
    OneofWrappers []interface{}
    // 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 Uses

func (mi *MessageInfo) Descriptor() protoreflect.MessageDescriptor

func (*MessageInfo) Enum Uses

func (mi *MessageInfo) Enum(i int) protoreflect.EnumType

func (*MessageInfo) Message Uses

func (mi *MessageInfo) Message(i int) protoreflect.MessageType

func (*MessageInfo) MessageOf Uses

func (mi *MessageInfo) MessageOf(m interface{}) pref.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 Uses

func (mi *MessageInfo) New() protoreflect.Message

func (*MessageInfo) Zero Uses

func (mi *MessageInfo) Zero() protoreflect.Message

type MessageState Uses

type MessageState struct {
    // 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 {
		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.


• 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 Pointer Uses

type Pointer unsafe.Pointer

Pointer is an opaque pointer type.

type SizeCache Uses

type SizeCache = int32

type UnknownFields Uses

type UnknownFields = unknownFieldsA // TODO: switch to unknownFieldsB

type ValidationStatus Uses

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.

    // ValidationValid indicates that unmarshaling the message will succeed.

func Validate Uses

func Validate(mt pref.MessageType, in piface.UnmarshalInput) (out piface.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 Uses

func (v ValidationStatus) String() string

type WeakFields Uses

type WeakFields = map[int32]protoreflect.ProtoMessage

Package impl imports 34 packages (graph) and is imported by 5 packages. Updated 2020-12-08. Refresh now. Tools for package owners.