...

Source file src/google.golang.org/protobuf/internal/filedesc/desc_list_gen.go

Documentation: google.golang.org/protobuf/internal/filedesc

     1  // Copyright 2018 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Code generated by generate-types. DO NOT EDIT.
     6  
     7  package filedesc
     8  
     9  import (
    10  	"fmt"
    11  	"strings"
    12  	"sync"
    13  
    14  	"google.golang.org/protobuf/internal/descfmt"
    15  	"google.golang.org/protobuf/internal/pragma"
    16  	"google.golang.org/protobuf/reflect/protoreflect"
    17  )
    18  
    19  type Enums struct {
    20  	List   []Enum
    21  	once   sync.Once
    22  	byName map[protoreflect.Name]*Enum // protected by once
    23  }
    24  
    25  func (p *Enums) Len() int {
    26  	return len(p.List)
    27  }
    28  func (p *Enums) Get(i int) protoreflect.EnumDescriptor {
    29  	return &p.List[i]
    30  }
    31  func (p *Enums) ByName(s protoreflect.Name) protoreflect.EnumDescriptor {
    32  	if d := p.lazyInit().byName[s]; d != nil {
    33  		return d
    34  	}
    35  	return nil
    36  }
    37  func (p *Enums) Format(s fmt.State, r rune) {
    38  	descfmt.FormatList(s, r, p)
    39  }
    40  func (p *Enums) ProtoInternal(pragma.DoNotImplement) {}
    41  func (p *Enums) lazyInit() *Enums {
    42  	p.once.Do(func() {
    43  		if len(p.List) > 0 {
    44  			p.byName = make(map[protoreflect.Name]*Enum, len(p.List))
    45  			for i := range p.List {
    46  				d := &p.List[i]
    47  				if _, ok := p.byName[d.Name()]; !ok {
    48  					p.byName[d.Name()] = d
    49  				}
    50  			}
    51  		}
    52  	})
    53  	return p
    54  }
    55  
    56  type EnumValues struct {
    57  	List   []EnumValue
    58  	once   sync.Once
    59  	byName map[protoreflect.Name]*EnumValue       // protected by once
    60  	byNum  map[protoreflect.EnumNumber]*EnumValue // protected by once
    61  }
    62  
    63  func (p *EnumValues) Len() int {
    64  	return len(p.List)
    65  }
    66  func (p *EnumValues) Get(i int) protoreflect.EnumValueDescriptor {
    67  	return &p.List[i]
    68  }
    69  func (p *EnumValues) ByName(s protoreflect.Name) protoreflect.EnumValueDescriptor {
    70  	if d := p.lazyInit().byName[s]; d != nil {
    71  		return d
    72  	}
    73  	return nil
    74  }
    75  func (p *EnumValues) ByNumber(n protoreflect.EnumNumber) protoreflect.EnumValueDescriptor {
    76  	if d := p.lazyInit().byNum[n]; d != nil {
    77  		return d
    78  	}
    79  	return nil
    80  }
    81  func (p *EnumValues) Format(s fmt.State, r rune) {
    82  	descfmt.FormatList(s, r, p)
    83  }
    84  func (p *EnumValues) ProtoInternal(pragma.DoNotImplement) {}
    85  func (p *EnumValues) lazyInit() *EnumValues {
    86  	p.once.Do(func() {
    87  		if len(p.List) > 0 {
    88  			p.byName = make(map[protoreflect.Name]*EnumValue, len(p.List))
    89  			p.byNum = make(map[protoreflect.EnumNumber]*EnumValue, len(p.List))
    90  			for i := range p.List {
    91  				d := &p.List[i]
    92  				if _, ok := p.byName[d.Name()]; !ok {
    93  					p.byName[d.Name()] = d
    94  				}
    95  				if _, ok := p.byNum[d.Number()]; !ok {
    96  					p.byNum[d.Number()] = d
    97  				}
    98  			}
    99  		}
   100  	})
   101  	return p
   102  }
   103  
   104  type Messages struct {
   105  	List   []Message
   106  	once   sync.Once
   107  	byName map[protoreflect.Name]*Message // protected by once
   108  }
   109  
   110  func (p *Messages) Len() int {
   111  	return len(p.List)
   112  }
   113  func (p *Messages) Get(i int) protoreflect.MessageDescriptor {
   114  	return &p.List[i]
   115  }
   116  func (p *Messages) ByName(s protoreflect.Name) protoreflect.MessageDescriptor {
   117  	if d := p.lazyInit().byName[s]; d != nil {
   118  		return d
   119  	}
   120  	return nil
   121  }
   122  func (p *Messages) Format(s fmt.State, r rune) {
   123  	descfmt.FormatList(s, r, p)
   124  }
   125  func (p *Messages) ProtoInternal(pragma.DoNotImplement) {}
   126  func (p *Messages) lazyInit() *Messages {
   127  	p.once.Do(func() {
   128  		if len(p.List) > 0 {
   129  			p.byName = make(map[protoreflect.Name]*Message, len(p.List))
   130  			for i := range p.List {
   131  				d := &p.List[i]
   132  				if _, ok := p.byName[d.Name()]; !ok {
   133  					p.byName[d.Name()] = d
   134  				}
   135  			}
   136  		}
   137  	})
   138  	return p
   139  }
   140  
   141  type Fields struct {
   142  	List   []Field
   143  	once   sync.Once
   144  	byName map[protoreflect.Name]*Field        // protected by once
   145  	byJSON map[string]*Field                   // protected by once
   146  	byText map[string]*Field                   // protected by once
   147  	byNum  map[protoreflect.FieldNumber]*Field // protected by once
   148  }
   149  
   150  func (p *Fields) Len() int {
   151  	return len(p.List)
   152  }
   153  func (p *Fields) Get(i int) protoreflect.FieldDescriptor {
   154  	return &p.List[i]
   155  }
   156  func (p *Fields) ByName(s protoreflect.Name) protoreflect.FieldDescriptor {
   157  	if d := p.lazyInit().byName[s]; d != nil {
   158  		return d
   159  	}
   160  	return nil
   161  }
   162  func (p *Fields) ByJSONName(s string) protoreflect.FieldDescriptor {
   163  	if d := p.lazyInit().byJSON[s]; d != nil {
   164  		return d
   165  	}
   166  	return nil
   167  }
   168  func (p *Fields) ByTextName(s string) protoreflect.FieldDescriptor {
   169  	if d := p.lazyInit().byText[s]; d != nil {
   170  		return d
   171  	}
   172  	return nil
   173  }
   174  func (p *Fields) ByNumber(n protoreflect.FieldNumber) protoreflect.FieldDescriptor {
   175  	if d := p.lazyInit().byNum[n]; d != nil {
   176  		return d
   177  	}
   178  	return nil
   179  }
   180  func (p *Fields) Format(s fmt.State, r rune) {
   181  	descfmt.FormatList(s, r, p)
   182  }
   183  func (p *Fields) ProtoInternal(pragma.DoNotImplement) {}
   184  func (p *Fields) lazyInit() *Fields {
   185  	p.once.Do(func() {
   186  		if len(p.List) > 0 {
   187  			p.byName = make(map[protoreflect.Name]*Field, len(p.List))
   188  			p.byJSON = make(map[string]*Field, len(p.List))
   189  			p.byText = make(map[string]*Field, len(p.List))
   190  			p.byNum = make(map[protoreflect.FieldNumber]*Field, len(p.List))
   191  			for i := range p.List {
   192  				d := &p.List[i]
   193  				if _, ok := p.byName[d.Name()]; !ok {
   194  					p.byName[d.Name()] = d
   195  				}
   196  				if _, ok := p.byJSON[d.JSONName()]; !ok {
   197  					p.byJSON[d.JSONName()] = d
   198  				}
   199  				if _, ok := p.byText[d.TextName()]; !ok {
   200  					p.byText[d.TextName()] = d
   201  				}
   202  				if isGroupLike(d) {
   203  					lowerJSONName := strings.ToLower(d.JSONName())
   204  					if _, ok := p.byJSON[lowerJSONName]; !ok {
   205  						p.byJSON[lowerJSONName] = d
   206  					}
   207  					lowerTextName := strings.ToLower(d.TextName())
   208  					if _, ok := p.byText[lowerTextName]; !ok {
   209  						p.byText[lowerTextName] = d
   210  					}
   211  				}
   212  				if _, ok := p.byNum[d.Number()]; !ok {
   213  					p.byNum[d.Number()] = d
   214  				}
   215  			}
   216  		}
   217  	})
   218  	return p
   219  }
   220  
   221  type Oneofs struct {
   222  	List   []Oneof
   223  	once   sync.Once
   224  	byName map[protoreflect.Name]*Oneof // protected by once
   225  }
   226  
   227  func (p *Oneofs) Len() int {
   228  	return len(p.List)
   229  }
   230  func (p *Oneofs) Get(i int) protoreflect.OneofDescriptor {
   231  	return &p.List[i]
   232  }
   233  func (p *Oneofs) ByName(s protoreflect.Name) protoreflect.OneofDescriptor {
   234  	if d := p.lazyInit().byName[s]; d != nil {
   235  		return d
   236  	}
   237  	return nil
   238  }
   239  func (p *Oneofs) Format(s fmt.State, r rune) {
   240  	descfmt.FormatList(s, r, p)
   241  }
   242  func (p *Oneofs) ProtoInternal(pragma.DoNotImplement) {}
   243  func (p *Oneofs) lazyInit() *Oneofs {
   244  	p.once.Do(func() {
   245  		if len(p.List) > 0 {
   246  			p.byName = make(map[protoreflect.Name]*Oneof, len(p.List))
   247  			for i := range p.List {
   248  				d := &p.List[i]
   249  				if _, ok := p.byName[d.Name()]; !ok {
   250  					p.byName[d.Name()] = d
   251  				}
   252  			}
   253  		}
   254  	})
   255  	return p
   256  }
   257  
   258  type Extensions struct {
   259  	List   []Extension
   260  	once   sync.Once
   261  	byName map[protoreflect.Name]*Extension // protected by once
   262  }
   263  
   264  func (p *Extensions) Len() int {
   265  	return len(p.List)
   266  }
   267  func (p *Extensions) Get(i int) protoreflect.ExtensionDescriptor {
   268  	return &p.List[i]
   269  }
   270  func (p *Extensions) ByName(s protoreflect.Name) protoreflect.ExtensionDescriptor {
   271  	if d := p.lazyInit().byName[s]; d != nil {
   272  		return d
   273  	}
   274  	return nil
   275  }
   276  func (p *Extensions) Format(s fmt.State, r rune) {
   277  	descfmt.FormatList(s, r, p)
   278  }
   279  func (p *Extensions) ProtoInternal(pragma.DoNotImplement) {}
   280  func (p *Extensions) lazyInit() *Extensions {
   281  	p.once.Do(func() {
   282  		if len(p.List) > 0 {
   283  			p.byName = make(map[protoreflect.Name]*Extension, len(p.List))
   284  			for i := range p.List {
   285  				d := &p.List[i]
   286  				if _, ok := p.byName[d.Name()]; !ok {
   287  					p.byName[d.Name()] = d
   288  				}
   289  			}
   290  		}
   291  	})
   292  	return p
   293  }
   294  
   295  type Services struct {
   296  	List   []Service
   297  	once   sync.Once
   298  	byName map[protoreflect.Name]*Service // protected by once
   299  }
   300  
   301  func (p *Services) Len() int {
   302  	return len(p.List)
   303  }
   304  func (p *Services) Get(i int) protoreflect.ServiceDescriptor {
   305  	return &p.List[i]
   306  }
   307  func (p *Services) ByName(s protoreflect.Name) protoreflect.ServiceDescriptor {
   308  	if d := p.lazyInit().byName[s]; d != nil {
   309  		return d
   310  	}
   311  	return nil
   312  }
   313  func (p *Services) Format(s fmt.State, r rune) {
   314  	descfmt.FormatList(s, r, p)
   315  }
   316  func (p *Services) ProtoInternal(pragma.DoNotImplement) {}
   317  func (p *Services) lazyInit() *Services {
   318  	p.once.Do(func() {
   319  		if len(p.List) > 0 {
   320  			p.byName = make(map[protoreflect.Name]*Service, len(p.List))
   321  			for i := range p.List {
   322  				d := &p.List[i]
   323  				if _, ok := p.byName[d.Name()]; !ok {
   324  					p.byName[d.Name()] = d
   325  				}
   326  			}
   327  		}
   328  	})
   329  	return p
   330  }
   331  
   332  type Methods struct {
   333  	List   []Method
   334  	once   sync.Once
   335  	byName map[protoreflect.Name]*Method // protected by once
   336  }
   337  
   338  func (p *Methods) Len() int {
   339  	return len(p.List)
   340  }
   341  func (p *Methods) Get(i int) protoreflect.MethodDescriptor {
   342  	return &p.List[i]
   343  }
   344  func (p *Methods) ByName(s protoreflect.Name) protoreflect.MethodDescriptor {
   345  	if d := p.lazyInit().byName[s]; d != nil {
   346  		return d
   347  	}
   348  	return nil
   349  }
   350  func (p *Methods) Format(s fmt.State, r rune) {
   351  	descfmt.FormatList(s, r, p)
   352  }
   353  func (p *Methods) ProtoInternal(pragma.DoNotImplement) {}
   354  func (p *Methods) lazyInit() *Methods {
   355  	p.once.Do(func() {
   356  		if len(p.List) > 0 {
   357  			p.byName = make(map[protoreflect.Name]*Method, len(p.List))
   358  			for i := range p.List {
   359  				d := &p.List[i]
   360  				if _, ok := p.byName[d.Name()]; !ok {
   361  					p.byName[d.Name()] = d
   362  				}
   363  			}
   364  		}
   365  	})
   366  	return p
   367  }
   368  

View as plain text