// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package filedesc

import (
	
	
	
	

	
	
	
	
	
	
	
	
	
)

// The types in this file may have a suffix:
//	• L0: Contains fields common to all descriptors (except File) and
//	must be initialized up front.
//	• L1: Contains fields specific to a descriptor and
//	must be initialized up front.
//	• L2: Contains fields that are lazily initialized when constructing
//	from the raw file descriptor. When constructing as a literal, the L2
//	fields must be initialized up front.
//
// The types are exported so that packages like reflect/protodesc can
// directly construct descriptors.

type (
	File struct {
		fileRaw
		L1 FileL1

		once uint32     // atomically set if L2 is valid
		mu   sync.Mutex // protects L2
		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() // recursively initializes all L2 structures
	}
	atomic.StoreUint32(&.once, 1)
	.mu.Unlock()
}

// GoPackagePath is a pseudo-internal API for determining the Go package path
// that this file descriptor is declared in.
//
// WARNING: This method is exempt from the compatibility promise and may be
// removed in the future without warning.
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() 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() // implicitly initializes L2
	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 // 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() protoreflect.ProtoMessage
		Fields                Fields
		Oneofs                Oneofs
		ReservedNames         Names
		ReservedRanges        FieldRanges
		RequiredNumbers       FieldNumbers // must be consistent with Fields.Cardinality
		ExtensionRanges       FieldRanges
		ExtensionRangeOptions []func() protoreflect.ProtoMessage // must be same length as ExtensionRanges
	}

	Field struct {
		Base
		L1 FieldL1
	}
	FieldL1 struct {
		Options          func() protoreflect.ProtoMessage
		Number           protoreflect.FieldNumber
		Cardinality      protoreflect.Cardinality // must be consistent with Message.RequiredNumbers
		Kind             protoreflect.Kind
		StringName       stringName
		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  protoreflect.OneofDescriptor // must be consistent with Message.Oneofs.Fields
		Enum             protoreflect.EnumDescriptor
		Message          protoreflect.MessageDescriptor
	}

	Oneof struct {
		Base
		L1 OneofL1
	}
	OneofL1 struct {
		Options func() protoreflect.ProtoMessage
		Fields  OneofFields // must be consistent with Message.Fields.ContainingOneof
	}
)

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() // implicitly initializes L2
	return .L2
}

// IsMessageSet is a pseudo-internal API for checking whether a message
// should serialize in the proto1 message format.
//
// WARNING: This method is exempt from the compatibility promise and may be
// removed in the future without warning.
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) {}

// EnforceUTF8 is a pseudo-internal API to determine whether to enforce UTF-8
// validation for the string field. This exists for Google-internal use only
// since proto3 did not enforce UTF-8 validity prior to the open-source release.
// If this method does not exist, the default is to enforce valid UTF-8.
//
// WARNING: This method is exempt from the compatibility promise and may be
// removed in the future without warning.
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 // protected by fileDesc.once
	}
	ExtensionL1 struct {
		Number      protoreflect.FieldNumber
		Extendee    protoreflect.MessageDescriptor
		Cardinality protoreflect.Cardinality
		Kind        protoreflect.Kind
	}
	ExtensionL2 struct {
		Options          func() protoreflect.ProtoMessage
		StringName       stringName
		IsProto3Optional bool // promoted from google.protobuf.FieldDescriptorProto
		IsPacked         bool // promoted from google.protobuf.FieldOptions
		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() // implicitly initializes L2
	return .L2
}

type (
	Service struct {
		Base
		L1 ServiceL1
		L2 *ServiceL2 // protected by fileDesc.once
	}
	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() // implicitly initializes L2
	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)     {}

// Surrogate files are can be used to create standalone descriptors
// where the syntax is only information derived from the parent file.
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 // must be populated
		ParentFile *File                 // must be populated
		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 // surrogate files are not real parents
	}
	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
}

// InitJSON initializes the name. It is exported for use by other internal packages.
func ( *stringName) ( string) {
	.hasJSON = true
	.nameJSON = 
}

func ( *stringName) ( protoreflect.FieldDescriptor) *stringName {
	.once.Do(func() {
		if .IsExtension() {
			// For extensions, JSON and text are formatted the same way.
			var  string
			if messageset.IsMessageSetExtension() {
				 = string("[" + .FullName().Parent() + "]")
			} else {
				 = string("[" + .FullName() + "]")
			}
			.nameJSON = 
			.nameText = 
		} else {
			// Format the JSON name.
			if !.hasJSON {
				.nameJSON = strs.JSONCamelCase(string(.Name()))
			}

			// Format the text 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);  {
		// Store a copy of the default bytes, so that we can detect
		// accidental mutations of the original value.
		.bytes = append([]byte(nil), ...)
	}
	return 
}

func ( []byte,  protoreflect.Kind,  *File,  protoreflect.EnumDescriptor) defaultValue {
	var  protoreflect.EnumValueDescriptors
	if  == protoreflect.EnumKind {
		// If the enum is declared within the same file, be careful not to
		// blindly call the Values method, lest we bind ourselves in a deadlock.
		if ,  := .(*Enum);  && .L0.ParentFile ==  {
			 = &.L2.Values
		} else {
			 = .Values()
		}

		// If we are unable to resolve the enum dependency, use a placeholder
		// enum value since we will not be able to parse the default value.
		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 {
	// Return the zero value as the default if unpopulated.
	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()) {
		// TODO: Avoid panic if we're running with the race detector
		// and instead spawn a goroutine that periodically resets
		// this value back to the original to induce a race.
		panic(fmt.Sprintf("detected mutation on the default bytes for %v", .FullName()))
	}
	return .val
}