Source File
desc.go
Belonging Package
google.golang.org/protobuf/internal/filedesc
package filedesc
import (
pref
)
type (
File struct {
fileRaw
L1 FileL1
once uint32 // atomically set if L2 is valid
mu sync.Mutex // protects L2
L2 *FileL2
}
FileL1 struct {
Syntax pref.Syntax
Path string
Package pref.FullName
Enums Enums
Messages Messages
Extensions Extensions
Services Services
}
FileL2 struct {
Options func() pref.ProtoMessage
Imports FileImports
Locations SourceLocations
}
)
func ( *File) () pref.FileDescriptor { return }
func ( *File) () pref.Descriptor { return nil }
func ( *File) () int { return 0 }
func ( *File) () pref.Syntax { return .L1.Syntax }
func ( *File) () pref.Name { return .L1.Package.Name() }
func ( *File) () pref.FullName { return .L1.Package }
func ( *File) () bool { return false }
func ( *File) () pref.ProtoMessage {
if := .lazyInit().Options; != nil {
return ()
}
return descopts.File
}
func ( *File) () string { return .L1.Path }
func ( *File) () pref.FullName { return .L1.Package }
func ( *File) () pref.FileImports { return &.lazyInit().Imports }
func ( *File) () pref.EnumDescriptors { return &.L1.Enums }
func ( *File) () pref.MessageDescriptors { return &.L1.Messages }
func ( *File) () pref.ExtensionDescriptors { return &.L1.Extensions }
func ( *File) () pref.ServiceDescriptors { return &.L1.Services }
func ( *File) () pref.SourceLocations { return &.lazyInit().Locations }
func ( *File) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *File) (pref.FileDescriptor) {}
func ( *File) (pragma.DoNotImplement) {}
func ( *File) () *FileL2 {
if atomic.LoadUint32(&.once) == 0 {
.lazyInitOnce()
}
return .L2
}
func ( *File) () {
.mu.Lock()
if .L2 == nil {
.lazyRawInit() // recursively initializes all L2 structures
}
atomic.StoreUint32(&.once, 1)
.mu.Unlock()
}
func ( *File) () []byte {
return .builder.RawDescriptor
}
func ( *File) () string {
return .builder.GoPackagePath
}
type (
Enum struct {
Base
L1 EnumL1
L2 *EnumL2 // protected by fileDesc.once
}
EnumL1 struct {
eagerValues bool // controls whether EnumL2.Values is already populated
}
EnumL2 struct {
Options func() pref.ProtoMessage
Values EnumValues
ReservedNames Names
ReservedRanges EnumRanges
}
EnumValue struct {
Base
L1 EnumValueL1
}
EnumValueL1 struct {
Options func() pref.ProtoMessage
Number pref.EnumNumber
}
)
func ( *Enum) () pref.ProtoMessage {
if := .lazyInit().Options; != nil {
return ()
}
return descopts.Enum
}
func ( *Enum) () pref.EnumValueDescriptors {
if .L1.eagerValues {
return &.L2.Values
}
return &.lazyInit().Values
}
func ( *Enum) () pref.Names { return &.lazyInit().ReservedNames }
func ( *Enum) () pref.EnumRanges { return &.lazyInit().ReservedRanges }
func ( *Enum) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Enum) (pref.EnumDescriptor) {}
func ( *Enum) () *EnumL2 {
.L0.ParentFile.lazyInit() // implicitly initializes L2
return .L2
}
func ( *EnumValue) () pref.ProtoMessage {
if := .L1.Options; != nil {
return ()
}
return descopts.EnumValue
}
func ( *EnumValue) () pref.EnumNumber { return .L1.Number }
func ( *EnumValue) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *EnumValue) (pref.EnumValueDescriptor) {}
type (
Message struct {
Base
L1 MessageL1
L2 *MessageL2 // protected by fileDesc.once
}
MessageL1 struct {
Enums Enums
Messages Messages
Extensions Extensions
IsMapEntry bool // promoted from google.protobuf.MessageOptions
IsMessageSet bool // promoted from google.protobuf.MessageOptions
}
MessageL2 struct {
Options func() pref.ProtoMessage
Fields Fields
Oneofs Oneofs
ReservedNames Names
ReservedRanges FieldRanges
RequiredNumbers FieldNumbers // must be consistent with Fields.Cardinality
ExtensionRanges FieldRanges
ExtensionRangeOptions []func() pref.ProtoMessage // must be same length as ExtensionRanges
}
Field struct {
Base
L1 FieldL1
}
FieldL1 struct {
Options func() pref.ProtoMessage
Number pref.FieldNumber
Cardinality pref.Cardinality // must be consistent with Message.RequiredNumbers
Kind pref.Kind
JSONName jsonName
IsProto3Optional bool // promoted from google.protobuf.FieldDescriptorProto
IsWeak bool // promoted from google.protobuf.FieldOptions
HasPacked bool // promoted from google.protobuf.FieldOptions
IsPacked bool // promoted from google.protobuf.FieldOptions
HasEnforceUTF8 bool // promoted from google.protobuf.FieldOptions
EnforceUTF8 bool // promoted from google.protobuf.FieldOptions
Default defaultValue
ContainingOneof pref.OneofDescriptor // must be consistent with Message.Oneofs.Fields
Enum pref.EnumDescriptor
Message pref.MessageDescriptor
}
Oneof struct {
Base
L1 OneofL1
}
OneofL1 struct {
Options func() pref.ProtoMessage
Fields OneofFields // must be consistent with Message.Fields.ContainingOneof
}
)
func ( *Message) () pref.ProtoMessage {
if := .lazyInit().Options; != nil {
return ()
}
return descopts.Message
}
func ( *Message) () bool { return .L1.IsMapEntry }
func ( *Message) () pref.FieldDescriptors { return &.lazyInit().Fields }
func ( *Message) () pref.OneofDescriptors { return &.lazyInit().Oneofs }
func ( *Message) () pref.Names { return &.lazyInit().ReservedNames }
func ( *Message) () pref.FieldRanges { return &.lazyInit().ReservedRanges }
func ( *Message) () pref.FieldNumbers { return &.lazyInit().RequiredNumbers }
func ( *Message) () pref.FieldRanges { return &.lazyInit().ExtensionRanges }
func ( *Message) ( int) pref.ProtoMessage {
if := .lazyInit().ExtensionRangeOptions[]; != nil {
return ()
}
return descopts.ExtensionRange
}
func ( *Message) () pref.EnumDescriptors { return &.L1.Enums }
func ( *Message) () pref.MessageDescriptors { return &.L1.Messages }
func ( *Message) () pref.ExtensionDescriptors { return &.L1.Extensions }
func ( *Message) (pref.MessageDescriptor) {}
func ( *Message) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Message) () *MessageL2 {
.L0.ParentFile.lazyInit() // implicitly initializes L2
return .L2
}
func ( *Message) () bool {
return .L1.IsMessageSet
}
func ( *Field) () pref.ProtoMessage {
if := .L1.Options; != nil {
return ()
}
return descopts.Field
}
func ( *Field) () pref.FieldNumber { return .L1.Number }
func ( *Field) () pref.Cardinality { return .L1.Cardinality }
func ( *Field) () pref.Kind { return .L1.Kind }
func ( *Field) () bool { return .L1.JSONName.has }
func ( *Field) () string { return .L1.JSONName.get() }
func ( *Field) () bool {
return .L1.Cardinality != pref.Repeated && (.L0.ParentFile.L1.Syntax == pref.Proto2 || .L1.Message != nil || .L1.ContainingOneof != nil)
}
func ( *Field) () bool {
return (.L0.ParentFile.L1.Syntax == pref.Proto2 && .L1.Cardinality == pref.Optional && .L1.ContainingOneof == nil) || .L1.IsProto3Optional
}
func ( *Field) () bool {
if !.L1.HasPacked && .L0.ParentFile.L1.Syntax != pref.Proto2 && .L1.Cardinality == pref.Repeated {
switch .L1.Kind {
case pref.StringKind, pref.BytesKind, pref.MessageKind, pref.GroupKind:
default:
return true
}
}
return .L1.IsPacked
}
func ( *Field) () bool { return false }
func ( *Field) () bool { return .L1.IsWeak }
func ( *Field) () bool { return .Cardinality() == pref.Repeated && !.IsMap() }
func ( *Field) () bool { return .Message() != nil && .Message().IsMapEntry() }
func ( *Field) () pref.FieldDescriptor {
if !.IsMap() {
return nil
}
return .Message().Fields().ByNumber(genid.MapEntry_Key_field_number)
}
func ( *Field) () pref.FieldDescriptor {
if !.IsMap() {
return nil
}
return .Message().Fields().ByNumber(genid.MapEntry_Value_field_number)
}
func ( *Field) () bool { return .L1.Default.has }
func ( *Field) () pref.Value { return .L1.Default.get() }
func ( *Field) () pref.EnumValueDescriptor { return .L1.Default.enum }
func ( *Field) () pref.OneofDescriptor { return .L1.ContainingOneof }
func ( *Field) () pref.MessageDescriptor {
return .L0.Parent.(pref.MessageDescriptor)
}
func ( *Field) () pref.EnumDescriptor {
return .L1.Enum
}
func ( *Field) () pref.MessageDescriptor {
if .L1.IsWeak {
if , := protoregistry.GlobalFiles.FindDescriptorByName(.L1.Message.FullName()); != nil {
return .(pref.MessageDescriptor)
}
}
return .L1.Message
}
func ( *Field) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Field) (pref.FieldDescriptor) {}
func ( *Field) () bool {
if .L1.HasEnforceUTF8 {
return .L1.EnforceUTF8
}
return .L0.ParentFile.L1.Syntax == pref.Proto3
}
func ( *Oneof) () bool {
return .L0.ParentFile.L1.Syntax == pref.Proto3 && len(.L1.Fields.List) == 1 && .L1.Fields.List[0].HasOptionalKeyword()
}
func ( *Oneof) () pref.ProtoMessage {
if := .L1.Options; != nil {
return ()
}
return descopts.Oneof
}
func ( *Oneof) () pref.FieldDescriptors { return &.L1.Fields }
func ( *Oneof) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Oneof) (pref.OneofDescriptor) {}
type (
Extension struct {
Base
L1 ExtensionL1
L2 *ExtensionL2 // protected by fileDesc.once
}
ExtensionL1 struct {
Number pref.FieldNumber
Extendee pref.MessageDescriptor
Cardinality pref.Cardinality
Kind pref.Kind
}
ExtensionL2 struct {
Options func() pref.ProtoMessage
JSONName jsonName
IsProto3Optional bool // promoted from google.protobuf.FieldDescriptorProto
IsPacked bool // promoted from google.protobuf.FieldOptions
Default defaultValue
Enum pref.EnumDescriptor
Message pref.MessageDescriptor
}
)
func ( *Extension) () pref.ProtoMessage {
if := .lazyInit().Options; != nil {
return ()
}
return descopts.Field
}
func ( *Extension) () pref.FieldNumber { return .L1.Number }
func ( *Extension) () pref.Cardinality { return .L1.Cardinality }
func ( *Extension) () pref.Kind { return .L1.Kind }
func ( *Extension) () bool { return .lazyInit().JSONName.has }
func ( *Extension) () string { return .lazyInit().JSONName.get() }
func ( *Extension) () bool { return .L1.Cardinality != pref.Repeated }
func ( *Extension) () bool {
return (.L0.ParentFile.L1.Syntax == pref.Proto2 && .L1.Cardinality == pref.Optional) || .lazyInit().IsProto3Optional
}
func ( *Extension) () bool { return .lazyInit().IsPacked }
func ( *Extension) () bool { return true }
func ( *Extension) () bool { return false }
func ( *Extension) () bool { return .Cardinality() == pref.Repeated }
func ( *Extension) () bool { return false }
func ( *Extension) () pref.FieldDescriptor { return nil }
func ( *Extension) () pref.FieldDescriptor { return nil }
func ( *Extension) () bool { return .lazyInit().Default.has }
func ( *Extension) () pref.Value { return .lazyInit().Default.get() }
func ( *Extension) () pref.EnumValueDescriptor { return .lazyInit().Default.enum }
func ( *Extension) () pref.OneofDescriptor { return nil }
func ( *Extension) () pref.MessageDescriptor { return .L1.Extendee }
func ( *Extension) () pref.EnumDescriptor { return .lazyInit().Enum }
func ( *Extension) () pref.MessageDescriptor { return .lazyInit().Message }
func ( *Extension) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Extension) (pref.FieldDescriptor) {}
func ( *Extension) (pragma.DoNotImplement) {}
func ( *Extension) () *ExtensionL2 {
.L0.ParentFile.lazyInit() // implicitly initializes L2
return .L2
}
type (
Service struct {
Base
L1 ServiceL1
L2 *ServiceL2 // protected by fileDesc.once
}
ServiceL1 struct{}
ServiceL2 struct {
Options func() pref.ProtoMessage
Methods Methods
}
Method struct {
Base
L1 MethodL1
}
MethodL1 struct {
Options func() pref.ProtoMessage
Input pref.MessageDescriptor
Output pref.MessageDescriptor
IsStreamingClient bool
IsStreamingServer bool
}
)
func ( *Service) () pref.ProtoMessage {
if := .lazyInit().Options; != nil {
return ()
}
return descopts.Service
}
func ( *Service) () pref.MethodDescriptors { return &.lazyInit().Methods }
func ( *Service) ( fmt.State, rune) { descfmt.FormatDesc(, , ) }
func ( *Service) (pref.ServiceDescriptor) {}
func ( *Service) (pragma.DoNotImplement) {}
func ( *Service) () *ServiceL2 {
.L0.ParentFile.lazyInit() // implicitly initializes L2
return .L2
}
func ( *Method) () pref.ProtoMessage {
if := .L1.Options; != nil {
return ()
}
return descopts.Method
}
func ( *Method) () pref.MessageDescriptor { return .L1.Input }
func ( *Method) () pref.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) (pref.MethodDescriptor) {}
func ( *Method) (pragma.DoNotImplement) {}
var (
SurrogateProto2 = &File{L1: FileL1{Syntax: pref.Proto2}, L2: &FileL2{}}
SurrogateProto3 = &File{L1: FileL1{Syntax: pref.Proto3}, L2: &FileL2{}}
)
type (
Base struct {
L0 BaseL0
}
BaseL0 struct {
FullName pref.FullName // must be populated
ParentFile *File // must be populated
Parent pref.Descriptor
Index int
}
)
func ( *Base) () pref.Name { return .L0.FullName.Name() }
func ( *Base) () pref.FullName { return .L0.FullName }
func ( *Base) () pref.FileDescriptor {
if .L0.ParentFile == SurrogateProto2 || .L0.ParentFile == SurrogateProto3 {
return nil // surrogate files are not real parents
}
return .L0.ParentFile
}
func ( *Base) () pref.Descriptor { return .L0.Parent }
func ( *Base) () int { return .L0.Index }
func ( *Base) () pref.Syntax { return .L0.ParentFile.Syntax() }
func ( *Base) () bool { return false }
func ( *Base) (pragma.DoNotImplement) {}
type jsonName struct {
has bool
once sync.Once
name string
}
func ( *jsonName) ( string) {
.has = true
.name =
}
func ( *jsonName) ( pref.FieldDescriptor) string {
if !.has {
.once.Do(func() {
.name = strs.JSONCamelCase(string(.Name()))
})
}
return .name
}
func ( pref.Value, pref.EnumValueDescriptor) defaultValue {
:= defaultValue{has: .IsValid(), val: , enum: }
.bytes = append([]byte(nil), ...)
}
return
}
func ( []byte, pref.Kind, *File, pref.EnumDescriptor) defaultValue {
var pref.EnumValueDescriptors
if .IsPlaceholder() && pref.Name().IsValid() {
:= pref.ValueOfEnum(0)
:= PlaceholderEnumValue(.FullName().Parent().Append(pref.Name()))
return DefaultValue(, )
}
}
, , := defval.Unmarshal(string(), , , defval.Descriptor)
if != nil {
panic()
}
return DefaultValue(, )
}
type defaultValue struct {
has bool
val pref.Value
enum pref.EnumValueDescriptor
bytes []byte
}
if !.has {
if .Cardinality() == pref.Repeated {
return pref.Value{}
}
switch .Kind() {
case pref.BoolKind:
return pref.ValueOfBool(false)
case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind:
return pref.ValueOfInt32(0)
case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind:
return pref.ValueOfInt64(0)
case pref.Uint32Kind, pref.Fixed32Kind:
return pref.ValueOfUint32(0)
case pref.Uint64Kind, pref.Fixed64Kind:
return pref.ValueOfUint64(0)
case pref.FloatKind:
return pref.ValueOfFloat32(0)
case pref.DoubleKind:
return pref.ValueOfFloat64(0)
case pref.StringKind:
return pref.ValueOfString("")
case pref.BytesKind:
return pref.ValueOfBytes(nil)
case pref.EnumKind:
if := .Enum().Values(); .Len() > 0 {
return pref.ValueOfEnum(.Get(0).Number())
}
return pref.ValueOfEnum(0)
}
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |