Movatterモバイル変換


[0]ホーム

URL:


impl

package
v1.36.11Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 12, 2025 License:BSD-3-ClauseImports:36Imported by:0

Details

Repository

github.com/protocolbuffers/protobuf-go

Links

Documentation

Index

Constants

View Source
const UnsafeEnabled =true

Variables

This section is empty.

Functions

funcAberrantDeriveFullName

func AberrantDeriveFullName(treflect.Type)protoreflect.FullName

AberrantDeriveFullName derives a fully qualified protobuf name for the given Go typeThe 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.

funcEnableLazyUnmarshaladded inv1.36.0

func EnableLazyUnmarshal(enablebool)

EnableLazyUnmarshal enables lazy unmarshaling.

funcIsLazy

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

funcLazyEnabledadded inv1.36.0

func LazyEnabled()bool

LazyEnabled reports whether lazy unmarshalling is currently enabled.

funcLegacyLoadEnumDesc

func LegacyLoadEnumDesc(treflect.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.

funcLegacyLoadMessageDesc

func LegacyLoadMessageDesc(treflect.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.

funcUnmarshalFieldadded inv1.36.0

func UnmarshalField(m interface{}, numprotowire.Number)

UnmarshalField unmarshals a field in a message.

Types

typeConverter

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.

funcNewConverter

NewConverter matches a Go type with a protobuf field and returns a Converterthat converts between the two. Enums must be a named int32 kind thatimplements protoreflect.Enum, and messages must be pointer to a namedstruct type that implements protoreflect.ProtoMessage.

This matcher deliberately supports a wider range of Go types than whatprotoc-gen-go historically generated to be able to automatically wrap somev1 messages generated by other forks of protoc-gen-go.

typeEnumInfo

type EnumInfo struct {GoReflectTypereflect.Type// int32 kindDescprotoreflect.EnumDescriptor}

func (*EnumInfo)Descriptor

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

func (*EnumInfo)New

typeExport

type Export struct{}

Export is a zero-length named type that exists only to export a set offunctions that we do not want to appear in godoc.

func (Export)AtomicCheckPointerIsNiladded inv1.36.0

func (Export) AtomicCheckPointerIsNil(ptrany)bool

AtomicCheckPointerIsNil takes an interface (which is a pointer to apointer) and returns true if the pointed-to pointer is nil (using anatomic load). This function is inlineable and, on x86, just becomes asimple load and compare.

func (Export)AtomicInitializePointeradded inv1.36.0

func (Export) AtomicInitializePointer(ptrPointer, dstPointer)

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)AtomicLoadPointeradded inv1.36.0

func (Export) AtomicLoadPointer(ptrPointer, dstPointer)

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)AtomicSetPointeradded inv1.36.0

func (Export) AtomicSetPointer(dstPtr, valPtrany)

AtomicSetPointer takes two interfaces (first is a pointer to a pointer,second is a pointer) and atomically sets the second pointer into locationreferenced by first pointer. Unfortunately, atomicSetPointer() does not inline(even on x86), so this does not become a simple store on x86.

func (Export)ClearPresentadded inv1.36.0

func (Export) ClearPresent(part *uint32, numuint32)

ClearPresence removes a field from the presence set. part is apointer to the relevant element in the presence array and num isthe field number unaltered.

func (Export)CompressGZIP

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

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

EnumStringOf returns the enum value as a string, either as the name ifthe 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)LegacyEnumName

func (Export) LegacyEnumName(edprotoreflect.EnumDescriptor)string

LegacyEnumName returns the name of enums used in legacy code.

func (Export)LegacyMessageTypeOf

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)MessageFieldStringOfadded inv1.36.0

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) MessageStateOf(pPointer) *messageState

func (Export)MessageStringOf

func (Export) MessageStringOf(mprotoreflect.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)NewErroradded inv1.25.0

func (Export) NewError(fstring, x ...any)error

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

func (Export)Presentadded inv1.36.0

func (Export) Present(part *uint32, numuint32)bool

Present checks the presence set for a certain field number (zerobased, ordered by appearance in original proto file). part isa pointer to the correct element in the bitmask array, num is thefield 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)SetPresentadded inv1.36.0

func (Export) SetPresent(part *uint32, numuint32, sizeuint32)

SetPresent adds a field to the presence set. part is a pointer tothe relevant element in the array and num is the field numberunaltered. size is the number of fields in the protocolbuffer.

func (Export)SetPresentNonAtomicadded inv1.36.0

func (Export) SetPresentNonAtomic(part *uint32, numuint32, sizeuint32)

SetPresentNonAtomic is like SetPresent, but operates non-atomically.It is meant for use by builder methods, where the message is known notto be accessible yet by other goroutines.

func (Export)UnmarshalFieldadded inv1.36.0

func (Export) UnmarshalField(msgany, fieldNumint32)

func (Export)UnmarshalJSONEnum

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.

typeExtensionField

type ExtensionField struct {// contains filtered or unexported fields}

func (ExtensionField)IsSet

func (fExtensionField) IsSet()bool

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

func (*ExtensionField)Set

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

func (ExtensionField)Type

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

func (*ExtensionField)Value

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

typeExtensionFields

type ExtensionFields = map[int32]ExtensionField

typeExtensionInfo

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.ExtendedTypeprotoiface.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.ExtensionTypeany// Field is the field number of the extension.//// Deprecated: Use the Descriptor().Number method instead.Fieldint32// Name is the fully qualified name of extension.//// Deprecated: Use the Descriptor().FullName method instead.Namestring// Tag is the protobuf struct tag used in the v1 API.//// Deprecated: Do not use.Tagstring// Filename is the proto filename in which the extension is defined.//// Deprecated: Use Descriptor().ParentFile().Path() instead.Filenamestring// 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 theExtensionType interface.

func (*ExtensionInfo)InterfaceOf

func (xi *ExtensionInfo) InterfaceOf(vprotoreflect.Value)any

func (*ExtensionInfo)IsValidInterface

func (xi *ExtensionInfo) IsValidInterface(vany)bool

func (*ExtensionInfo)IsValidValue

func (xi *ExtensionInfo) IsValidValue(vprotoreflect.Value)bool

func (*ExtensionInfo)New

func (*ExtensionInfo)TypeDescriptor

func (*ExtensionInfo)ValueOf

func (xi *ExtensionInfo) ValueOf(vany)protoreflect.Value

func (*ExtensionInfo)Zero

typeMessageInfo

type MessageInfo struct {// GoReflectType is the underlying message Go type and must be populated.GoReflectTypereflect.Type// pointer to struct// Desc is the underlying message descriptor type and must be populated.Descprotoreflect.MessageDescriptor// Deprecated: Exporter will be removed the next time we bump// protoimpl.GenVersion. Seehttps://github.com/golang/protobuf/issues/1640Exporter 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 typethat represents a message. A given instance of MessageInfo is tied toexactly one Go type, which must be a pointer to a struct type.

The exported fields must be populated before any methods are calledand cannot be mutated after set.

func (*MessageInfo)Descriptor

func (*MessageInfo)Enumadded inv1.26.0

func (*MessageInfo)Messageadded inv1.26.0

func (*MessageInfo)MessageOf

func (mi *MessageInfo) MessageOf(many)protoreflect.Message

MessageOf returns a reflective view over a message. The input must be apointer 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 (*MessageInfo)Zero

typeMessageState

type MessageState struct {pragma.NoUnkeyedLiteralspragma.DoNotComparepragma.DoNotCopy// contains filtered or unexported fields}

MessageState is a data structure that is nested as the first field in aconcrete message. It provides a way to implement the ProtoReflect methodin an allocation-free way without needing to have a shadow Go type generatedfor every message type. This technique only works using unsafe.

Example generated code:

type M struct {state protoimpl.MessageStateField1 int32Field2 stringField3 *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 tothe message info associated with a given message instance.By unsafely converting a *M into a *MessageState, the MessageState objecthas 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 theMessageState 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.

typePointer

type Pointerunsafe.Pointer

Pointer is an opaque pointer type.

typeRaceDetectHookDataadded inv1.36.0

type RaceDetectHookData struct{}

There is no additional data as we're not running under race detector.

typeSizeCache

type SizeCache =int32

typeUnknownFields

type UnknownFields = unknownFieldsA// TODO: switch to unknownFieldsB

typeValidationStatus

type ValidationStatusint

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.ValidationUnknownValidationStatus =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)

funcValidate

Validate determines whether the contents of the buffer are a valid wire encodingof the message type.

This function is exposed for testing.

func (ValidationStatus)String

func (vValidationStatus) String()string

typeWeakFields

type WeakFields = map[int32]protoreflect.ProtoMessage

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp