mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-01 11:58:21 +00:00
9d9d8d3ef5
This is a result of the discussion in [1]. Before editions, a group defined a multiple things: * a type * a field * an encoding scheme With editions this has changed and groups no longer exist and the different parts have to be defined individually. Most importantly, the field and the type also had the same name (usually and CamelCase name). To keep compatibility with proto2 groups, [2] introduced a concept of group-like fields and adjusted the Text/JSON parsers to accept the type name instead of the field name for such fields. This means you can convert from proto2 groups to editions without changing the semantics. Furthermore, to avoid suprises with group-like fields (e.g. when a user by coincident specified a field that is group-like) protobuf decided that group-like fields should always accept the type and the field name for group like fields. This also allows us to eventually emit the field name rather than the type name for group like fields in the future. This change implements this decision in Go. [1] https://github.com/protocolbuffers/protobuf/issues/16239 [2] https://go.dev/cl/575916 Change-Id: I701c4cd228d2e0867b2a87771b6c6331459c4910 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/582755 Reviewed-by: Lasse Folger <lassefolger@google.com> Reviewed-by: Mike Kruskal <mkruskal@google.com> Commit-Queue: Michael Stapelberg <stapelberg@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Stapelberg <stapelberg@google.com> Auto-Submit: Michael Stapelberg <stapelberg@google.com>
368 lines
8.7 KiB
Go
368 lines
8.7 KiB
Go
// Copyright 2018 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.
|
|
|
|
// Code generated by generate-types. DO NOT EDIT.
|
|
|
|
package filedesc
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"sync"
|
|
|
|
"google.golang.org/protobuf/internal/descfmt"
|
|
"google.golang.org/protobuf/internal/pragma"
|
|
"google.golang.org/protobuf/reflect/protoreflect"
|
|
)
|
|
|
|
type Enums struct {
|
|
List []Enum
|
|
once sync.Once
|
|
byName map[protoreflect.Name]*Enum // protected by once
|
|
}
|
|
|
|
func (p *Enums) Len() int {
|
|
return len(p.List)
|
|
}
|
|
func (p *Enums) Get(i int) protoreflect.EnumDescriptor {
|
|
return &p.List[i]
|
|
}
|
|
func (p *Enums) ByName(s protoreflect.Name) protoreflect.EnumDescriptor {
|
|
if d := p.lazyInit().byName[s]; d != nil {
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
func (p *Enums) Format(s fmt.State, r rune) {
|
|
descfmt.FormatList(s, r, p)
|
|
}
|
|
func (p *Enums) ProtoInternal(pragma.DoNotImplement) {}
|
|
func (p *Enums) lazyInit() *Enums {
|
|
p.once.Do(func() {
|
|
if len(p.List) > 0 {
|
|
p.byName = make(map[protoreflect.Name]*Enum, len(p.List))
|
|
for i := range p.List {
|
|
d := &p.List[i]
|
|
if _, ok := p.byName[d.Name()]; !ok {
|
|
p.byName[d.Name()] = d
|
|
}
|
|
}
|
|
}
|
|
})
|
|
return p
|
|
}
|
|
|
|
type EnumValues struct {
|
|
List []EnumValue
|
|
once sync.Once
|
|
byName map[protoreflect.Name]*EnumValue // protected by once
|
|
byNum map[protoreflect.EnumNumber]*EnumValue // protected by once
|
|
}
|
|
|
|
func (p *EnumValues) Len() int {
|
|
return len(p.List)
|
|
}
|
|
func (p *EnumValues) Get(i int) protoreflect.EnumValueDescriptor {
|
|
return &p.List[i]
|
|
}
|
|
func (p *EnumValues) ByName(s protoreflect.Name) protoreflect.EnumValueDescriptor {
|
|
if d := p.lazyInit().byName[s]; d != nil {
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
func (p *EnumValues) ByNumber(n protoreflect.EnumNumber) protoreflect.EnumValueDescriptor {
|
|
if d := p.lazyInit().byNum[n]; d != nil {
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
func (p *EnumValues) Format(s fmt.State, r rune) {
|
|
descfmt.FormatList(s, r, p)
|
|
}
|
|
func (p *EnumValues) ProtoInternal(pragma.DoNotImplement) {}
|
|
func (p *EnumValues) lazyInit() *EnumValues {
|
|
p.once.Do(func() {
|
|
if len(p.List) > 0 {
|
|
p.byName = make(map[protoreflect.Name]*EnumValue, len(p.List))
|
|
p.byNum = make(map[protoreflect.EnumNumber]*EnumValue, len(p.List))
|
|
for i := range p.List {
|
|
d := &p.List[i]
|
|
if _, ok := p.byName[d.Name()]; !ok {
|
|
p.byName[d.Name()] = d
|
|
}
|
|
if _, ok := p.byNum[d.Number()]; !ok {
|
|
p.byNum[d.Number()] = d
|
|
}
|
|
}
|
|
}
|
|
})
|
|
return p
|
|
}
|
|
|
|
type Messages struct {
|
|
List []Message
|
|
once sync.Once
|
|
byName map[protoreflect.Name]*Message // protected by once
|
|
}
|
|
|
|
func (p *Messages) Len() int {
|
|
return len(p.List)
|
|
}
|
|
func (p *Messages) Get(i int) protoreflect.MessageDescriptor {
|
|
return &p.List[i]
|
|
}
|
|
func (p *Messages) ByName(s protoreflect.Name) protoreflect.MessageDescriptor {
|
|
if d := p.lazyInit().byName[s]; d != nil {
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
func (p *Messages) Format(s fmt.State, r rune) {
|
|
descfmt.FormatList(s, r, p)
|
|
}
|
|
func (p *Messages) ProtoInternal(pragma.DoNotImplement) {}
|
|
func (p *Messages) lazyInit() *Messages {
|
|
p.once.Do(func() {
|
|
if len(p.List) > 0 {
|
|
p.byName = make(map[protoreflect.Name]*Message, len(p.List))
|
|
for i := range p.List {
|
|
d := &p.List[i]
|
|
if _, ok := p.byName[d.Name()]; !ok {
|
|
p.byName[d.Name()] = d
|
|
}
|
|
}
|
|
}
|
|
})
|
|
return p
|
|
}
|
|
|
|
type Fields struct {
|
|
List []Field
|
|
once sync.Once
|
|
byName map[protoreflect.Name]*Field // protected by once
|
|
byJSON map[string]*Field // protected by once
|
|
byText map[string]*Field // protected by once
|
|
byNum map[protoreflect.FieldNumber]*Field // protected by once
|
|
}
|
|
|
|
func (p *Fields) Len() int {
|
|
return len(p.List)
|
|
}
|
|
func (p *Fields) Get(i int) protoreflect.FieldDescriptor {
|
|
return &p.List[i]
|
|
}
|
|
func (p *Fields) ByName(s protoreflect.Name) protoreflect.FieldDescriptor {
|
|
if d := p.lazyInit().byName[s]; d != nil {
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
func (p *Fields) ByJSONName(s string) protoreflect.FieldDescriptor {
|
|
if d := p.lazyInit().byJSON[s]; d != nil {
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
func (p *Fields) ByTextName(s string) protoreflect.FieldDescriptor {
|
|
if d := p.lazyInit().byText[s]; d != nil {
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
func (p *Fields) ByNumber(n protoreflect.FieldNumber) protoreflect.FieldDescriptor {
|
|
if d := p.lazyInit().byNum[n]; d != nil {
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
func (p *Fields) Format(s fmt.State, r rune) {
|
|
descfmt.FormatList(s, r, p)
|
|
}
|
|
func (p *Fields) ProtoInternal(pragma.DoNotImplement) {}
|
|
func (p *Fields) lazyInit() *Fields {
|
|
p.once.Do(func() {
|
|
if len(p.List) > 0 {
|
|
p.byName = make(map[protoreflect.Name]*Field, len(p.List))
|
|
p.byJSON = make(map[string]*Field, len(p.List))
|
|
p.byText = make(map[string]*Field, len(p.List))
|
|
p.byNum = make(map[protoreflect.FieldNumber]*Field, len(p.List))
|
|
for i := range p.List {
|
|
d := &p.List[i]
|
|
if _, ok := p.byName[d.Name()]; !ok {
|
|
p.byName[d.Name()] = d
|
|
}
|
|
if _, ok := p.byJSON[d.JSONName()]; !ok {
|
|
p.byJSON[d.JSONName()] = d
|
|
}
|
|
if _, ok := p.byText[d.TextName()]; !ok {
|
|
p.byText[d.TextName()] = d
|
|
}
|
|
if isGroupLike(d) {
|
|
lowerJSONName := strings.ToLower(d.JSONName())
|
|
if _, ok := p.byJSON[lowerJSONName]; !ok {
|
|
p.byJSON[lowerJSONName] = d
|
|
}
|
|
lowerTextName := strings.ToLower(d.TextName())
|
|
if _, ok := p.byText[lowerTextName]; !ok {
|
|
p.byText[lowerTextName] = d
|
|
}
|
|
}
|
|
if _, ok := p.byNum[d.Number()]; !ok {
|
|
p.byNum[d.Number()] = d
|
|
}
|
|
}
|
|
}
|
|
})
|
|
return p
|
|
}
|
|
|
|
type Oneofs struct {
|
|
List []Oneof
|
|
once sync.Once
|
|
byName map[protoreflect.Name]*Oneof // protected by once
|
|
}
|
|
|
|
func (p *Oneofs) Len() int {
|
|
return len(p.List)
|
|
}
|
|
func (p *Oneofs) Get(i int) protoreflect.OneofDescriptor {
|
|
return &p.List[i]
|
|
}
|
|
func (p *Oneofs) ByName(s protoreflect.Name) protoreflect.OneofDescriptor {
|
|
if d := p.lazyInit().byName[s]; d != nil {
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
func (p *Oneofs) Format(s fmt.State, r rune) {
|
|
descfmt.FormatList(s, r, p)
|
|
}
|
|
func (p *Oneofs) ProtoInternal(pragma.DoNotImplement) {}
|
|
func (p *Oneofs) lazyInit() *Oneofs {
|
|
p.once.Do(func() {
|
|
if len(p.List) > 0 {
|
|
p.byName = make(map[protoreflect.Name]*Oneof, len(p.List))
|
|
for i := range p.List {
|
|
d := &p.List[i]
|
|
if _, ok := p.byName[d.Name()]; !ok {
|
|
p.byName[d.Name()] = d
|
|
}
|
|
}
|
|
}
|
|
})
|
|
return p
|
|
}
|
|
|
|
type Extensions struct {
|
|
List []Extension
|
|
once sync.Once
|
|
byName map[protoreflect.Name]*Extension // protected by once
|
|
}
|
|
|
|
func (p *Extensions) Len() int {
|
|
return len(p.List)
|
|
}
|
|
func (p *Extensions) Get(i int) protoreflect.ExtensionDescriptor {
|
|
return &p.List[i]
|
|
}
|
|
func (p *Extensions) ByName(s protoreflect.Name) protoreflect.ExtensionDescriptor {
|
|
if d := p.lazyInit().byName[s]; d != nil {
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
func (p *Extensions) Format(s fmt.State, r rune) {
|
|
descfmt.FormatList(s, r, p)
|
|
}
|
|
func (p *Extensions) ProtoInternal(pragma.DoNotImplement) {}
|
|
func (p *Extensions) lazyInit() *Extensions {
|
|
p.once.Do(func() {
|
|
if len(p.List) > 0 {
|
|
p.byName = make(map[protoreflect.Name]*Extension, len(p.List))
|
|
for i := range p.List {
|
|
d := &p.List[i]
|
|
if _, ok := p.byName[d.Name()]; !ok {
|
|
p.byName[d.Name()] = d
|
|
}
|
|
}
|
|
}
|
|
})
|
|
return p
|
|
}
|
|
|
|
type Services struct {
|
|
List []Service
|
|
once sync.Once
|
|
byName map[protoreflect.Name]*Service // protected by once
|
|
}
|
|
|
|
func (p *Services) Len() int {
|
|
return len(p.List)
|
|
}
|
|
func (p *Services) Get(i int) protoreflect.ServiceDescriptor {
|
|
return &p.List[i]
|
|
}
|
|
func (p *Services) ByName(s protoreflect.Name) protoreflect.ServiceDescriptor {
|
|
if d := p.lazyInit().byName[s]; d != nil {
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
func (p *Services) Format(s fmt.State, r rune) {
|
|
descfmt.FormatList(s, r, p)
|
|
}
|
|
func (p *Services) ProtoInternal(pragma.DoNotImplement) {}
|
|
func (p *Services) lazyInit() *Services {
|
|
p.once.Do(func() {
|
|
if len(p.List) > 0 {
|
|
p.byName = make(map[protoreflect.Name]*Service, len(p.List))
|
|
for i := range p.List {
|
|
d := &p.List[i]
|
|
if _, ok := p.byName[d.Name()]; !ok {
|
|
p.byName[d.Name()] = d
|
|
}
|
|
}
|
|
}
|
|
})
|
|
return p
|
|
}
|
|
|
|
type Methods struct {
|
|
List []Method
|
|
once sync.Once
|
|
byName map[protoreflect.Name]*Method // protected by once
|
|
}
|
|
|
|
func (p *Methods) Len() int {
|
|
return len(p.List)
|
|
}
|
|
func (p *Methods) Get(i int) protoreflect.MethodDescriptor {
|
|
return &p.List[i]
|
|
}
|
|
func (p *Methods) ByName(s protoreflect.Name) protoreflect.MethodDescriptor {
|
|
if d := p.lazyInit().byName[s]; d != nil {
|
|
return d
|
|
}
|
|
return nil
|
|
}
|
|
func (p *Methods) Format(s fmt.State, r rune) {
|
|
descfmt.FormatList(s, r, p)
|
|
}
|
|
func (p *Methods) ProtoInternal(pragma.DoNotImplement) {}
|
|
func (p *Methods) lazyInit() *Methods {
|
|
p.once.Do(func() {
|
|
if len(p.List) > 0 {
|
|
p.byName = make(map[protoreflect.Name]*Method, len(p.List))
|
|
for i := range p.List {
|
|
d := &p.List[i]
|
|
if _, ok := p.byName[d.Name()]; !ok {
|
|
p.byName[d.Name()] = d
|
|
}
|
|
}
|
|
}
|
|
})
|
|
return p
|
|
}
|