Documentation
¶
Overview ¶
Package descriptor -- builder_enum.go contains the EnumDescriptorBuilder and EnumValueDescriptorBuilder for constructing immutable enum descriptors through chainable setter APIs.
Package descriptor -- builder_field.go contains the FieldDescriptorBuilder and OneofDescriptorBuilder for constructing immutable field and oneof descriptors through chainable setter APIs.
Package descriptor -- builder_file.go contains the FileDescriptorBuilder. String-interning helpers are in intern_gc.go and intern_tinygo.go.
Package descriptor -- builder_message.go contains the MessageDescriptorBuilder for constructing immutable message descriptors through a chainable setter API.
Package descriptor -- builder_service.go contains the ServiceDescriptorBuilder and MethodDescriptorBuilder for constructing immutable service and method descriptors through chainable setter APIs.
Package descriptor defines the protobuf descriptor hierarchy used to represent the schema of protocol buffer files, messages, fields, enums, services, and methods at runtime. Each descriptor type is an immutable struct constructed through a builder pattern and accessed through a focused read-only interface following the Interface Segregation Principle.
Index ¶
- type DescriptorAccessor
- type EditionFeatures
- type EnumDescriptor
- func (d *EnumDescriptor) FullName() FullName
- func (d *EnumDescriptor) IsClosed() bool
- func (d *EnumDescriptor) Name() string
- func (d *EnumDescriptor) Options() []byte
- func (d *EnumDescriptor) Parent() DescriptorAccessor
- func (d *EnumDescriptor) ReservedNames() []string
- func (d *EnumDescriptor) ReservedRanges() [][2]int32
- func (d *EnumDescriptor) ResolvedFeatures() EditionFeatures
- func (d *EnumDescriptor) SetTypedOptionsResolved(opts any)
- func (d *EnumDescriptor) TypedOptions() any
- func (d *EnumDescriptor) Values() EnumValueDescriptors
- type EnumDescriptorAccessor
- type EnumDescriptorBuilder
- func (b *EnumDescriptorBuilder) AddValue(v *EnumValueDescriptor) *EnumDescriptorBuilder
- func (b *EnumDescriptorBuilder) Build() (*EnumDescriptor, error)
- func (b *EnumDescriptorBuilder) SetFullName(fn FullName) *EnumDescriptorBuilder
- func (b *EnumDescriptorBuilder) SetIsClosed(v bool) *EnumDescriptorBuilder
- func (b *EnumDescriptorBuilder) SetName(name string) *EnumDescriptorBuilder
- func (b *EnumDescriptorBuilder) SetOptions(opts []byte) *EnumDescriptorBuilder
- func (b *EnumDescriptorBuilder) SetParent(p DescriptorAccessor) *EnumDescriptorBuilder
- func (b *EnumDescriptorBuilder) SetReservedNames(names []string) *EnumDescriptorBuilder
- func (b *EnumDescriptorBuilder) SetReservedRanges(ranges [][2]int32) *EnumDescriptorBuilder
- func (b *EnumDescriptorBuilder) SetResolvedFeatures(features EditionFeatures) *EnumDescriptorBuilder
- func (b *EnumDescriptorBuilder) SetTypedOptions(opts any) *EnumDescriptorBuilder
- type EnumDescriptors
- type EnumType
- type EnumValueDescriptor
- type EnumValueDescriptorAccessor
- type EnumValueDescriptorBuilder
- func (b *EnumValueDescriptorBuilder) Build() (*EnumValueDescriptor, error)
- func (b *EnumValueDescriptorBuilder) SetFullName(fn FullName) *EnumValueDescriptorBuilder
- func (b *EnumValueDescriptorBuilder) SetJSONName(name string) *EnumValueDescriptorBuilder
- func (b *EnumValueDescriptorBuilder) SetName(name string) *EnumValueDescriptorBuilder
- func (b *EnumValueDescriptorBuilder) SetNumber(num int32) *EnumValueDescriptorBuilder
- func (b *EnumValueDescriptorBuilder) SetOptions(opts []byte) *EnumValueDescriptorBuilder
- func (b *EnumValueDescriptorBuilder) SetParent(p EnumDescriptorAccessor) *EnumValueDescriptorBuilder
- type EnumValueDescriptors
- type FieldCardinality
- type FieldDescriptor
- func (d *FieldDescriptor) Cardinality() FieldCardinality
- func (d *FieldDescriptor) ContainingMessage() MessageDescriptorAccessor
- func (d *FieldDescriptor) ContainingOneof() OneofDescriptorAccessor
- func (d *FieldDescriptor) DefaultValue() string
- func (d *FieldDescriptor) EnumType() EnumDescriptorAccessor
- func (d *FieldDescriptor) FullName() FullName
- func (d *FieldDescriptor) HasJSONName() bool
- func (d *FieldDescriptor) IsExtension() bool
- func (d *FieldDescriptor) IsList() bool
- func (d *FieldDescriptor) IsMap() bool
- func (d *FieldDescriptor) IsPacked() bool
- func (d *FieldDescriptor) JSONName() string
- func (d *FieldDescriptor) Kind() scalar.Kind
- func (d *FieldDescriptor) MessageType() MessageDescriptorAccessor
- func (d *FieldDescriptor) Name() string
- func (d *FieldDescriptor) Number() uint32
- func (d *FieldDescriptor) Options() []byte
- func (d *FieldDescriptor) ResolvedFeatures() EditionFeatures
- func (d *FieldDescriptor) SetTypedOptionsResolved(opts any)
- func (d *FieldDescriptor) TypedOptions() any
- type FieldDescriptorAccessor
- type FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) Build() (*FieldDescriptor, error)
- func (b *FieldDescriptorBuilder) SetCardinality(c FieldCardinality) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetContainingMessage(msg MessageDescriptorAccessor) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetContainingOneof(o OneofDescriptorAccessor) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetDefaultValue(val string) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetEnumType(e EnumDescriptorAccessor) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetFullName(fn FullName) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetHasJSONName(v bool) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetIsExtension(v bool) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetIsList(v bool) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetIsMap(v bool) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetIsPacked(v bool) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetJSONName(name string) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetKind(k scalar.Kind) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetMessageType(msg MessageDescriptorAccessor) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetName(name string) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetNumber(num uint32) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetOptions(opts []byte) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetResolvedFeatures(features EditionFeatures) *FieldDescriptorBuilder
- func (b *FieldDescriptorBuilder) SetTypedOptions(opts any) *FieldDescriptorBuilder
- type FieldDescriptors
- type FieldEncoder
- type FieldIdentifier
- type FieldPresence
- type FieldTyper
- type FileContents
- type FileDescriptor
- func (d *FileDescriptor) Dependencies() FileDescriptors
- func (d *FileDescriptor) Edition() string
- func (d *FileDescriptor) Enums() EnumDescriptors
- func (d *FileDescriptor) Extensions() FieldDescriptors
- func (d *FileDescriptor) Features() EditionFeatures
- func (d *FileDescriptor) FullName() FullName
- func (d *FileDescriptor) Messages() MessageDescriptors
- func (d *FileDescriptor) Name() string
- func (d *FileDescriptor) Options() []byte
- func (d *FileDescriptor) Package() string
- func (d *FileDescriptor) Path() string
- func (d *FileDescriptor) Services() ServiceDescriptors
- func (d *FileDescriptor) SetTypedOptionsResolved(opts any)
- func (d *FileDescriptor) SourceCodeInfo() *SourceCodeInfo
- func (d *FileDescriptor) Syntax() Syntax
- func (d *FileDescriptor) TypedOptions() any
- type FileDescriptorAccessor
- type FileDescriptorBuilder
- func (b *FileDescriptorBuilder) AddDependency(dep *FileDescriptor) *FileDescriptorBuilder
- func (b *FileDescriptorBuilder) AddEnum(e *EnumDescriptor) *FileDescriptorBuilder
- func (b *FileDescriptorBuilder) AddExtension(ext *FieldDescriptor) *FileDescriptorBuilder
- func (b *FileDescriptorBuilder) AddMessage(msg *MessageDescriptor) *FileDescriptorBuilder
- func (b *FileDescriptorBuilder) AddService(svc *ServiceDescriptor) *FileDescriptorBuilder
- func (b *FileDescriptorBuilder) Build() (*FileDescriptor, error)
- func (b *FileDescriptorBuilder) SetEdition(edition string) *FileDescriptorBuilder
- func (b *FileDescriptorBuilder) SetFeatures(features EditionFeatures) *FileDescriptorBuilder
- func (b *FileDescriptorBuilder) SetName(name string) *FileDescriptorBuilder
- func (b *FileDescriptorBuilder) SetOptions(opts []byte) *FileDescriptorBuilder
- func (b *FileDescriptorBuilder) SetPackage(pkg string) *FileDescriptorBuilder
- func (b *FileDescriptorBuilder) SetSourceCodeInfo(sci *SourceCodeInfo) *FileDescriptorBuilder
- func (b *FileDescriptorBuilder) SetSyntax(s Syntax) *FileDescriptorBuilder
- func (b *FileDescriptorBuilder) SetTypedOptions(opts any) *FileDescriptorBuilder
- type FileDescriptors
- type FileIdentity
- type FileOptionsAccessor
- type FullName
- type GoAPIMode
- type JsonFormat
- type Location
- type MessageDescriptor
- func (d *MessageDescriptor) ExtensionRanges() [][2]uint32
- func (d *MessageDescriptor) Fields() FieldDescriptors
- func (d *MessageDescriptor) FullName() FullName
- func (d *MessageDescriptor) HasFieldNumberInExtensionRange(number uint32) bool
- func (d *MessageDescriptor) IsMapEntry() bool
- func (d *MessageDescriptor) Name() string
- func (d *MessageDescriptor) NestedEnums() EnumDescriptors
- func (d *MessageDescriptor) NestedMessages() MessageDescriptors
- func (d *MessageDescriptor) Oneofs() OneofDescriptors
- func (d *MessageDescriptor) Options() []byte
- func (d *MessageDescriptor) Parent() DescriptorAccessor
- func (d *MessageDescriptor) ReservedNames() []string
- func (d *MessageDescriptor) ReservedRanges() [][2]uint32
- func (d *MessageDescriptor) ResolvedFeatures() EditionFeatures
- func (d *MessageDescriptor) SetTypedOptionsResolved(opts any)
- func (d *MessageDescriptor) TypedOptions() any
- type MessageDescriptorAccessor
- type MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) AddField(fd *FieldDescriptor) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) AddNestedEnum(ed *EnumDescriptor) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) AddNestedMessage(md *MessageDescriptor) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) AddOneof(od *OneofDescriptor) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) Build() (*MessageDescriptor, error)
- func (b *MessageDescriptorBuilder) SetExtensionRanges(ranges [][2]uint32) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) SetFullName(fn FullName) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) SetIsMapEntry(v bool) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) SetName(name string) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) SetOptions(opts []byte) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) SetParent(p DescriptorAccessor) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) SetReservedNames(names []string) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) SetReservedRanges(ranges [][2]uint32) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) SetResolvedFeatures(features EditionFeatures) *MessageDescriptorBuilder
- func (b *MessageDescriptorBuilder) SetTypedOptions(opts any) *MessageDescriptorBuilder
- type MessageDescriptors
- type MessageEncoding
- type MethodDescriptor
- func (d *MethodDescriptor) FullName() FullName
- func (d *MethodDescriptor) InputType() MessageDescriptorAccessor
- func (d *MethodDescriptor) IsClientStreaming() bool
- func (d *MethodDescriptor) IsServerStreaming() bool
- func (d *MethodDescriptor) Name() string
- func (d *MethodDescriptor) Options() []byte
- func (d *MethodDescriptor) OutputType() MessageDescriptorAccessor
- func (d *MethodDescriptor) Parent() ServiceDescriptorAccessor
- func (d *MethodDescriptor) SetTypedOptionsResolved(opts any)
- func (d *MethodDescriptor) TypedOptions() any
- type MethodDescriptorAccessor
- type MethodDescriptorBuilder
- func (b *MethodDescriptorBuilder) Build() (*MethodDescriptor, error)
- func (b *MethodDescriptorBuilder) SetClientStreaming(v bool) *MethodDescriptorBuilder
- func (b *MethodDescriptorBuilder) SetFullName(fn FullName) *MethodDescriptorBuilder
- func (b *MethodDescriptorBuilder) SetInputType(msg MessageDescriptorAccessor) *MethodDescriptorBuilder
- func (b *MethodDescriptorBuilder) SetName(name string) *MethodDescriptorBuilder
- func (b *MethodDescriptorBuilder) SetOptions(opts []byte) *MethodDescriptorBuilder
- func (b *MethodDescriptorBuilder) SetOutputType(msg MessageDescriptorAccessor) *MethodDescriptorBuilder
- func (b *MethodDescriptorBuilder) SetParent(p ServiceDescriptorAccessor) *MethodDescriptorBuilder
- func (b *MethodDescriptorBuilder) SetServerStreaming(v bool) *MethodDescriptorBuilder
- func (b *MethodDescriptorBuilder) SetTypedOptions(opts any) *MethodDescriptorBuilder
- type MethodDescriptors
- type NamingStyle
- type OneofDescriptor
- func (d *OneofDescriptor) Fields() FieldDescriptors
- func (d *OneofDescriptor) FullName() FullName
- func (d *OneofDescriptor) IsSynthetic() bool
- func (d *OneofDescriptor) Name() string
- func (d *OneofDescriptor) Options() []byte
- func (d *OneofDescriptor) Parent() MessageDescriptorAccessor
- func (d *OneofDescriptor) PopulateFields(s []*FieldDescriptor)
- type OneofDescriptorAccessor
- type OneofDescriptorBuilder
- func (b *OneofDescriptorBuilder) AddField(fd *FieldDescriptor) *OneofDescriptorBuilder
- func (b *OneofDescriptorBuilder) Build() (*OneofDescriptor, error)
- func (b *OneofDescriptorBuilder) SetFullName(fn FullName) *OneofDescriptorBuilder
- func (b *OneofDescriptorBuilder) SetIsSynthetic(v bool) *OneofDescriptorBuilder
- func (b *OneofDescriptorBuilder) SetName(name string) *OneofDescriptorBuilder
- func (b *OneofDescriptorBuilder) SetOptions(opts []byte) *OneofDescriptorBuilder
- func (b *OneofDescriptorBuilder) SetParent(p MessageDescriptorAccessor) *OneofDescriptorBuilder
- type OneofDescriptors
- type RepeatedFieldEncoding
- type ServiceDescriptor
- func (d *ServiceDescriptor) FullName() FullName
- func (d *ServiceDescriptor) Methods() MethodDescriptors
- func (d *ServiceDescriptor) Name() string
- func (d *ServiceDescriptor) Options() []byte
- func (d *ServiceDescriptor) Parent() FileDescriptorAccessor
- func (d *ServiceDescriptor) SetTypedOptionsResolved(opts any)
- func (d *ServiceDescriptor) TypedOptions() any
- type ServiceDescriptorAccessor
- type ServiceDescriptorBuilder
- func (b *ServiceDescriptorBuilder) AddMethod(m *MethodDescriptor) *ServiceDescriptorBuilder
- func (b *ServiceDescriptorBuilder) Build() (*ServiceDescriptor, error)
- func (b *ServiceDescriptorBuilder) SetFullName(fn FullName) *ServiceDescriptorBuilder
- func (b *ServiceDescriptorBuilder) SetName(name string) *ServiceDescriptorBuilder
- func (b *ServiceDescriptorBuilder) SetOptions(opts []byte) *ServiceDescriptorBuilder
- func (b *ServiceDescriptorBuilder) SetParent(p FileDescriptorAccessor) *ServiceDescriptorBuilder
- func (b *ServiceDescriptorBuilder) SetTypedOptions(opts any) *ServiceDescriptorBuilder
- type ServiceDescriptors
- type SourceCodeInfo
- type StripEnumPrefix
- type SymbolVisibility
- type Syntax
- type Utf8Validation
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DescriptorAccessor ¶
type DescriptorAccessor interface {
// Name returns the unqualified short name of the descriptor.
Name() string
// FullName returns the fully qualified dot-separated name of the
// descriptor.
FullName() FullName
}
DescriptorAccessor is the base interface embedded by all specific descriptor accessor interfaces. It provides the common identity contract: an unqualified name and a fully qualified name.
type EditionFeatures ¶
type EditionFeatures struct {
FieldPresence FieldPresence
EnumType EnumType
RepeatedFieldEncoding RepeatedFieldEncoding
MessageEncoding MessageEncoding
Utf8Validation Utf8Validation
JsonFormat JsonFormat
StripEnumPrefix StripEnumPrefix
DefaultSymbolVisibility SymbolVisibility
EnforceNamingStyle NamingStyle
GoAPIMode GoAPIMode
}
EditionFeatures holds the resolved feature set for a descriptor element under editions semantics. Each field corresponds to one of the standard protobuf edition features or a Go-specific edition extension feature.
func DefaultFeaturesForEdition ¶
func DefaultFeaturesForEdition(edition string) (EditionFeatures, error)
DefaultFeaturesForEdition returns the default EditionFeatures for the given edition string. It returns an error for unrecognized editions.
func ResolveFeatures ¶
func ResolveFeatures(fileFeatures EditionFeatures, msgOverrides, fieldOverrides *EditionFeatures) EditionFeatures
ResolveFeatures computes the effective feature set by starting with fileFeatures (the file-level defaults from the edition defaults table) and applying any non-zero overrides from msgOverrides and then fieldOverrides. A nil pointer means no overrides at that level; a zero-value field within an override struct means "inherit from parent".
type EnumDescriptor ¶
type EnumDescriptor struct {
// contains filtered or unexported fields
}
EnumDescriptor represents an immutable protobuf enum descriptor. It holds metadata about an enum type, including its values, reserved ranges and names, and whether it is a closed enum. Access its properties through the EnumDescriptorAccessor interface.
func (*EnumDescriptor) FullName ¶
func (d *EnumDescriptor) FullName() FullName
FullName returns the fully qualified dot-separated name of the enum.
func (*EnumDescriptor) IsClosed ¶
func (d *EnumDescriptor) IsClosed() bool
IsClosed reports whether this is a closed enum. Proto2 enums are closed, meaning that unrecognized values are treated as unknown fields.
func (*EnumDescriptor) Name ¶
func (d *EnumDescriptor) Name() string
Name returns the unqualified short name of the enum.
func (*EnumDescriptor) Options ¶
func (d *EnumDescriptor) Options() []byte
Options returns a copy of the serialized enum options as an opaque byte slice. Returns nil if no options are set.
func (*EnumDescriptor) Parent ¶
func (d *EnumDescriptor) Parent() DescriptorAccessor
Parent returns the parent descriptor, which is either a file or a message for nested enum types.
func (*EnumDescriptor) ReservedNames ¶
func (d *EnumDescriptor) ReservedNames() []string
ReservedNames returns a copy of the reserved enum value names. Mutating the returned slice does not affect the descriptor.
func (*EnumDescriptor) ReservedRanges ¶
func (d *EnumDescriptor) ReservedRanges() [][2]int32
ReservedRanges returns a copy of the reserved enum value number range pairs. Mutating the returned slice does not affect the descriptor.
func (*EnumDescriptor) ResolvedFeatures ¶
func (d *EnumDescriptor) ResolvedFeatures() EditionFeatures
ResolvedFeatures returns the resolved EditionFeatures for this enum, incorporating file-level defaults and message/enum-level overrides. For non-editions enums, this returns a zero-value EditionFeatures.
func (*EnumDescriptor) SetTypedOptionsResolved ¶
func (d *EnumDescriptor) SetTypedOptionsResolved(opts any)
SetTypedOptionsResolved sets the typed options on the enum descriptor after it has been built. This is used by the compilation pipeline to populate typed options from raw option bytes during resolution.
func (*EnumDescriptor) TypedOptions ¶
func (d *EnumDescriptor) TypedOptions() any
TypedOptions returns the parsed enum options as a typed message, or nil if no typed options have been set.
func (*EnumDescriptor) Values ¶
func (d *EnumDescriptor) Values() EnumValueDescriptors
Values returns the enum value descriptors defined in this enum.
type EnumDescriptorAccessor ¶
type EnumDescriptorAccessor interface {
DescriptorAccessor
// Parent returns the parent descriptor, which is either a file or a
// message for nested enum types.
Parent() DescriptorAccessor
// Values returns the enum value descriptors defined in this enum.
Values() EnumValueDescriptors
// ReservedRanges returns the reserved enum value number range pairs.
ReservedRanges() [][2]int32
// ReservedNames returns the reserved enum value names.
ReservedNames() []string
// IsClosed reports whether this is a closed enum (proto2 enums are
// closed).
IsClosed() bool
// Options returns the serialized enum options as an opaque byte slice.
Options() []byte
// TypedOptions returns the parsed enum options as a typed message, or
// nil if no typed options have been set. The returned value is typically
// a *dynamicpb.Message representing google.protobuf.EnumOptions.
// Callers should type-assert to the expected concrete type.
TypedOptions() any
// ResolvedFeatures returns the resolved EditionFeatures for this
// enum, incorporating file-level defaults and message/enum-level
// overrides. For non-editions enums, this returns a zero-value
// EditionFeatures.
ResolvedFeatures() EditionFeatures
}
EnumDescriptorAccessor is the read-only interface for accessing enum descriptor properties. It embeds DescriptorAccessor for the common identity contract and adds methods specific to protobuf enum descriptors.
ISP note: EnumDescriptorAccessor has 9 methods (including embedded DescriptorAccessor). The methods form a single cohesive "enum schema" concern with no clear independent sub-grouping used by consumers. All consumers (codegen, dynamicpb, jsoncodec) use the majority of methods. This is documented as an accepted exception to the 5-method guideline.
type EnumDescriptorBuilder ¶
type EnumDescriptorBuilder struct {
// contains filtered or unexported fields
}
EnumDescriptorBuilder constructs an immutable EnumDescriptor through a chainable setter API. Call Build to validate and produce the descriptor. Builders are reusable: calling Build multiple times produces independent descriptors.
func (*EnumDescriptorBuilder) AddValue ¶
func (b *EnumDescriptorBuilder) AddValue(v *EnumValueDescriptor) *EnumDescriptorBuilder
AddValue appends an enum value descriptor to the enum.
func (*EnumDescriptorBuilder) Build ¶
func (b *EnumDescriptorBuilder) Build() (*EnumDescriptor, error)
Build validates the builder state and returns an immutable EnumDescriptor. It returns an error if the name or full name is empty.
func (*EnumDescriptorBuilder) SetFullName ¶
func (b *EnumDescriptorBuilder) SetFullName(fn FullName) *EnumDescriptorBuilder
SetFullName sets the fully qualified dot-separated name of the enum.
func (*EnumDescriptorBuilder) SetIsClosed ¶
func (b *EnumDescriptorBuilder) SetIsClosed(v bool) *EnumDescriptorBuilder
SetIsClosed sets whether this is a closed enum.
func (*EnumDescriptorBuilder) SetName ¶
func (b *EnumDescriptorBuilder) SetName(name string) *EnumDescriptorBuilder
SetName sets the unqualified short name of the enum.
func (*EnumDescriptorBuilder) SetOptions ¶
func (b *EnumDescriptorBuilder) SetOptions(opts []byte) *EnumDescriptorBuilder
SetOptions sets the serialized enum options as an opaque byte slice.
func (*EnumDescriptorBuilder) SetParent ¶
func (b *EnumDescriptorBuilder) SetParent(p DescriptorAccessor) *EnumDescriptorBuilder
SetParent sets the parent descriptor (file or enclosing message).
func (*EnumDescriptorBuilder) SetReservedNames ¶
func (b *EnumDescriptorBuilder) SetReservedNames(names []string) *EnumDescriptorBuilder
SetReservedNames sets the reserved enum value names.
func (*EnumDescriptorBuilder) SetReservedRanges ¶
func (b *EnumDescriptorBuilder) SetReservedRanges(ranges [][2]int32) *EnumDescriptorBuilder
SetReservedRanges sets the reserved enum value number range pairs.
func (*EnumDescriptorBuilder) SetResolvedFeatures ¶
func (b *EnumDescriptorBuilder) SetResolvedFeatures(features EditionFeatures) *EnumDescriptorBuilder
SetResolvedFeatures sets the resolved EditionFeatures for this enum.
func (*EnumDescriptorBuilder) SetTypedOptions ¶
func (b *EnumDescriptorBuilder) SetTypedOptions(opts any) *EnumDescriptorBuilder
SetTypedOptions sets the parsed enum options as a typed message. The value is typically a *dynamicpb.Message representing google.protobuf.EnumOptions.
type EnumDescriptors ¶
type EnumDescriptors struct {
// contains filtered or unexported fields
}
EnumDescriptors is a list of enum descriptor pointers. It wraps an unexported slice to prevent caller mutation of the internal state.
func (EnumDescriptors) ByName ¶
func (l EnumDescriptors) ByName(name string) *EnumDescriptor
ByName returns the enum descriptor with the given unqualified name, or nil if no such descriptor is found. It performs a linear scan over the list.
func (EnumDescriptors) Get ¶
func (l EnumDescriptors) Get(i int) *EnumDescriptor
Get returns the enum descriptor at the given index. It panics if the index is out of range, matching Go slice semantics.
func (EnumDescriptors) Len ¶
func (l EnumDescriptors) Len() int
Len returns the number of enum descriptors in the list.
type EnumType ¶
type EnumType int8
EnumType controls whether an enum is open or closed under editions semantics.
EnumType constants matching the official protobuf edition feature values.
type EnumValueDescriptor ¶
type EnumValueDescriptor struct {
// contains filtered or unexported fields
}
EnumValueDescriptor represents an immutable protobuf enum value descriptor. It holds the name, number, parent enum, and serialized options for a single enum value. Access its properties through the EnumValueDescriptorAccessor interface.
func (*EnumValueDescriptor) FullName ¶
func (d *EnumValueDescriptor) FullName() FullName
FullName returns the fully qualified dot-separated name of this enum value.
func (*EnumValueDescriptor) JSONName ¶
func (d *EnumValueDescriptor) JSONName() string
JSONName returns the custom JSON name for this enum value. If no custom json_name was set, it returns an empty string, indicating that the proto name should be used instead.
func (*EnumValueDescriptor) Name ¶
func (d *EnumValueDescriptor) Name() string
Name returns the unqualified short name of this enum value.
func (*EnumValueDescriptor) Number ¶
func (d *EnumValueDescriptor) Number() int32
Number returns the integer value of this enum value.
func (*EnumValueDescriptor) Options ¶
func (d *EnumValueDescriptor) Options() []byte
Options returns the serialized enum value options as an opaque byte slice. The returned slice is a copy; modifying it does not affect the descriptor.
func (*EnumValueDescriptor) Parent ¶
func (d *EnumValueDescriptor) Parent() EnumDescriptorAccessor
Parent returns the enum descriptor that contains this value.
type EnumValueDescriptorAccessor ¶
type EnumValueDescriptorAccessor interface {
DescriptorAccessor
// Number returns the integer value of this enum value.
Number() int32
// Parent returns the enum descriptor that contains this value.
Parent() EnumDescriptorAccessor
// JSONName returns the custom JSON name for this enum value. If no
// custom json_name was set, it returns an empty string, indicating
// that the proto name should be used instead.
JSONName() string
// Options returns the serialized enum value options as an opaque byte
// slice.
Options() []byte
}
EnumValueDescriptorAccessor is the read-only interface for accessing enum value descriptor properties. It embeds DescriptorAccessor for the common identity contract and adds methods specific to protobuf enum value descriptors.
ISP note: EnumValueDescriptorAccessor has 6 methods (including embedded DescriptorAccessor). The methods form a single cohesive "enum value identity" concern. All consumers (codegen, dynamicpb, jsoncodec) use the full set when processing enum value declarations. Splitting would create fragments with no independent consumers. This is documented as an accepted exception to the 5-method guideline.
type EnumValueDescriptorBuilder ¶
type EnumValueDescriptorBuilder struct {
// contains filtered or unexported fields
}
EnumValueDescriptorBuilder constructs an immutable EnumValueDescriptor through a chainable setter API. Call Build to validate and produce the descriptor. Builders are reusable: calling Build multiple times produces independent descriptors.
func (*EnumValueDescriptorBuilder) Build ¶
func (b *EnumValueDescriptorBuilder) Build() (*EnumValueDescriptor, error)
Build validates the builder state and returns an immutable EnumValueDescriptor. It returns an error if the name or full name is empty. The number is not validated because any int32 is valid per protobuf spec.
func (*EnumValueDescriptorBuilder) SetFullName ¶
func (b *EnumValueDescriptorBuilder) SetFullName(fn FullName) *EnumValueDescriptorBuilder
SetFullName sets the fully qualified dot-separated name of the enum value.
func (*EnumValueDescriptorBuilder) SetJSONName ¶
func (b *EnumValueDescriptorBuilder) SetJSONName(name string) *EnumValueDescriptorBuilder
SetJSONName sets the custom JSON name for this enum value. When set, the JSON codec uses this name instead of the proto name during marshaling.
func (*EnumValueDescriptorBuilder) SetName ¶
func (b *EnumValueDescriptorBuilder) SetName(name string) *EnumValueDescriptorBuilder
SetName sets the unqualified short name of the enum value.
func (*EnumValueDescriptorBuilder) SetNumber ¶
func (b *EnumValueDescriptorBuilder) SetNumber(num int32) *EnumValueDescriptorBuilder
SetNumber sets the integer value of this enum value. Any int32 value is valid per protobuf spec, including negative numbers.
func (*EnumValueDescriptorBuilder) SetOptions ¶
func (b *EnumValueDescriptorBuilder) SetOptions(opts []byte) *EnumValueDescriptorBuilder
SetOptions sets the serialized enum value options as an opaque byte slice.
func (*EnumValueDescriptorBuilder) SetParent ¶
func (b *EnumValueDescriptorBuilder) SetParent(p EnumDescriptorAccessor) *EnumValueDescriptorBuilder
SetParent sets the enum descriptor that contains this value.
type EnumValueDescriptors ¶
type EnumValueDescriptors struct {
// contains filtered or unexported fields
}
EnumValueDescriptors is a list of enum value descriptor pointers. It wraps an unexported slice to prevent caller mutation of the internal state.
func (EnumValueDescriptors) ByName ¶
func (l EnumValueDescriptors) ByName(name string) *EnumValueDescriptor
ByName returns the enum value descriptor with the given unqualified name, or nil if no such descriptor is found. It performs a linear scan over the list.
func (EnumValueDescriptors) ByNumber ¶
func (l EnumValueDescriptors) ByNumber(num int32) *EnumValueDescriptor
ByNumber returns the enum value descriptor with the given number, or nil if no such descriptor is found. It performs a linear scan over the list. The number parameter is int32 because protobuf enum values may be negative.
func (EnumValueDescriptors) Get ¶
func (l EnumValueDescriptors) Get(i int) *EnumValueDescriptor
Get returns the enum value descriptor at the given index. It panics if the index is out of range, matching Go slice semantics.
func (EnumValueDescriptors) Len ¶
func (l EnumValueDescriptors) Len() int
Len returns the number of enum value descriptors in the list.
type FieldCardinality ¶
type FieldCardinality int8
FieldCardinality represents the cardinality of a protobuf field. It is a named type over int8 to provide type safety. The zero value is intentionally invalid.
const ( // Optional identifies an optional field. Optional FieldCardinality = 1 // Required identifies a required field (proto2 only). Required FieldCardinality = 2 // Repeated identifies a repeated field. Repeated FieldCardinality = 3 )
FieldCardinality constants for the three protobuf field cardinalities. Values start at 1 so that the zero value of FieldCardinality is invalid by design.
func (FieldCardinality) String ¶
func (c FieldCardinality) String() string
String returns the lowercase protobuf name of the field cardinality. For the three valid values (1-3) it returns names such as "optional" and "repeated". For out-of-range values it returns a formatted string like "FieldCardinality(4)".
func (FieldCardinality) Valid ¶
func (c FieldCardinality) Valid() bool
Valid reports whether c is one of the three defined protobuf field cardinalities (1 through 3 inclusive).
type FieldDescriptor ¶
type FieldDescriptor struct {
// contains filtered or unexported fields
}
FieldDescriptor represents an immutable protobuf field descriptor. It holds the name, number, kind, cardinality, and all associated metadata for a single field within a message. Access its properties through the FieldDescriptorAccessor interface.
fieldalignment: fields ordered by alignment size with qualified types last
func (*FieldDescriptor) Cardinality ¶
func (d *FieldDescriptor) Cardinality() FieldCardinality
Cardinality returns the field cardinality (optional, required, or repeated).
func (*FieldDescriptor) ContainingMessage ¶
func (d *FieldDescriptor) ContainingMessage() MessageDescriptorAccessor
ContainingMessage returns the message descriptor that contains this field.
func (*FieldDescriptor) ContainingOneof ¶
func (d *FieldDescriptor) ContainingOneof() OneofDescriptorAccessor
ContainingOneof returns the oneof descriptor that contains this field, or nil if the field is not part of a oneof.
func (*FieldDescriptor) DefaultValue ¶
func (d *FieldDescriptor) DefaultValue() string
DefaultValue returns the textual representation of the field's default value.
func (*FieldDescriptor) EnumType ¶
func (d *FieldDescriptor) EnumType() EnumDescriptorAccessor
EnumType returns the enum descriptor for enum-typed fields, or nil if the field is not an enum type.
func (*FieldDescriptor) FullName ¶
func (d *FieldDescriptor) FullName() FullName
FullName returns the fully qualified dot-separated name of this field.
func (*FieldDescriptor) HasJSONName ¶
func (d *FieldDescriptor) HasJSONName() bool
HasJSONName reports whether the JSON name was explicitly set in the .proto file rather than auto-generated.
func (*FieldDescriptor) IsExtension ¶
func (d *FieldDescriptor) IsExtension() bool
IsExtension reports whether this field is an extension field.
func (*FieldDescriptor) IsList ¶
func (d *FieldDescriptor) IsList() bool
IsList reports whether the field is a list (repeated non-map) field.
func (*FieldDescriptor) IsMap ¶
func (d *FieldDescriptor) IsMap() bool
IsMap reports whether the field is a map field.
func (*FieldDescriptor) IsPacked ¶
func (d *FieldDescriptor) IsPacked() bool
IsPacked reports whether the field uses packed encoding.
func (*FieldDescriptor) JSONName ¶
func (d *FieldDescriptor) JSONName() string
JSONName returns the JSON field name.
func (*FieldDescriptor) Kind ¶
func (d *FieldDescriptor) Kind() scalar.Kind
Kind returns the scalar kind of the field.
func (*FieldDescriptor) MessageType ¶
func (d *FieldDescriptor) MessageType() MessageDescriptorAccessor
MessageType returns the message descriptor for message-typed fields, or nil if the field is not a message type.
func (*FieldDescriptor) Name ¶
func (d *FieldDescriptor) Name() string
Name returns the unqualified short name of this field.
func (*FieldDescriptor) Number ¶
func (d *FieldDescriptor) Number() uint32
Number returns the protobuf field number.
func (*FieldDescriptor) Options ¶
func (d *FieldDescriptor) Options() []byte
Options returns the serialized field options as an opaque byte slice. The returned slice is a copy; modifying it does not affect the descriptor.
func (*FieldDescriptor) ResolvedFeatures ¶
func (d *FieldDescriptor) ResolvedFeatures() EditionFeatures
ResolvedFeatures returns the resolved EditionFeatures for this field, incorporating file-level defaults, message-level overrides, and field-level overrides. For non-editions fields, this returns a zero-value EditionFeatures.
func (*FieldDescriptor) SetTypedOptionsResolved ¶
func (d *FieldDescriptor) SetTypedOptionsResolved(opts any)
SetTypedOptionsResolved sets the typed options on the field descriptor after it has been built. This is used by the compilation pipeline to populate typed options from raw option bytes during resolution.
func (*FieldDescriptor) TypedOptions ¶
func (d *FieldDescriptor) TypedOptions() any
TypedOptions returns the parsed field options as a typed message, or nil if no typed options have been set.
type FieldDescriptorAccessor ¶
type FieldDescriptorAccessor interface {
FieldIdentifier
FieldTyper
FieldEncoder
// ContainingMessage returns the message descriptor that contains this
// field.
ContainingMessage() MessageDescriptorAccessor
// ContainingOneof returns the oneof descriptor that contains this
// field, or nil if the field is not part of a oneof.
ContainingOneof() OneofDescriptorAccessor
// Options returns the serialized field options as an opaque byte slice.
Options() []byte
// TypedOptions returns the parsed field options as a typed message, or
// nil if no typed options have been set. The returned value is typically
// a *dynamicpb.Message representing google.protobuf.FieldOptions.
// Callers should type-assert to the expected concrete type.
TypedOptions() any
// ResolvedFeatures returns the resolved EditionFeatures for this
// field, incorporating file-level defaults, message-level overrides,
// and field-level overrides. For non-editions fields, this returns a
// zero-value EditionFeatures.
ResolvedFeatures() EditionFeatures
}
FieldDescriptorAccessor is the read-only interface for accessing field descriptor properties. It composes the narrower FieldIdentifier, FieldTyper, and FieldEncoder sub-interfaces along with DescriptorAccessor, following the Interface Segregation Principle. Functions should accept the narrowest sub-interface their logic requires rather than the full accessor.
The full accessor also includes relationship accessors (ContainingMessage, ContainingOneof) and options/features that do not belong to any single narrow sub-interface.
type FieldDescriptorBuilder ¶
type FieldDescriptorBuilder struct {
// contains filtered or unexported fields
}
FieldDescriptorBuilder constructs an immutable FieldDescriptor through a chainable setter API. Call Build to validate and produce the descriptor. Builders are reusable: calling Build multiple times produces independent descriptors.
fieldalignment: fields ordered to mirror FieldDescriptor for readability
func (*FieldDescriptorBuilder) Build ¶
func (b *FieldDescriptorBuilder) Build() (*FieldDescriptor, error)
Build validates the builder state and returns an immutable FieldDescriptor. It returns an error if the name or full name is empty, the number is zero, the kind is invalid, or the cardinality is invalid.
func (*FieldDescriptorBuilder) SetCardinality ¶
func (b *FieldDescriptorBuilder) SetCardinality(c FieldCardinality) *FieldDescriptorBuilder
SetCardinality sets the field cardinality (optional, required, or repeated).
func (*FieldDescriptorBuilder) SetContainingMessage ¶
func (b *FieldDescriptorBuilder) SetContainingMessage(msg MessageDescriptorAccessor) *FieldDescriptorBuilder
SetContainingMessage sets the message descriptor that contains this field.
func (*FieldDescriptorBuilder) SetContainingOneof ¶
func (b *FieldDescriptorBuilder) SetContainingOneof(o OneofDescriptorAccessor) *FieldDescriptorBuilder
SetContainingOneof sets the oneof descriptor that contains this field.
func (*FieldDescriptorBuilder) SetDefaultValue ¶
func (b *FieldDescriptorBuilder) SetDefaultValue(val string) *FieldDescriptorBuilder
SetDefaultValue sets the textual representation of the field's default value.
func (*FieldDescriptorBuilder) SetEnumType ¶
func (b *FieldDescriptorBuilder) SetEnumType(e EnumDescriptorAccessor) *FieldDescriptorBuilder
SetEnumType sets the enum descriptor for enum-typed fields.
func (*FieldDescriptorBuilder) SetFullName ¶
func (b *FieldDescriptorBuilder) SetFullName(fn FullName) *FieldDescriptorBuilder
SetFullName sets the fully qualified dot-separated name of the field.
func (*FieldDescriptorBuilder) SetHasJSONName ¶
func (b *FieldDescriptorBuilder) SetHasJSONName(v bool) *FieldDescriptorBuilder
SetHasJSONName sets whether the JSON name was explicitly set in the .proto file.
func (*FieldDescriptorBuilder) SetIsExtension ¶
func (b *FieldDescriptorBuilder) SetIsExtension(v bool) *FieldDescriptorBuilder
SetIsExtension sets whether this field is an extension field.
func (*FieldDescriptorBuilder) SetIsList ¶
func (b *FieldDescriptorBuilder) SetIsList(v bool) *FieldDescriptorBuilder
SetIsList sets whether the field is a list (repeated non-map) field.
func (*FieldDescriptorBuilder) SetIsMap ¶
func (b *FieldDescriptorBuilder) SetIsMap(v bool) *FieldDescriptorBuilder
SetIsMap sets whether the field is a map field.
func (*FieldDescriptorBuilder) SetIsPacked ¶
func (b *FieldDescriptorBuilder) SetIsPacked(v bool) *FieldDescriptorBuilder
SetIsPacked sets whether the field uses packed encoding.
func (*FieldDescriptorBuilder) SetJSONName ¶
func (b *FieldDescriptorBuilder) SetJSONName(name string) *FieldDescriptorBuilder
SetJSONName sets the JSON field name.
func (*FieldDescriptorBuilder) SetKind ¶
func (b *FieldDescriptorBuilder) SetKind(k scalar.Kind) *FieldDescriptorBuilder
SetKind sets the scalar kind of the field.
func (*FieldDescriptorBuilder) SetMessageType ¶
func (b *FieldDescriptorBuilder) SetMessageType(msg MessageDescriptorAccessor) *FieldDescriptorBuilder
SetMessageType sets the message descriptor for message-typed fields.
func (*FieldDescriptorBuilder) SetName ¶
func (b *FieldDescriptorBuilder) SetName(name string) *FieldDescriptorBuilder
SetName sets the unqualified short name of the field.
func (*FieldDescriptorBuilder) SetNumber ¶
func (b *FieldDescriptorBuilder) SetNumber(num uint32) *FieldDescriptorBuilder
SetNumber sets the protobuf field number.
func (*FieldDescriptorBuilder) SetOptions ¶
func (b *FieldDescriptorBuilder) SetOptions(opts []byte) *FieldDescriptorBuilder
SetOptions sets the serialized field options as an opaque byte slice.
func (*FieldDescriptorBuilder) SetResolvedFeatures ¶
func (b *FieldDescriptorBuilder) SetResolvedFeatures(features EditionFeatures) *FieldDescriptorBuilder
SetResolvedFeatures sets the resolved EditionFeatures for this field.
func (*FieldDescriptorBuilder) SetTypedOptions ¶
func (b *FieldDescriptorBuilder) SetTypedOptions(opts any) *FieldDescriptorBuilder
SetTypedOptions sets the parsed field options as a typed message. The value is typically a *dynamicpb.Message representing google.protobuf.FieldOptions.
type FieldDescriptors ¶
type FieldDescriptors struct {
// contains filtered or unexported fields
}
FieldDescriptors is a list of field descriptor pointers. It wraps an unexported slice to prevent caller mutation of the internal state.
func (FieldDescriptors) ByJSONName ¶
func (l FieldDescriptors) ByJSONName(name string) *FieldDescriptor
ByJSONName returns the field descriptor with the given JSON name, or nil if no such descriptor is found. It performs a linear scan over the list.
func (FieldDescriptors) ByName ¶
func (l FieldDescriptors) ByName(name string) *FieldDescriptor
ByName returns the field descriptor with the given unqualified name, or nil if no such descriptor is found. It performs a linear scan over the list.
func (FieldDescriptors) ByNumber ¶
func (l FieldDescriptors) ByNumber(num uint32) *FieldDescriptor
ByNumber returns the field descriptor with the given field number, or nil if no such descriptor is found. It performs a linear scan over the list.
func (FieldDescriptors) Get ¶
func (l FieldDescriptors) Get(i int) *FieldDescriptor
Get returns the field descriptor at the given index. It panics if the index is out of range, matching Go slice semantics.
func (FieldDescriptors) Len ¶
func (l FieldDescriptors) Len() int
Len returns the number of field descriptors in the list.
type FieldEncoder ¶
type FieldEncoder interface {
// Cardinality returns the field cardinality (optional, required, or
// repeated).
Cardinality() FieldCardinality
// DefaultValue returns the textual representation of the field's
// default value.
DefaultValue() string
// Number returns the protobuf field number.
Number() uint32
// Kind returns the scalar kind of the field.
Kind() scalar.Kind
}
FieldEncoder provides the encoding-relevant properties of a protobuf field: cardinality, default value, number, and kind. Functions that need to make encoding decisions should accept this narrow interface.
type FieldIdentifier ¶
type FieldIdentifier interface {
DescriptorAccessor
// Number returns the protobuf field number.
Number() uint32
// JSONName returns the JSON field name.
JSONName() string
// HasJSONName reports whether the JSON name was explicitly set in the
// .proto file rather than auto-generated.
HasJSONName() bool
}
FieldIdentifier provides the minimal identity properties of a protobuf field: its number, name, full name, and JSON name. Functions that only need to identify a field should accept this narrow interface rather than the full FieldDescriptorAccessor.
type FieldPresence ¶
type FieldPresence int8
FieldPresence controls how field presence is tracked for a field under editions semantics. It replaces the implicit rules derived from proto2 vs proto3 syntax.
const ( FieldPresenceExplicit FieldPresence = 1 FieldPresenceImplicit FieldPresence = 2 FieldPresenceLegacyRequired FieldPresence = 3 )
FieldPresence constants matching the official protobuf edition feature values.
func (FieldPresence) String ¶
func (fp FieldPresence) String() string
String returns a human-readable name for the FieldPresence constant.
type FieldTyper ¶
type FieldTyper interface {
// Kind returns the scalar kind of the field.
Kind() scalar.Kind
// MessageType returns the message descriptor for message-typed fields,
// or nil if the field is not a message type.
MessageType() MessageDescriptorAccessor
// EnumType returns the enum descriptor for enum-typed fields, or nil
// if the field is not an enum type.
EnumType() EnumDescriptorAccessor
// IsList reports whether the field is a list (repeated non-map) field.
IsList() bool
// IsMap reports whether the field is a map field.
IsMap() bool
// IsPacked reports whether the field uses packed encoding.
IsPacked() bool
// IsExtension reports whether this field is an extension field.
IsExtension() bool
}
FieldTyper provides type-related properties of a protobuf field: its scalar kind, associated message/enum types, and structural flags (list, map, packed, extension). Functions that only need to inspect a field's type should accept this narrow interface.
ISP note: FieldTyper has 7 methods. It is already a sub-interface of the larger FieldDescriptorAccessor and represents a single cohesive "field type introspection" concern. The type-query methods (Kind, MessageType, EnumType) and structural-flag methods (IsList, IsMap, IsPacked, IsExtension) are always used together when making encoding or code-generation decisions. Splitting further would create fragments with no independent consumers. This is documented as an accepted exception to the 5-method guideline.
type FileContents ¶
type FileContents interface {
// Dependencies returns the list of files this file directly imports.
Dependencies() FileDescriptors
// Messages returns the top-level message descriptors defined in the file.
Messages() MessageDescriptors
// Enums returns the top-level enum descriptors defined in the file.
Enums() EnumDescriptors
// Services returns the service descriptors defined in the file.
Services() ServiceDescriptors
// Extensions returns the top-level extension field descriptors defined
// in the file.
Extensions() FieldDescriptors
}
FileContents provides access to the top-level declarations contained in a protobuf file: messages, enums, services, extensions, and dependencies.
type FileDescriptor ¶
type FileDescriptor struct {
// contains filtered or unexported fields
}
FileDescriptor represents an immutable protobuf file descriptor. It holds metadata about a .proto file, including its syntax version, package name, dependencies, top-level messages, enums, services, extensions, and serialized options. Access its properties through the FileDescriptorAccessor interface.
func (*FileDescriptor) Dependencies ¶
func (d *FileDescriptor) Dependencies() FileDescriptors
Dependencies returns the list of files this file directly imports.
func (*FileDescriptor) Edition ¶
func (d *FileDescriptor) Edition() string
Edition returns the edition string (e.g., "2023", "2024") for files using editions syntax. Returns an empty string for proto2/proto3 files.
func (*FileDescriptor) Enums ¶
func (d *FileDescriptor) Enums() EnumDescriptors
Enums returns the top-level enum descriptors defined in the file.
func (*FileDescriptor) Extensions ¶
func (d *FileDescriptor) Extensions() FieldDescriptors
Extensions returns the top-level extension field descriptors defined in the file.
func (*FileDescriptor) Features ¶
func (d *FileDescriptor) Features() EditionFeatures
Features returns the file-level EditionFeatures. For non-editions files, this returns a zero-value EditionFeatures.
func (*FileDescriptor) FullName ¶
func (d *FileDescriptor) FullName() FullName
FullName returns the fully qualified name of the file, which is the protobuf package name declared in the file.
func (*FileDescriptor) Messages ¶
func (d *FileDescriptor) Messages() MessageDescriptors
Messages returns the top-level message descriptors defined in the file.
func (*FileDescriptor) Name ¶
func (d *FileDescriptor) Name() string
Name returns the file path of the .proto file. For a file descriptor, the name is the file path rather than a short identifier.
func (*FileDescriptor) Options ¶
func (d *FileDescriptor) Options() []byte
Options returns a copy of the serialized file options as an opaque byte slice. Returns nil if no options are set.
func (*FileDescriptor) Package ¶
func (d *FileDescriptor) Package() string
Package returns the protobuf package name declared in the file.
func (*FileDescriptor) Path ¶
func (d *FileDescriptor) Path() string
Path returns the file path of the .proto file.
func (*FileDescriptor) Services ¶
func (d *FileDescriptor) Services() ServiceDescriptors
Services returns the service descriptors defined in the file.
func (*FileDescriptor) SetTypedOptionsResolved ¶
func (d *FileDescriptor) SetTypedOptionsResolved(opts any)
SetTypedOptionsResolved sets the typed options on the file descriptor after it has been built. This is used by the compilation pipeline to populate typed options from raw option bytes during resolution.
func (*FileDescriptor) SourceCodeInfo ¶
func (d *FileDescriptor) SourceCodeInfo() *SourceCodeInfo
SourceCodeInfo returns the source code location information for the file, or nil if no source code info was provided.
func (*FileDescriptor) Syntax ¶
func (d *FileDescriptor) Syntax() Syntax
Syntax returns the protobuf syntax version of the file.
func (*FileDescriptor) TypedOptions ¶
func (d *FileDescriptor) TypedOptions() any
TypedOptions returns the parsed file options as a typed message, or nil if no typed options have been set.
type FileDescriptorAccessor ¶
type FileDescriptorAccessor interface {
FileIdentity
FileContents
FileOptionsAccessor
}
FileDescriptorAccessor is the read-only interface for accessing file descriptor properties. It composes the narrower FileIdentity, FileContents, and FileOptionsAccessor sub-interfaces, following the Interface Segregation Principle. Functions should accept the narrowest sub-interface their logic requires rather than the full accessor.
type FileDescriptorBuilder ¶
type FileDescriptorBuilder struct {
// contains filtered or unexported fields
}
FileDescriptorBuilder constructs an immutable FileDescriptor through a chainable setter API. Call Build to validate and produce the descriptor. Builders are reusable: calling Build multiple times produces independent descriptors.
func (*FileDescriptorBuilder) AddDependency ¶
func (b *FileDescriptorBuilder) AddDependency(dep *FileDescriptor) *FileDescriptorBuilder
AddDependency appends a file descriptor to the list of direct imports.
func (*FileDescriptorBuilder) AddEnum ¶
func (b *FileDescriptorBuilder) AddEnum(e *EnumDescriptor) *FileDescriptorBuilder
AddEnum appends a top-level enum descriptor to the file.
func (*FileDescriptorBuilder) AddExtension ¶
func (b *FileDescriptorBuilder) AddExtension(ext *FieldDescriptor) *FileDescriptorBuilder
AddExtension appends a top-level extension field descriptor to the file.
func (*FileDescriptorBuilder) AddMessage ¶
func (b *FileDescriptorBuilder) AddMessage(msg *MessageDescriptor) *FileDescriptorBuilder
AddMessage appends a top-level message descriptor to the file.
func (*FileDescriptorBuilder) AddService ¶
func (b *FileDescriptorBuilder) AddService(svc *ServiceDescriptor) *FileDescriptorBuilder
AddService appends a service descriptor to the file.
func (*FileDescriptorBuilder) Build ¶
func (b *FileDescriptorBuilder) Build() (*FileDescriptor, error)
Build validates the builder state and returns an immutable FileDescriptor. It returns an error if the name (file path) is empty or the package name (used as full name) is empty.
func (*FileDescriptorBuilder) SetEdition ¶
func (b *FileDescriptorBuilder) SetEdition(edition string) *FileDescriptorBuilder
SetEdition sets the edition string (e.g., "2023", "2024") for files using editions syntax.
func (*FileDescriptorBuilder) SetFeatures ¶
func (b *FileDescriptorBuilder) SetFeatures(features EditionFeatures) *FileDescriptorBuilder
SetFeatures sets the file-level EditionFeatures.
func (*FileDescriptorBuilder) SetName ¶
func (b *FileDescriptorBuilder) SetName(name string) *FileDescriptorBuilder
SetName sets the file path of the .proto file.
func (*FileDescriptorBuilder) SetOptions ¶
func (b *FileDescriptorBuilder) SetOptions(opts []byte) *FileDescriptorBuilder
SetOptions sets the serialized file options as an opaque byte slice.
func (*FileDescriptorBuilder) SetPackage ¶
func (b *FileDescriptorBuilder) SetPackage(pkg string) *FileDescriptorBuilder
SetPackage sets the protobuf package name declared in the file. The package name also becomes the full name of the file descriptor.
func (*FileDescriptorBuilder) SetSourceCodeInfo ¶
func (b *FileDescriptorBuilder) SetSourceCodeInfo(sci *SourceCodeInfo) *FileDescriptorBuilder
SetSourceCodeInfo sets the source code location information for the file. Source code info is optional and does not affect serialization behavior.
func (*FileDescriptorBuilder) SetSyntax ¶
func (b *FileDescriptorBuilder) SetSyntax(s Syntax) *FileDescriptorBuilder
SetSyntax sets the protobuf syntax version of the file.
func (*FileDescriptorBuilder) SetTypedOptions ¶
func (b *FileDescriptorBuilder) SetTypedOptions(opts any) *FileDescriptorBuilder
SetTypedOptions sets the parsed file options as a typed message. The value is typically a *dynamicpb.Message representing google.protobuf.FileOptions.
type FileDescriptors ¶
type FileDescriptors struct {
// contains filtered or unexported fields
}
FileDescriptors is a list of file descriptor pointers. It wraps an unexported slice to prevent caller mutation of the internal state.
func (FileDescriptors) ByName ¶
func (l FileDescriptors) ByName(name string) *FileDescriptor
ByName returns the file descriptor with the given unqualified name, or nil if no such descriptor is found. It performs a linear scan over the list.
func (FileDescriptors) Get ¶
func (l FileDescriptors) Get(i int) *FileDescriptor
Get returns the file descriptor at the given index. It panics if the index is out of range, matching Go slice semantics.
func (FileDescriptors) Len ¶
func (l FileDescriptors) Len() int
Len returns the number of file descriptors in the list.
type FileIdentity ¶
type FileIdentity interface {
DescriptorAccessor
// Syntax returns the protobuf syntax version of the file.
Syntax() Syntax
// Path returns the file path of the .proto file.
Path() string
// Package returns the protobuf package name declared in the file.
Package() string
}
FileIdentity provides the minimal identity and syntax properties of a protobuf file descriptor. Functions that only need to identify a file or check its syntax should accept this narrow interface rather than the full FileDescriptorAccessor.
type FileOptionsAccessor ¶
type FileOptionsAccessor interface {
// Options returns the serialized file options as an opaque byte slice.
Options() []byte
// TypedOptions returns the parsed file options as a typed message, or
// nil if no typed options have been set. The returned value is typically
// a *dynamicpb.Message representing google.protobuf.FileOptions. Callers
// should type-assert to the expected concrete type.
TypedOptions() any
// SourceCodeInfo returns the source code location information for the
// file, or nil if no source code info was provided. Source code info
// is optional and does not affect serialization behavior.
SourceCodeInfo() *SourceCodeInfo
// Edition returns the edition string (e.g., "2023", "2024") for files
// using editions syntax. Returns an empty string for proto2/proto3.
Edition() string
// Features returns the file-level EditionFeatures. For non-editions
// files, this returns a zero-value EditionFeatures.
Features() EditionFeatures
}
FileOptionsAccessor provides access to file-level options, source info, edition, and features metadata.
type FullName ¶
type FullName string
FullName represents a dot-separated fully qualified protobuf name such as "mypackage.MyMessage.my_field". It provides methods to extract the trailing component and the parent prefix.
type GoAPIMode ¶
type GoAPIMode int8
GoAPIMode controls whether generated Go message structs use the traditional open API (exported fields) or the opaque API (unexported fields with getter/setter methods) under Edition 2024 semantics. It is a Go-specific edition feature.
GoAPIMode constants matching the Go-specific edition feature values.
type JsonFormat ¶
type JsonFormat int8
JsonFormat controls JSON serialization behavior under editions semantics.
const ( JsonFormatAllow JsonFormat = 1 JsonFormatLegacyBestEffort JsonFormat = 2 )
JsonFormat constants matching the official protobuf edition feature values.
func (JsonFormat) String ¶
func (jf JsonFormat) String() string
String returns a human-readable name for the JsonFormat constant.
type Location ¶
type Location struct {
Path []int32
Span []int32
LeadingComments string
TrailingComments string
LeadingDetachedComments []string
}
Location represents a single source code location within a .proto file. It maps a path of field tag indices to source positions and associated comments. Path identifies the declaration using the standard protobuf SourceCodeInfo encoding (a sequence of field numbers identifying the descriptor tree traversal to reach the declaration). Span encodes the source position as [startLine, startColumn, endLine, endColumn] or [startLine, startColumn, endColumn] when start and end are on the same line.
type MessageDescriptor ¶
type MessageDescriptor struct {
// contains filtered or unexported fields
}
MessageDescriptor represents an immutable protobuf message descriptor. It holds metadata about a message type, including its fields, oneofs, nested types, extension ranges, reserved ranges and names, and serialized options. Access its properties through the MessageDescriptorAccessor interface.
func (*MessageDescriptor) ExtensionRanges ¶
func (d *MessageDescriptor) ExtensionRanges() [][2]uint32
ExtensionRanges returns a copy of the extension range pairs for this message. Mutating the returned slice does not affect the descriptor.
func (*MessageDescriptor) Fields ¶
func (d *MessageDescriptor) Fields() FieldDescriptors
Fields returns the field descriptors defined in this message.
func (*MessageDescriptor) FullName ¶
func (d *MessageDescriptor) FullName() FullName
FullName returns the fully qualified dot-separated name of the message.
func (*MessageDescriptor) HasFieldNumberInExtensionRange ¶
func (d *MessageDescriptor) HasFieldNumberInExtensionRange(number uint32) bool
HasFieldNumberInExtensionRange reports whether the given field number falls within any of the message's declared extension ranges. Ranges use start-inclusive, end-exclusive semantics: [start, end).
func (*MessageDescriptor) IsMapEntry ¶
func (d *MessageDescriptor) IsMapEntry() bool
IsMapEntry reports whether this message is a synthetic map entry type.
func (*MessageDescriptor) Name ¶
func (d *MessageDescriptor) Name() string
Name returns the unqualified short name of the message.
func (*MessageDescriptor) NestedEnums ¶
func (d *MessageDescriptor) NestedEnums() EnumDescriptors
NestedEnums returns the nested enum descriptors defined in this message.
func (*MessageDescriptor) NestedMessages ¶
func (d *MessageDescriptor) NestedMessages() MessageDescriptors
NestedMessages returns the nested message descriptors defined in this message.
func (*MessageDescriptor) Oneofs ¶
func (d *MessageDescriptor) Oneofs() OneofDescriptors
Oneofs returns the oneof descriptors defined in this message.
func (*MessageDescriptor) Options ¶
func (d *MessageDescriptor) Options() []byte
Options returns a copy of the serialized message options as an opaque byte slice. Returns nil if no options are set.
func (*MessageDescriptor) Parent ¶
func (d *MessageDescriptor) Parent() DescriptorAccessor
Parent returns the parent descriptor, which is either a file or a message for nested message types.
func (*MessageDescriptor) ReservedNames ¶
func (d *MessageDescriptor) ReservedNames() []string
ReservedNames returns a copy of the reserved field names for this message. Mutating the returned slice does not affect the descriptor.
func (*MessageDescriptor) ReservedRanges ¶
func (d *MessageDescriptor) ReservedRanges() [][2]uint32
ReservedRanges returns a copy of the reserved field number range pairs for this message. Mutating the returned slice does not affect the descriptor.
func (*MessageDescriptor) ResolvedFeatures ¶
func (d *MessageDescriptor) ResolvedFeatures() EditionFeatures
ResolvedFeatures returns the resolved EditionFeatures for this message, incorporating file-level defaults and message-level overrides. For non-editions messages, this returns a zero-value EditionFeatures.
func (*MessageDescriptor) SetTypedOptionsResolved ¶
func (d *MessageDescriptor) SetTypedOptionsResolved(opts any)
SetTypedOptionsResolved sets the typed options on the message descriptor after it has been built. This is used by the compilation pipeline to populate typed options from raw option bytes during resolution.
func (*MessageDescriptor) TypedOptions ¶
func (d *MessageDescriptor) TypedOptions() any
TypedOptions returns the parsed message options as a typed message, or nil if no typed options have been set.
type MessageDescriptorAccessor ¶
type MessageDescriptorAccessor interface {
DescriptorAccessor
// Parent returns the parent descriptor, which is either a file or a
// message for nested message types.
Parent() DescriptorAccessor
// Fields returns the field descriptors defined in this message.
Fields() FieldDescriptors
// Oneofs returns the oneof descriptors defined in this message.
Oneofs() OneofDescriptors
// NestedMessages returns the nested message descriptors defined in
// this message.
NestedMessages() MessageDescriptors
// NestedEnums returns the nested enum descriptors defined in this
// message.
NestedEnums() EnumDescriptors
// ExtensionRanges returns the extension range pairs for this message.
ExtensionRanges() [][2]uint32
// HasFieldNumberInExtensionRange reports whether the given field number
// falls within any of the message's declared extension ranges. Ranges
// use start-inclusive, end-exclusive semantics: [start, end).
HasFieldNumberInExtensionRange(number uint32) bool
// ReservedRanges returns the reserved field number range pairs for
// this message.
ReservedRanges() [][2]uint32
// ReservedNames returns the reserved field names for this message.
ReservedNames() []string
// IsMapEntry reports whether this message is a synthetic map entry
// type.
IsMapEntry() bool
// Options returns the serialized message options as an opaque byte
// slice.
Options() []byte
// TypedOptions returns the parsed message options as a typed message,
// or nil if no typed options have been set. The returned value is
// typically a *dynamicpb.Message representing
// google.protobuf.MessageOptions. Callers should type-assert to the
// expected concrete type.
TypedOptions() any
// ResolvedFeatures returns the resolved EditionFeatures for this
// message, incorporating file-level defaults and message-level
// overrides. For non-editions messages, this returns a zero-value
// EditionFeatures.
ResolvedFeatures() EditionFeatures
}
MessageDescriptorAccessor is the read-only interface for accessing message descriptor properties. It embeds DescriptorAccessor for the common identity contract and adds methods specific to protobuf message descriptors.
ISP note: MessageDescriptorAccessor has 15 methods (including embedded DescriptorAccessor). Splitting was evaluated but the methods form a single cohesive "message schema" concern, and all consumers (protoreflect.Message, codegen, protodesc, dynamicpb) use the majority of the methods. Splitting would create sub-interfaces with overlapping consumers and no clear independent usage pattern. This is documented as an accepted exception.
type MessageDescriptorBuilder ¶
type MessageDescriptorBuilder struct {
// contains filtered or unexported fields
}
MessageDescriptorBuilder constructs an immutable MessageDescriptor through a chainable setter API. Call Build to validate and produce the descriptor. Builders are reusable: calling Build multiple times produces independent descriptors.
func (*MessageDescriptorBuilder) AddField ¶
func (b *MessageDescriptorBuilder) AddField(fd *FieldDescriptor) *MessageDescriptorBuilder
AddField appends a field descriptor to the message.
func (*MessageDescriptorBuilder) AddNestedEnum ¶
func (b *MessageDescriptorBuilder) AddNestedEnum(ed *EnumDescriptor) *MessageDescriptorBuilder
AddNestedEnum appends a nested enum descriptor to the message.
func (*MessageDescriptorBuilder) AddNestedMessage ¶
func (b *MessageDescriptorBuilder) AddNestedMessage(md *MessageDescriptor) *MessageDescriptorBuilder
AddNestedMessage appends a nested message descriptor to the message.
func (*MessageDescriptorBuilder) AddOneof ¶
func (b *MessageDescriptorBuilder) AddOneof(od *OneofDescriptor) *MessageDescriptorBuilder
AddOneof appends a oneof descriptor to the message.
func (*MessageDescriptorBuilder) Build ¶
func (b *MessageDescriptorBuilder) Build() (*MessageDescriptor, error)
Build validates the builder state and returns an immutable MessageDescriptor. It returns an error if the name or full name is empty.
func (*MessageDescriptorBuilder) SetExtensionRanges ¶
func (b *MessageDescriptorBuilder) SetExtensionRanges(ranges [][2]uint32) *MessageDescriptorBuilder
SetExtensionRanges sets the extension range pairs for the message.
func (*MessageDescriptorBuilder) SetFullName ¶
func (b *MessageDescriptorBuilder) SetFullName(fn FullName) *MessageDescriptorBuilder
SetFullName sets the fully qualified dot-separated name of the message.
func (*MessageDescriptorBuilder) SetIsMapEntry ¶
func (b *MessageDescriptorBuilder) SetIsMapEntry(v bool) *MessageDescriptorBuilder
SetIsMapEntry sets whether the message is a synthetic map entry type.
func (*MessageDescriptorBuilder) SetName ¶
func (b *MessageDescriptorBuilder) SetName(name string) *MessageDescriptorBuilder
SetName sets the unqualified short name of the message.
func (*MessageDescriptorBuilder) SetOptions ¶
func (b *MessageDescriptorBuilder) SetOptions(opts []byte) *MessageDescriptorBuilder
SetOptions sets the serialized message options as an opaque byte slice.
func (*MessageDescriptorBuilder) SetParent ¶
func (b *MessageDescriptorBuilder) SetParent(p DescriptorAccessor) *MessageDescriptorBuilder
SetParent sets the parent descriptor (file or enclosing message).
func (*MessageDescriptorBuilder) SetReservedNames ¶
func (b *MessageDescriptorBuilder) SetReservedNames(names []string) *MessageDescriptorBuilder
SetReservedNames sets the reserved field names for the message.
func (*MessageDescriptorBuilder) SetReservedRanges ¶
func (b *MessageDescriptorBuilder) SetReservedRanges(ranges [][2]uint32) *MessageDescriptorBuilder
SetReservedRanges sets the reserved field number range pairs for the message.
func (*MessageDescriptorBuilder) SetResolvedFeatures ¶
func (b *MessageDescriptorBuilder) SetResolvedFeatures(features EditionFeatures) *MessageDescriptorBuilder
SetResolvedFeatures sets the resolved EditionFeatures for this message.
func (*MessageDescriptorBuilder) SetTypedOptions ¶
func (b *MessageDescriptorBuilder) SetTypedOptions(opts any) *MessageDescriptorBuilder
SetTypedOptions sets the parsed message options as a typed message. The value is typically a *dynamicpb.Message representing google.protobuf.MessageOptions.
type MessageDescriptors ¶
type MessageDescriptors struct {
// contains filtered or unexported fields
}
MessageDescriptors is a list of message descriptor pointers. It wraps an unexported slice to prevent caller mutation of the internal state.
func (MessageDescriptors) ByName ¶
func (l MessageDescriptors) ByName(name string) *MessageDescriptor
ByName returns the message descriptor with the given unqualified name, or nil if no such descriptor is found. It performs a linear scan over the list.
func (MessageDescriptors) Get ¶
func (l MessageDescriptors) Get(i int) *MessageDescriptor
Get returns the message descriptor at the given index. It panics if the index is out of range, matching Go slice semantics.
func (MessageDescriptors) Len ¶
func (l MessageDescriptors) Len() int
Len returns the number of message descriptors in the list.
type MessageEncoding ¶
type MessageEncoding int8
MessageEncoding controls the wire encoding of sub-messages under editions semantics.
const ( MessageEncodingLengthPrefixed MessageEncoding = 1 MessageEncodingDelimited MessageEncoding = 2 )
MessageEncoding constants matching the official protobuf edition feature values.
func (MessageEncoding) String ¶
func (me MessageEncoding) String() string
String returns a human-readable name for the MessageEncoding constant.
type MethodDescriptor ¶
type MethodDescriptor struct {
// contains filtered or unexported fields
}
MethodDescriptor represents an immutable protobuf method descriptor. It holds the name, parent service, input/output types, streaming flags, and serialized options for a single RPC method. Access its properties through the MethodDescriptorAccessor interface.
func (*MethodDescriptor) FullName ¶
func (d *MethodDescriptor) FullName() FullName
FullName returns the fully qualified dot-separated name of this method.
func (*MethodDescriptor) InputType ¶
func (d *MethodDescriptor) InputType() MessageDescriptorAccessor
InputType returns the message descriptor for the method's input type.
func (*MethodDescriptor) IsClientStreaming ¶
func (d *MethodDescriptor) IsClientStreaming() bool
IsClientStreaming reports whether the method uses client-side streaming.
func (*MethodDescriptor) IsServerStreaming ¶
func (d *MethodDescriptor) IsServerStreaming() bool
IsServerStreaming reports whether the method uses server-side streaming.
func (*MethodDescriptor) Name ¶
func (d *MethodDescriptor) Name() string
Name returns the unqualified short name of this method.
func (*MethodDescriptor) Options ¶
func (d *MethodDescriptor) Options() []byte
Options returns the serialized method options as an opaque byte slice. The returned slice is a copy; modifying it does not affect the descriptor.
func (*MethodDescriptor) OutputType ¶
func (d *MethodDescriptor) OutputType() MessageDescriptorAccessor
OutputType returns the message descriptor for the method's output type.
func (*MethodDescriptor) Parent ¶
func (d *MethodDescriptor) Parent() ServiceDescriptorAccessor
Parent returns the service descriptor that contains this method.
func (*MethodDescriptor) SetTypedOptionsResolved ¶
func (d *MethodDescriptor) SetTypedOptionsResolved(opts any)
SetTypedOptionsResolved sets the typed options on the method descriptor after it has been built. This is used by the compilation pipeline to populate typed options from raw option bytes during resolution.
func (*MethodDescriptor) TypedOptions ¶
func (d *MethodDescriptor) TypedOptions() any
TypedOptions returns the parsed method options as a typed message, or nil if no typed options have been set.
type MethodDescriptorAccessor ¶
type MethodDescriptorAccessor interface {
DescriptorAccessor
// Parent returns the service descriptor that contains this method.
Parent() ServiceDescriptorAccessor
// InputType returns the message descriptor for the method's input
// type.
InputType() MessageDescriptorAccessor
// OutputType returns the message descriptor for the method's output
// type.
OutputType() MessageDescriptorAccessor
// IsClientStreaming reports whether the method uses client-side
// streaming.
IsClientStreaming() bool
// IsServerStreaming reports whether the method uses server-side
// streaming.
IsServerStreaming() bool
// Options returns the serialized method options as an opaque byte
// slice.
Options() []byte
// TypedOptions returns the parsed method options as a typed message,
// or nil if no typed options have been set. The returned value is
// typically a *dynamicpb.Message representing
// google.protobuf.MethodOptions. Callers should type-assert to the
// expected concrete type.
TypedOptions() any
}
MethodDescriptorAccessor is the read-only interface for accessing method descriptor properties. It embeds DescriptorAccessor for the common identity contract and adds methods specific to protobuf method descriptors.
ISP note: MethodDescriptorAccessor has 9 methods (including embedded DescriptorAccessor). The methods form a single cohesive "RPC method schema" concern. Splitting input/output types from streaming flags would create sub-interfaces with no independent consumers. This is documented as an accepted exception to the 5-method guideline.
type MethodDescriptorBuilder ¶
type MethodDescriptorBuilder struct {
// contains filtered or unexported fields
}
MethodDescriptorBuilder constructs an immutable MethodDescriptor through a chainable setter API. Call Build to validate and produce the descriptor. Builders are reusable: calling Build multiple times produces independent descriptors.
func (*MethodDescriptorBuilder) Build ¶
func (b *MethodDescriptorBuilder) Build() (*MethodDescriptor, error)
Build validates the builder state and returns an immutable MethodDescriptor. It returns an error if the name or full name is empty.
func (*MethodDescriptorBuilder) SetClientStreaming ¶
func (b *MethodDescriptorBuilder) SetClientStreaming(v bool) *MethodDescriptorBuilder
SetClientStreaming sets whether the method uses client-side streaming.
func (*MethodDescriptorBuilder) SetFullName ¶
func (b *MethodDescriptorBuilder) SetFullName(fn FullName) *MethodDescriptorBuilder
SetFullName sets the fully qualified dot-separated name of the method.
func (*MethodDescriptorBuilder) SetInputType ¶
func (b *MethodDescriptorBuilder) SetInputType(msg MessageDescriptorAccessor) *MethodDescriptorBuilder
SetInputType sets the message descriptor for the method's input type.
func (*MethodDescriptorBuilder) SetName ¶
func (b *MethodDescriptorBuilder) SetName(name string) *MethodDescriptorBuilder
SetName sets the unqualified short name of the method.
func (*MethodDescriptorBuilder) SetOptions ¶
func (b *MethodDescriptorBuilder) SetOptions(opts []byte) *MethodDescriptorBuilder
SetOptions sets the serialized method options as an opaque byte slice.
func (*MethodDescriptorBuilder) SetOutputType ¶
func (b *MethodDescriptorBuilder) SetOutputType(msg MessageDescriptorAccessor) *MethodDescriptorBuilder
SetOutputType sets the message descriptor for the method's output type.
func (*MethodDescriptorBuilder) SetParent ¶
func (b *MethodDescriptorBuilder) SetParent(p ServiceDescriptorAccessor) *MethodDescriptorBuilder
SetParent sets the service descriptor that contains this method.
func (*MethodDescriptorBuilder) SetServerStreaming ¶
func (b *MethodDescriptorBuilder) SetServerStreaming(v bool) *MethodDescriptorBuilder
SetServerStreaming sets whether the method uses server-side streaming.
func (*MethodDescriptorBuilder) SetTypedOptions ¶
func (b *MethodDescriptorBuilder) SetTypedOptions(opts any) *MethodDescriptorBuilder
SetTypedOptions sets the parsed method options as a typed message. The value is typically a *dynamicpb.Message representing google.protobuf.MethodOptions.
type MethodDescriptors ¶
type MethodDescriptors struct {
// contains filtered or unexported fields
}
MethodDescriptors is a list of method descriptor pointers. It wraps an unexported slice to prevent caller mutation of the internal state.
func (MethodDescriptors) ByName ¶
func (l MethodDescriptors) ByName(name string) *MethodDescriptor
ByName returns the method descriptor with the given unqualified name, or nil if no such descriptor is found. It performs a linear scan over the list.
func (MethodDescriptors) Get ¶
func (l MethodDescriptors) Get(i int) *MethodDescriptor
Get returns the method descriptor at the given index. It panics if the index is out of range, matching Go slice semantics.
func (MethodDescriptors) Len ¶
func (l MethodDescriptors) Len() int
Len returns the number of method descriptors in the list.
type NamingStyle ¶
type NamingStyle int8
NamingStyle controls whether generated type and enum value names are validated against Edition 2024 naming conventions. It is a Go-specific edition feature.
const ( NamingStyleLegacy NamingStyle = 1 NamingStyle2024 NamingStyle = 2 )
NamingStyle constants matching the Go-specific edition feature values.
func (NamingStyle) String ¶
func (ns NamingStyle) String() string
String returns a human-readable name for the NamingStyle constant.
type OneofDescriptor ¶
type OneofDescriptor struct {
// contains filtered or unexported fields
}
OneofDescriptor represents an immutable protobuf oneof descriptor. It holds metadata about a oneof group within a message, including the fields that belong to it and whether it is a synthetic oneof generated for proto3 optional fields. Access its properties through the OneofDescriptorAccessor interface.
func (*OneofDescriptor) Fields ¶
func (d *OneofDescriptor) Fields() FieldDescriptors
Fields returns the field descriptors that belong to this oneof.
func (*OneofDescriptor) FullName ¶
func (d *OneofDescriptor) FullName() FullName
FullName returns the fully qualified dot-separated name of the oneof.
func (*OneofDescriptor) IsSynthetic ¶
func (d *OneofDescriptor) IsSynthetic() bool
IsSynthetic reports whether this oneof is a synthetic oneof generated for proto3 optional fields.
func (*OneofDescriptor) Name ¶
func (d *OneofDescriptor) Name() string
Name returns the unqualified short name of the oneof.
func (*OneofDescriptor) Options ¶
func (d *OneofDescriptor) Options() []byte
Options returns a copy of the serialized oneof options as an opaque byte slice. Returns nil if no options are set.
func (*OneofDescriptor) Parent ¶
func (d *OneofDescriptor) Parent() MessageDescriptorAccessor
Parent returns the message descriptor that contains this oneof.
func (*OneofDescriptor) PopulateFields ¶
func (d *OneofDescriptor) PopulateFields(s []*FieldDescriptor)
PopulateFields swaps the descriptor's field list to the provided slice. It exists exclusively to fix the codegen bootstrap order: descriptors are built before fields know their containing oneof, so the initial OneofDescriptor must be constructed without fields and then back-filled once the FieldDescriptors that reference it are themselves built. Outside of that single use site this method MUST NOT be called — it intentionally breaks the immutability contract of the descriptor.
The method makes a defensive copy of s so the caller's slice can be mutated independently after the call.
type OneofDescriptorAccessor ¶
type OneofDescriptorAccessor interface {
DescriptorAccessor
// Parent returns the message descriptor that contains this oneof.
Parent() MessageDescriptorAccessor
// Fields returns the field descriptors that belong to this oneof.
Fields() FieldDescriptors
// IsSynthetic reports whether this oneof is a synthetic oneof
// generated for proto3 optional fields.
IsSynthetic() bool
// Options returns the serialized oneof options as an opaque byte
// slice.
Options() []byte
}
OneofDescriptorAccessor is the read-only interface for accessing oneof descriptor properties. It embeds DescriptorAccessor for the common identity contract and adds methods specific to protobuf oneof descriptors.
ISP note: OneofDescriptorAccessor has 6 methods (including embedded DescriptorAccessor). The methods form a single cohesive "oneof schema" concern. All consumers (codegen, dynamicpb, protodesc) use the full set when processing oneof declarations. Splitting into identity and structure sub-interfaces would create fragments with no independent consumers. This is documented as an accepted exception to the 5-method guideline.
type OneofDescriptorBuilder ¶
type OneofDescriptorBuilder struct {
// contains filtered or unexported fields
}
OneofDescriptorBuilder constructs an immutable OneofDescriptor through a chainable setter API. Call Build to validate and produce the descriptor. Builders are reusable: calling Build multiple times produces independent descriptors.
func (*OneofDescriptorBuilder) AddField ¶
func (b *OneofDescriptorBuilder) AddField(fd *FieldDescriptor) *OneofDescriptorBuilder
AddField appends a field descriptor to the oneof.
func (*OneofDescriptorBuilder) Build ¶
func (b *OneofDescriptorBuilder) Build() (*OneofDescriptor, error)
Build validates the builder state and returns an immutable OneofDescriptor. It returns an error if the name or full name is empty.
func (*OneofDescriptorBuilder) SetFullName ¶
func (b *OneofDescriptorBuilder) SetFullName(fn FullName) *OneofDescriptorBuilder
SetFullName sets the fully qualified dot-separated name of the oneof.
func (*OneofDescriptorBuilder) SetIsSynthetic ¶
func (b *OneofDescriptorBuilder) SetIsSynthetic(v bool) *OneofDescriptorBuilder
SetIsSynthetic sets whether this oneof is a synthetic oneof generated for proto3 optional fields.
func (*OneofDescriptorBuilder) SetName ¶
func (b *OneofDescriptorBuilder) SetName(name string) *OneofDescriptorBuilder
SetName sets the unqualified short name of the oneof.
func (*OneofDescriptorBuilder) SetOptions ¶
func (b *OneofDescriptorBuilder) SetOptions(opts []byte) *OneofDescriptorBuilder
SetOptions sets the serialized oneof options as an opaque byte slice.
func (*OneofDescriptorBuilder) SetParent ¶
func (b *OneofDescriptorBuilder) SetParent(p MessageDescriptorAccessor) *OneofDescriptorBuilder
SetParent sets the message descriptor that contains this oneof.
type OneofDescriptors ¶
type OneofDescriptors struct {
// contains filtered or unexported fields
}
OneofDescriptors is a list of oneof descriptor pointers. It wraps an unexported slice to prevent caller mutation of the internal state.
func (OneofDescriptors) ByName ¶
func (l OneofDescriptors) ByName(name string) *OneofDescriptor
ByName returns the oneof descriptor with the given unqualified name, or nil if no such descriptor is found. It performs a linear scan over the list.
func (OneofDescriptors) Get ¶
func (l OneofDescriptors) Get(i int) *OneofDescriptor
Get returns the oneof descriptor at the given index. It panics if the index is out of range, matching Go slice semantics.
func (OneofDescriptors) Len ¶
func (l OneofDescriptors) Len() int
Len returns the number of oneof descriptors in the list.
type RepeatedFieldEncoding ¶
type RepeatedFieldEncoding int8
RepeatedFieldEncoding controls the wire encoding of repeated scalar fields under editions semantics.
const ( RepeatedFieldEncodingPacked RepeatedFieldEncoding = 1 RepeatedFieldEncodingExpanded RepeatedFieldEncoding = 2 )
RepeatedFieldEncoding constants matching the official protobuf edition feature values.
func (RepeatedFieldEncoding) String ¶
func (rfe RepeatedFieldEncoding) String() string
String returns a human-readable name for the RepeatedFieldEncoding constant.
type ServiceDescriptor ¶
type ServiceDescriptor struct {
// contains filtered or unexported fields
}
ServiceDescriptor represents an immutable protobuf service descriptor. It holds metadata about a service definition, including the methods it declares. Access its properties through the ServiceDescriptorAccessor interface.
func (*ServiceDescriptor) FullName ¶
func (d *ServiceDescriptor) FullName() FullName
FullName returns the fully qualified dot-separated name of the service.
func (*ServiceDescriptor) Methods ¶
func (d *ServiceDescriptor) Methods() MethodDescriptors
Methods returns the method descriptors defined in this service.
func (*ServiceDescriptor) Name ¶
func (d *ServiceDescriptor) Name() string
Name returns the unqualified short name of the service.
func (*ServiceDescriptor) Options ¶
func (d *ServiceDescriptor) Options() []byte
Options returns a copy of the serialized service options as an opaque byte slice. Returns nil if no options are set.
func (*ServiceDescriptor) Parent ¶
func (d *ServiceDescriptor) Parent() FileDescriptorAccessor
Parent returns the file descriptor that contains this service.
func (*ServiceDescriptor) SetTypedOptionsResolved ¶
func (d *ServiceDescriptor) SetTypedOptionsResolved(opts any)
SetTypedOptionsResolved sets the typed options on the service descriptor after it has been built. This is used by the compilation pipeline to populate typed options from raw option bytes during resolution.
func (*ServiceDescriptor) TypedOptions ¶
func (d *ServiceDescriptor) TypedOptions() any
TypedOptions returns the parsed service options as a typed message, or nil if no typed options have been set.
type ServiceDescriptorAccessor ¶
type ServiceDescriptorAccessor interface {
DescriptorAccessor
// Parent returns the file descriptor that contains this service.
Parent() FileDescriptorAccessor
// Methods returns the method descriptors defined in this service.
Methods() MethodDescriptors
// Options returns the serialized service options as an opaque byte
// slice.
Options() []byte
// TypedOptions returns the parsed service options as a typed message,
// or nil if no typed options have been set. The returned value is
// typically a *dynamicpb.Message representing
// google.protobuf.ServiceOptions. Callers should type-assert to the
// expected concrete type.
TypedOptions() any
}
ServiceDescriptorAccessor is the read-only interface for accessing service descriptor properties. It embeds DescriptorAccessor for the common identity contract and adds methods specific to protobuf service descriptors.
ISP note: ServiceDescriptorAccessor has 6 methods (including embedded DescriptorAccessor). The methods form a single cohesive "service schema" concern. All consumers (codegen, grpcreflect, protodesc) use the full set when processing service declarations. Splitting would create fragments with no independent consumers. This is documented as an accepted exception to the 5-method guideline.
type ServiceDescriptorBuilder ¶
type ServiceDescriptorBuilder struct {
// contains filtered or unexported fields
}
ServiceDescriptorBuilder constructs an immutable ServiceDescriptor through a chainable setter API. Call Build to validate and produce the descriptor. Builders are reusable: calling Build multiple times produces independent descriptors.
func (*ServiceDescriptorBuilder) AddMethod ¶
func (b *ServiceDescriptorBuilder) AddMethod(m *MethodDescriptor) *ServiceDescriptorBuilder
AddMethod appends a method descriptor to the service.
func (*ServiceDescriptorBuilder) Build ¶
func (b *ServiceDescriptorBuilder) Build() (*ServiceDescriptor, error)
Build validates the builder state and returns an immutable ServiceDescriptor. It returns an error if the name or full name is empty.
func (*ServiceDescriptorBuilder) SetFullName ¶
func (b *ServiceDescriptorBuilder) SetFullName(fn FullName) *ServiceDescriptorBuilder
SetFullName sets the fully qualified dot-separated name of the service.
func (*ServiceDescriptorBuilder) SetName ¶
func (b *ServiceDescriptorBuilder) SetName(name string) *ServiceDescriptorBuilder
SetName sets the unqualified short name of the service.
func (*ServiceDescriptorBuilder) SetOptions ¶
func (b *ServiceDescriptorBuilder) SetOptions(opts []byte) *ServiceDescriptorBuilder
SetOptions sets the serialized service options as an opaque byte slice.
func (*ServiceDescriptorBuilder) SetParent ¶
func (b *ServiceDescriptorBuilder) SetParent(p FileDescriptorAccessor) *ServiceDescriptorBuilder
SetParent sets the file descriptor that contains this service.
func (*ServiceDescriptorBuilder) SetTypedOptions ¶
func (b *ServiceDescriptorBuilder) SetTypedOptions(opts any) *ServiceDescriptorBuilder
SetTypedOptions sets the parsed service options as a typed message. The value is typically a *dynamicpb.Message representing google.protobuf.ServiceOptions.
type ServiceDescriptors ¶
type ServiceDescriptors struct {
// contains filtered or unexported fields
}
ServiceDescriptors is a list of service descriptor pointers. It wraps an unexported slice to prevent caller mutation of the internal state.
func (ServiceDescriptors) ByName ¶
func (l ServiceDescriptors) ByName(name string) *ServiceDescriptor
ByName returns the service descriptor with the given unqualified name, or nil if no such descriptor is found. It performs a linear scan over the list.
func (ServiceDescriptors) Get ¶
func (l ServiceDescriptors) Get(i int) *ServiceDescriptor
Get returns the service descriptor at the given index. It panics if the index is out of range, matching Go slice semantics.
func (ServiceDescriptors) Len ¶
func (l ServiceDescriptors) Len() int
Len returns the number of service descriptors in the list.
type SourceCodeInfo ¶
type SourceCodeInfo struct {
// contains filtered or unexported fields
}
SourceCodeInfo holds the source code location information extracted from a .proto file during parsing. It maps declarations to their positions and associated comments. SourceCodeInfo is optional and does not affect serialization behavior.
func NewSourceCodeInfo ¶
func NewSourceCodeInfo(locations []Location) *SourceCodeInfo
NewSourceCodeInfo creates a SourceCodeInfo from the given location entries. The entries are defensively copied.
func (*SourceCodeInfo) Locations ¶
func (s *SourceCodeInfo) Locations() []Location
Locations returns a copy of the location entries. Mutating the returned slice does not affect the SourceCodeInfo.
type StripEnumPrefix ¶
type StripEnumPrefix int8
StripEnumPrefix controls whether generated Go enum constant names have the enum type name prefix stripped under Edition 2024 Go-specific features.
const ( StripEnumPrefixKeep StripEnumPrefix = 1 StripEnumPrefixGenerateBoth StripEnumPrefix = 2 StripEnumPrefixStrip StripEnumPrefix = 3 )
StripEnumPrefix constants matching the Go-specific edition feature values.
func (StripEnumPrefix) String ¶
func (sep StripEnumPrefix) String() string
String returns a human-readable name for the StripEnumPrefix constant.
type SymbolVisibility ¶
type SymbolVisibility int8
SymbolVisibility controls whether generated Go type names are exported or unexported under Edition 2024 semantics. It is a Go-specific edition feature.
const ( SymbolVisibilityExportAll SymbolVisibility = 1 SymbolVisibilityExportTopLevel SymbolVisibility = 2 SymbolVisibilityLocalAll SymbolVisibility = 3 SymbolVisibilityStrict SymbolVisibility = 4 )
SymbolVisibility constants matching the Go-specific edition feature values.
func (SymbolVisibility) String ¶
func (sv SymbolVisibility) String() string
String returns a human-readable name for the SymbolVisibility constant.
type Syntax ¶
type Syntax int8
Syntax represents the protobuf syntax version of a .proto file. It is a named type over int8 to provide type safety. The zero value is intentionally invalid.
const ( // Proto2 identifies the proto2 syntax. Proto2 Syntax = 1 // Proto3 identifies the proto3 syntax. Proto3 Syntax = 2 // Editions identifies the editions syntax. Editions Syntax = 3 )
Syntax constants for the three protobuf syntax versions. Values start at 1 so that the zero value of Syntax is invalid by design.
type Utf8Validation ¶
type Utf8Validation int8
Utf8Validation controls whether string fields are validated as UTF-8 under editions semantics.
const ( Utf8ValidationVerify Utf8Validation = 1 Utf8ValidationNone Utf8Validation = 2 )
Utf8Validation constants matching the official protobuf edition feature values.
func (Utf8Validation) String ¶
func (uv Utf8Validation) String() string
String returns a human-readable name for the Utf8Validation constant.