package filedesc
import (
)
type (
File struct {
fileRaw
L1 FileL1
once uint32
mu sync.Mutex
L2 *FileL2
}
FileL1 struct {
Syntax protoreflect.Syntax
Path string
Package protoreflect.FullName
Enums Enums
Messages Messages
Extensions Extensions
Services Services
}
FileL2 struct {
Options func() protoreflect.ProtoMessage
Imports FileImports
Locations SourceLocations
}
)
func ( *File) () protoreflect.FileDescriptor { return }
func ( *File) () protoreflect.Descriptor { return nil }
func ( *File) () int { return 0 }
func ( *File) () protoreflect.Syntax { return .L1.Syntax }
func ( *File) () protoreflect.Name { return .L1.Package.Name() }
func ( *File) () protoreflect.FullName { return .L1.Package }
func ( *File) () bool { return false }
func ( *File) () protoreflect.ProtoMessage {
if := .lazyInit().Options; != nil {
return ()
}
return descopts.File
}
func ( *File) () string { return .L1.Path }
func ( *File) () protoreflect.FullName { return .L1.Package }
func ( *File) () protoreflect.FileImports { return &.lazyInit().Imports }
func ( *File) () protoreflect.EnumDescriptors { return &.L1.Enums }
func ( *File) () protoreflect.MessageDescriptors { return &.L1.Messages }
func ( *File) () protoreflect.ExtensionDescriptors { return &.L1.Extensions }
func ( *File) () protoreflect.ServiceDescriptors { return &.L1.Services }
func ( *File) () protoreflect.SourceLocations { return &.lazyInit().Locations }
func ( *File) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *File) (protoreflect.FileDescriptor) {}
func ( *File) (pragma.DoNotImplement) {}
func ( *File) () *FileL2 {
if atomic.LoadUint32(&.once) == 0 {
.lazyInitOnce()
}
return .L2
}
func ( *File) () {
.mu.Lock()
if .L2 == nil {
.lazyRawInit()
}
atomic.StoreUint32(&.once, 1)
.mu.Unlock()
}
func ( *File) () string {
return .builder.GoPackagePath
}
type (
Enum struct {
Base
L1 EnumL1
L2 *EnumL2
}
EnumL1 struct {
eagerValues bool
}
EnumL2 struct {
Options func() protoreflect.ProtoMessage
Values EnumValues
ReservedNames Names
ReservedRanges EnumRanges
}
EnumValue struct {
Base
L1 EnumValueL1
}
EnumValueL1 struct {
Options func() protoreflect.ProtoMessage
Number protoreflect.EnumNumber
}
)
func ( *Enum) () protoreflect.ProtoMessage {
if := .lazyInit().Options; != nil {
return ()
}
return descopts.Enum
}
func ( *Enum) () protoreflect.EnumValueDescriptors {
if .L1.eagerValues {
return &.L2.Values
}
return &.lazyInit().Values
}
func ( *Enum) () protoreflect.Names { return &.lazyInit().ReservedNames }
func ( *Enum) () protoreflect.EnumRanges { return &.lazyInit().ReservedRanges }
func ( *Enum) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Enum) (protoreflect.EnumDescriptor) {}
func ( *Enum) () *EnumL2 {
.L0.ParentFile.lazyInit()
return .L2
}
func ( *EnumValue) () protoreflect.ProtoMessage {
if := .L1.Options; != nil {
return ()
}
return descopts.EnumValue
}
func ( *EnumValue) () protoreflect.EnumNumber { return .L1.Number }
func ( *EnumValue) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *EnumValue) (protoreflect.EnumValueDescriptor) {}
type (
Message struct {
Base
L1 MessageL1
L2 *MessageL2
}
MessageL1 struct {
Enums Enums
Messages Messages
Extensions Extensions
IsMapEntry bool
IsMessageSet bool
}
MessageL2 struct {
Options func() protoreflect.ProtoMessage
Fields Fields
Oneofs Oneofs
ReservedNames Names
ReservedRanges FieldRanges
RequiredNumbers FieldNumbers
ExtensionRanges FieldRanges
ExtensionRangeOptions []func() protoreflect.ProtoMessage
}
Field struct {
Base
L1 FieldL1
}
FieldL1 struct {
Options func() protoreflect.ProtoMessage
Number protoreflect.FieldNumber
Cardinality protoreflect.Cardinality
Kind protoreflect.Kind
StringName stringName
IsProto3Optional bool
IsWeak bool
HasPacked bool
IsPacked bool
HasEnforceUTF8 bool
EnforceUTF8 bool
Default defaultValue
ContainingOneof protoreflect.OneofDescriptor
Enum protoreflect.EnumDescriptor
Message protoreflect.MessageDescriptor
}
Oneof struct {
Base
L1 OneofL1
}
OneofL1 struct {
Options func() protoreflect.ProtoMessage
Fields OneofFields
}
)
func ( *Message) () protoreflect.ProtoMessage {
if := .lazyInit().Options; != nil {
return ()
}
return descopts.Message
}
func ( *Message) () bool { return .L1.IsMapEntry }
func ( *Message) () protoreflect.FieldDescriptors { return &.lazyInit().Fields }
func ( *Message) () protoreflect.OneofDescriptors { return &.lazyInit().Oneofs }
func ( *Message) () protoreflect.Names { return &.lazyInit().ReservedNames }
func ( *Message) () protoreflect.FieldRanges { return &.lazyInit().ReservedRanges }
func ( *Message) () protoreflect.FieldNumbers { return &.lazyInit().RequiredNumbers }
func ( *Message) () protoreflect.FieldRanges { return &.lazyInit().ExtensionRanges }
func ( *Message) ( int) protoreflect.ProtoMessage {
if := .lazyInit().ExtensionRangeOptions[]; != nil {
return ()
}
return descopts.ExtensionRange
}
func ( *Message) () protoreflect.EnumDescriptors { return &.L1.Enums }
func ( *Message) () protoreflect.MessageDescriptors { return &.L1.Messages }
func ( *Message) () protoreflect.ExtensionDescriptors { return &.L1.Extensions }
func ( *Message) (protoreflect.MessageDescriptor) {}
func ( *Message) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Message) () *MessageL2 {
.L0.ParentFile.lazyInit()
return .L2
}
func ( *Message) () bool {
return .L1.IsMessageSet
}
func ( *Field) () protoreflect.ProtoMessage {
if := .L1.Options; != nil {
return ()
}
return descopts.Field
}
func ( *Field) () protoreflect.FieldNumber { return .L1.Number }
func ( *Field) () protoreflect.Cardinality { return .L1.Cardinality }
func ( *Field) () protoreflect.Kind { return .L1.Kind }
func ( *Field) () bool { return .L1.StringName.hasJSON }
func ( *Field) () string { return .L1.StringName.getJSON() }
func ( *Field) () string { return .L1.StringName.getText() }
func ( *Field) () bool {
return .L1.Cardinality != protoreflect.Repeated && (.L0.ParentFile.L1.Syntax == protoreflect.Proto2 || .L1.Message != nil || .L1.ContainingOneof != nil)
}
func ( *Field) () bool {
return (.L0.ParentFile.L1.Syntax == protoreflect.Proto2 && .L1.Cardinality == protoreflect.Optional && .L1.ContainingOneof == nil) || .L1.IsProto3Optional
}
func ( *Field) () bool {
if !.L1.HasPacked && .L0.ParentFile.L1.Syntax != protoreflect.Proto2 && .L1.Cardinality == protoreflect.Repeated {
switch .L1.Kind {
case protoreflect.StringKind, protoreflect.BytesKind, protoreflect.MessageKind, protoreflect.GroupKind:
default:
return true
}
}
return .L1.IsPacked
}
func ( *Field) () bool { return false }
func ( *Field) () bool { return .L1.IsWeak }
func ( *Field) () bool { return .Cardinality() == protoreflect.Repeated && !.IsMap() }
func ( *Field) () bool { return .Message() != nil && .Message().IsMapEntry() }
func ( *Field) () protoreflect.FieldDescriptor {
if !.IsMap() {
return nil
}
return .Message().Fields().ByNumber(genid.MapEntry_Key_field_number)
}
func ( *Field) () protoreflect.FieldDescriptor {
if !.IsMap() {
return nil
}
return .Message().Fields().ByNumber(genid.MapEntry_Value_field_number)
}
func ( *Field) () bool { return .L1.Default.has }
func ( *Field) () protoreflect.Value { return .L1.Default.get() }
func ( *Field) () protoreflect.EnumValueDescriptor { return .L1.Default.enum }
func ( *Field) () protoreflect.OneofDescriptor { return .L1.ContainingOneof }
func ( *Field) () protoreflect.MessageDescriptor {
return .L0.Parent.(protoreflect.MessageDescriptor)
}
func ( *Field) () protoreflect.EnumDescriptor {
return .L1.Enum
}
func ( *Field) () protoreflect.MessageDescriptor {
if .L1.IsWeak {
if , := protoregistry.GlobalFiles.FindDescriptorByName(.L1.Message.FullName()); != nil {
return .(protoreflect.MessageDescriptor)
}
}
return .L1.Message
}
func ( *Field) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Field) (protoreflect.FieldDescriptor) {}
func ( *Field) () bool {
if .L1.HasEnforceUTF8 {
return .L1.EnforceUTF8
}
return .L0.ParentFile.L1.Syntax == protoreflect.Proto3
}
func ( *Oneof) () bool {
return .L0.ParentFile.L1.Syntax == protoreflect.Proto3 && len(.L1.Fields.List) == 1 && .L1.Fields.List[0].HasOptionalKeyword()
}
func ( *Oneof) () protoreflect.ProtoMessage {
if := .L1.Options; != nil {
return ()
}
return descopts.Oneof
}
func ( *Oneof) () protoreflect.FieldDescriptors { return &.L1.Fields }
func ( *Oneof) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Oneof) (protoreflect.OneofDescriptor) {}
type (
Extension struct {
Base
L1 ExtensionL1
L2 *ExtensionL2
}
ExtensionL1 struct {
Number protoreflect.FieldNumber
Extendee protoreflect.MessageDescriptor
Cardinality protoreflect.Cardinality
Kind protoreflect.Kind
}
ExtensionL2 struct {
Options func() protoreflect.ProtoMessage
StringName stringName
IsProto3Optional bool
IsPacked bool
Default defaultValue
Enum protoreflect.EnumDescriptor
Message protoreflect.MessageDescriptor
}
)
func ( *Extension) () protoreflect.ProtoMessage {
if := .lazyInit().Options; != nil {
return ()
}
return descopts.Field
}
func ( *Extension) () protoreflect.FieldNumber { return .L1.Number }
func ( *Extension) () protoreflect.Cardinality { return .L1.Cardinality }
func ( *Extension) () protoreflect.Kind { return .L1.Kind }
func ( *Extension) () bool { return .lazyInit().StringName.hasJSON }
func ( *Extension) () string { return .lazyInit().StringName.getJSON() }
func ( *Extension) () string { return .lazyInit().StringName.getText() }
func ( *Extension) () bool { return .L1.Cardinality != protoreflect.Repeated }
func ( *Extension) () bool {
return (.L0.ParentFile.L1.Syntax == protoreflect.Proto2 && .L1.Cardinality == protoreflect.Optional) || .lazyInit().IsProto3Optional
}
func ( *Extension) () bool { return .lazyInit().IsPacked }
func ( *Extension) () bool { return true }
func ( *Extension) () bool { return false }
func ( *Extension) () bool { return .Cardinality() == protoreflect.Repeated }
func ( *Extension) () bool { return false }
func ( *Extension) () protoreflect.FieldDescriptor { return nil }
func ( *Extension) () protoreflect.FieldDescriptor { return nil }
func ( *Extension) () bool { return .lazyInit().Default.has }
func ( *Extension) () protoreflect.Value { return .lazyInit().Default.get() }
func ( *Extension) () protoreflect.EnumValueDescriptor {
return .lazyInit().Default.enum
}
func ( *Extension) () protoreflect.OneofDescriptor { return nil }
func ( *Extension) () protoreflect.MessageDescriptor { return .L1.Extendee }
func ( *Extension) () protoreflect.EnumDescriptor { return .lazyInit().Enum }
func ( *Extension) () protoreflect.MessageDescriptor { return .lazyInit().Message }
func ( *Extension) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Extension) (protoreflect.FieldDescriptor) {}
func ( *Extension) (pragma.DoNotImplement) {}
func ( *Extension) () *ExtensionL2 {
.L0.ParentFile.lazyInit()
return .L2
}
type (
Service struct {
Base
L1 ServiceL1
L2 *ServiceL2
}
ServiceL1 struct{}
ServiceL2 struct {
Options func() protoreflect.ProtoMessage
Methods Methods
}
Method struct {
Base
L1 MethodL1
}
MethodL1 struct {
Options func() protoreflect.ProtoMessage
Input protoreflect.MessageDescriptor
Output protoreflect.MessageDescriptor
IsStreamingClient bool
IsStreamingServer bool
}
)
func ( *Service) () protoreflect.ProtoMessage {
if := .lazyInit().Options; != nil {
return ()
}
return descopts.Service
}
func ( *Service) () protoreflect.MethodDescriptors { return &.lazyInit().Methods }
func ( *Service) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Service) (protoreflect.ServiceDescriptor) {}
func ( *Service) (pragma.DoNotImplement) {}
func ( *Service) () *ServiceL2 {
.L0.ParentFile.lazyInit()
return .L2
}
func ( *Method) () protoreflect.ProtoMessage {
if := .L1.Options; != nil {
return ()
}
return descopts.Method
}
func ( *Method) () protoreflect.MessageDescriptor { return .L1.Input }
func ( *Method) () protoreflect.MessageDescriptor { return .L1.Output }
func ( *Method) () bool { return .L1.IsStreamingClient }
func ( *Method) () bool { return .L1.IsStreamingServer }
func ( *Method) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Method) (protoreflect.MethodDescriptor) {}
func ( *Method) (pragma.DoNotImplement) {}
var (
SurrogateProto2 = &File{L1: FileL1{Syntax: protoreflect.Proto2}, L2: &FileL2{}}
SurrogateProto3 = &File{L1: FileL1{Syntax: protoreflect.Proto3}, L2: &FileL2{}}
)
type (
Base struct {
L0 BaseL0
}
BaseL0 struct {
FullName protoreflect.FullName
ParentFile *File
Parent protoreflect.Descriptor
Index int
}
)
func ( *Base) () protoreflect.Name { return .L0.FullName.Name() }
func ( *Base) () protoreflect.FullName { return .L0.FullName }
func ( *Base) () protoreflect.FileDescriptor {
if .L0.ParentFile == SurrogateProto2 || .L0.ParentFile == SurrogateProto3 {
return nil
}
return .L0.ParentFile
}
func ( *Base) () protoreflect.Descriptor { return .L0.Parent }
func ( *Base) () int { return .L0.Index }
func ( *Base) () protoreflect.Syntax { return .L0.ParentFile.Syntax() }
func ( *Base) () bool { return false }
func ( *Base) (pragma.DoNotImplement) {}
type stringName struct {
hasJSON bool
once sync.Once
nameJSON string
nameText string
}
func ( *stringName) ( string) {
.hasJSON = true
.nameJSON =
}
func ( *stringName) ( protoreflect.FieldDescriptor) *stringName {
.once.Do(func() {
if .IsExtension() {
var string
if messageset.IsMessageSetExtension() {
= string("[" + .FullName().Parent() + "]")
} else {
= string("[" + .FullName() + "]")
}
.nameJSON =
.nameText =
} else {
if !.hasJSON {
.nameJSON = strs.JSONCamelCase(string(.Name()))
}
.nameText = string(.Name())
if .Kind() == protoreflect.GroupKind {
.nameText = string(.Message().Name())
}
}
})
return
}
func ( *stringName) ( protoreflect.FieldDescriptor) string { return .lazyInit().nameJSON }
func ( *stringName) ( protoreflect.FieldDescriptor) string { return .lazyInit().nameText }
func ( protoreflect.Value, protoreflect.EnumValueDescriptor) defaultValue {
:= defaultValue{has: .IsValid(), val: , enum: }
if , := .Interface().([]byte); {
.bytes = append([]byte(nil), ...)
}
return
}
func ( []byte, protoreflect.Kind, *File, protoreflect.EnumDescriptor) defaultValue {
var protoreflect.EnumValueDescriptors
if == protoreflect.EnumKind {
if , := .(*Enum); && .L0.ParentFile == {
= &.L2.Values
} else {
= .Values()
}
if .IsPlaceholder() && protoreflect.Name().IsValid() {
:= protoreflect.ValueOfEnum(0)
:= PlaceholderEnumValue(.FullName().Parent().Append(protoreflect.Name()))
return DefaultValue(, )
}
}
, , := defval.Unmarshal(string(), , , defval.Descriptor)
if != nil {
panic()
}
return DefaultValue(, )
}
type defaultValue struct {
has bool
val protoreflect.Value
enum protoreflect.EnumValueDescriptor
bytes []byte
}
func ( *defaultValue) ( protoreflect.FieldDescriptor) protoreflect.Value {
if !.has {
if .Cardinality() == protoreflect.Repeated {
return protoreflect.Value{}
}
switch .Kind() {
case protoreflect.BoolKind:
return protoreflect.ValueOfBool(false)
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind:
return protoreflect.ValueOfInt32(0)
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind:
return protoreflect.ValueOfInt64(0)
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind:
return protoreflect.ValueOfUint32(0)
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind:
return protoreflect.ValueOfUint64(0)
case protoreflect.FloatKind:
return protoreflect.ValueOfFloat32(0)
case protoreflect.DoubleKind:
return protoreflect.ValueOfFloat64(0)
case protoreflect.StringKind:
return protoreflect.ValueOfString("")
case protoreflect.BytesKind:
return protoreflect.ValueOfBytes(nil)
case protoreflect.EnumKind:
if := .Enum().Values(); .Len() > 0 {
return protoreflect.ValueOfEnum(.Get(0).Number())
}
return protoreflect.ValueOfEnum(0)
}
}
if len(.bytes) > 0 && !bytes.Equal(.bytes, .val.Bytes()) {
panic(fmt.Sprintf("detected mutation on the default bytes for %v", .FullName()))
}
return .val
}