descriptor

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 4 Imported by: 0

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

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

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

AddValue appends an enum value descriptor to the enum.

func (*EnumDescriptorBuilder) Build

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

SetFullName sets the fully qualified dot-separated name of the enum.

func (*EnumDescriptorBuilder) SetIsClosed

SetIsClosed sets whether this is a closed enum.

func (*EnumDescriptorBuilder) SetName

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

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

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.

const (
	EnumTypeOpen   EnumType = 1
	EnumTypeClosed EnumType = 2
)

EnumType constants matching the official protobuf edition feature values.

func (EnumType) String

func (et EnumType) String() string

String returns a human-readable name for the EnumType constant.

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

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

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

SetFullName sets the fully qualified dot-separated name of the enum value.

func (*EnumValueDescriptorBuilder) SetJSONName

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

SetName sets the unqualified short name of the enum value.

func (*EnumValueDescriptorBuilder) SetNumber

SetNumber sets the integer value of this enum value. Any int32 value is valid per protobuf spec, including negative numbers.

func (*EnumValueDescriptorBuilder) SetOptions

SetOptions sets the serialized enum value options as an opaque byte slice.

func (*EnumValueDescriptorBuilder) SetParent

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

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

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

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

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

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

SetCardinality sets the field cardinality (optional, required, or repeated).

func (*FieldDescriptorBuilder) SetContainingMessage

SetContainingMessage sets the message descriptor that contains this field.

func (*FieldDescriptorBuilder) SetContainingOneof

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

SetEnumType sets the enum descriptor for enum-typed fields.

func (*FieldDescriptorBuilder) SetFullName

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

SetIsList sets whether the field is a list (repeated non-map) field.

func (*FieldDescriptorBuilder) SetIsMap

SetIsMap sets whether the field is a map field.

func (*FieldDescriptorBuilder) SetIsPacked

SetIsPacked sets whether the field uses packed encoding.

func (*FieldDescriptorBuilder) SetJSONName

SetJSONName sets the JSON field name.

func (*FieldDescriptorBuilder) SetKind

SetKind sets the scalar kind of the field.

func (*FieldDescriptorBuilder) SetMessageType

SetMessageType sets the message descriptor for message-typed fields.

func (*FieldDescriptorBuilder) SetName

SetName sets the unqualified short name of the field.

func (*FieldDescriptorBuilder) SetNumber

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

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

AddDependency appends a file descriptor to the list of direct imports.

func (*FileDescriptorBuilder) AddEnum

AddEnum appends a top-level enum descriptor to the file.

func (*FileDescriptorBuilder) AddExtension

AddExtension appends a top-level extension field descriptor to the file.

func (*FileDescriptorBuilder) AddMessage

AddMessage appends a top-level message descriptor to the file.

func (*FileDescriptorBuilder) AddService

AddService appends a service descriptor to the file.

func (*FileDescriptorBuilder) Build

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

SetFeatures sets the file-level EditionFeatures.

func (*FileDescriptorBuilder) SetName

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

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

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

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.

func (FullName) Name

func (fn FullName) Name() string

Name returns the unqualified trailing component of the full name. For a dotted name like "pkg.Msg.field" it returns "field". For a single-component name like "field" it returns "field". For an empty string it returns "".

func (FullName) Parent

func (fn FullName) Parent() FullName

Parent returns everything before the last dot as a FullName. For a dotted name like "pkg.Msg.field" it returns "pkg.Msg". For a single-component name or an empty string it returns "".

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.

const (
	GoAPIModeOpen   GoAPIMode = 1
	GoAPIModeOpaque GoAPIMode = 2
)

GoAPIMode constants matching the Go-specific edition feature values.

func (GoAPIMode) String

func (m GoAPIMode) String() string

String returns a human-readable name for the GoAPIMode constant.

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

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

AddField appends a field descriptor to the message.

func (*MessageDescriptorBuilder) AddNestedEnum

AddNestedEnum appends a nested enum descriptor to the message.

func (*MessageDescriptorBuilder) AddNestedMessage

AddNestedMessage appends a nested message descriptor to the message.

func (*MessageDescriptorBuilder) AddOneof

AddOneof appends a oneof descriptor to the message.

func (*MessageDescriptorBuilder) Build

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

SetFullName sets the fully qualified dot-separated name of the message.

func (*MessageDescriptorBuilder) SetIsMapEntry

SetIsMapEntry sets whether the message is a synthetic map entry type.

func (*MessageDescriptorBuilder) SetName

SetName sets the unqualified short name of the message.

func (*MessageDescriptorBuilder) SetOptions

SetOptions sets the serialized message options as an opaque byte slice.

func (*MessageDescriptorBuilder) SetParent

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

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

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

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

OutputType returns the message descriptor for the method's output type.

func (*MethodDescriptor) Parent

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

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

SetFullName sets the fully qualified dot-separated name of the method.

func (*MethodDescriptorBuilder) SetInputType

SetInputType sets the message descriptor for the method's input type.

func (*MethodDescriptorBuilder) SetName

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

SetOutputType sets the message descriptor for the method's output type.

func (*MethodDescriptorBuilder) SetParent

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

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

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

AddField appends a field descriptor to the oneof.

func (*OneofDescriptorBuilder) Build

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

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

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

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

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

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

AddMethod appends a method descriptor to the service.

func (*ServiceDescriptorBuilder) Build

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

SetFullName sets the fully qualified dot-separated name of the service.

func (*ServiceDescriptorBuilder) SetName

SetName sets the unqualified short name of the service.

func (*ServiceDescriptorBuilder) SetOptions

SetOptions sets the serialized service options as an opaque byte slice.

func (*ServiceDescriptorBuilder) SetParent

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

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

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.

func (Syntax) String

func (s Syntax) String() string

String returns the lowercase protobuf name of the syntax version. For the three valid values (1-3) it returns names such as "proto2" and "editions". For out-of-range values it returns a formatted string like "Syntax(4)".

func (Syntax) Valid

func (s Syntax) Valid() bool

Valid reports whether s is one of the three defined protobuf syntax versions (1 through 3 inclusive).

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL