build(deps): bump the golang group across 1 directory with 4 updates
Bumps the golang group with 2 updates in the / directory: [github.com/Microsoft/hcsshim](https://github.com/Microsoft/hcsshim) and [github.com/onsi/ginkgo/v2](https://github.com/onsi/ginkgo). Updates `github.com/Microsoft/hcsshim` from 0.12.4 to 0.12.6 - [Release notes](https://github.com/Microsoft/hcsshim/releases) - [Commits](https://github.com/Microsoft/hcsshim/compare/v0.12.4...v0.12.6) Updates `github.com/onsi/ginkgo/v2` from 2.19.0 to 2.20.1 - [Release notes](https://github.com/onsi/ginkgo/releases) - [Changelog](https://github.com/onsi/ginkgo/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/ginkgo/compare/v2.19.0...v2.20.1) Updates `github.com/onsi/gomega` from 1.33.1 to 1.34.1 - [Release notes](https://github.com/onsi/gomega/releases) - [Changelog](https://github.com/onsi/gomega/blob/master/CHANGELOG.md) - [Commits](https://github.com/onsi/gomega/compare/v1.33.1...v1.34.1) Updates `golang.org/x/sys` from 0.21.0 to 0.23.0 - [Commits](https://github.com/golang/sys/compare/v0.21.0...v0.23.0) --- updated-dependencies: - dependency-name: github.com/Microsoft/hcsshim dependency-type: direct:production update-type: version-update:semver-patch dependency-group: golang - dependency-name: github.com/onsi/ginkgo/v2 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: github.com/onsi/gomega dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang - dependency-name: golang.org/x/sys dependency-type: direct:production update-type: version-update:semver-minor dependency-group: golang ... Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
285
vendor/google.golang.org/protobuf/reflect/protodesc/desc.go
generated
vendored
285
vendor/google.golang.org/protobuf/reflect/protodesc/desc.go
generated
vendored
@ -1,285 +0,0 @@
|
||||
// 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.
|
||||
|
||||
// Package protodesc provides functionality for converting
|
||||
// FileDescriptorProto messages to/from [protoreflect.FileDescriptor] values.
|
||||
//
|
||||
// The google.protobuf.FileDescriptorProto is a protobuf message that describes
|
||||
// the type information for a .proto file in a form that is easily serializable.
|
||||
// The [protoreflect.FileDescriptor] is a more structured representation of
|
||||
// the FileDescriptorProto message where references and remote dependencies
|
||||
// can be directly followed.
|
||||
package protodesc
|
||||
|
||||
import (
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
"google.golang.org/protobuf/internal/filedesc"
|
||||
"google.golang.org/protobuf/internal/pragma"
|
||||
"google.golang.org/protobuf/internal/strs"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
)
|
||||
|
||||
// Resolver is the resolver used by [NewFile] to resolve dependencies.
|
||||
// The enums and messages provided must belong to some parent file,
|
||||
// which is also registered.
|
||||
//
|
||||
// It is implemented by [protoregistry.Files].
|
||||
type Resolver interface {
|
||||
FindFileByPath(string) (protoreflect.FileDescriptor, error)
|
||||
FindDescriptorByName(protoreflect.FullName) (protoreflect.Descriptor, error)
|
||||
}
|
||||
|
||||
// FileOptions configures the construction of file descriptors.
|
||||
type FileOptions struct {
|
||||
pragma.NoUnkeyedLiterals
|
||||
|
||||
// AllowUnresolvable configures New to permissively allow unresolvable
|
||||
// file, enum, or message dependencies. Unresolved dependencies are replaced
|
||||
// by placeholder equivalents.
|
||||
//
|
||||
// The following dependencies may be left unresolved:
|
||||
// • Resolving an imported file.
|
||||
// • Resolving the type for a message field or extension field.
|
||||
// If the kind of the field is unknown, then a placeholder is used for both
|
||||
// the Enum and Message accessors on the protoreflect.FieldDescriptor.
|
||||
// • Resolving an enum value set as the default for an optional enum field.
|
||||
// If unresolvable, the protoreflect.FieldDescriptor.Default is set to the
|
||||
// first value in the associated enum (or zero if the also enum dependency
|
||||
// is also unresolvable). The protoreflect.FieldDescriptor.DefaultEnumValue
|
||||
// is populated with a placeholder.
|
||||
// • Resolving the extended message type for an extension field.
|
||||
// • Resolving the input or output message type for a service method.
|
||||
//
|
||||
// If the unresolved dependency uses a relative name,
|
||||
// then the placeholder will contain an invalid FullName with a "*." prefix,
|
||||
// indicating that the starting prefix of the full name is unknown.
|
||||
AllowUnresolvable bool
|
||||
}
|
||||
|
||||
// NewFile creates a new [protoreflect.FileDescriptor] from the provided
|
||||
// file descriptor message. See [FileOptions.New] for more information.
|
||||
func NewFile(fd *descriptorpb.FileDescriptorProto, r Resolver) (protoreflect.FileDescriptor, error) {
|
||||
return FileOptions{}.New(fd, r)
|
||||
}
|
||||
|
||||
// NewFiles creates a new [protoregistry.Files] from the provided
|
||||
// FileDescriptorSet message. See [FileOptions.NewFiles] for more information.
|
||||
func NewFiles(fd *descriptorpb.FileDescriptorSet) (*protoregistry.Files, error) {
|
||||
return FileOptions{}.NewFiles(fd)
|
||||
}
|
||||
|
||||
// New creates a new [protoreflect.FileDescriptor] from the provided
|
||||
// file descriptor message. The file must represent a valid proto file according
|
||||
// to protobuf semantics. The returned descriptor is a deep copy of the input.
|
||||
//
|
||||
// Any imported files, enum types, or message types referenced in the file are
|
||||
// resolved using the provided registry. When looking up an import file path,
|
||||
// the path must be unique. The newly created file descriptor is not registered
|
||||
// back into the provided file registry.
|
||||
func (o FileOptions) New(fd *descriptorpb.FileDescriptorProto, r Resolver) (protoreflect.FileDescriptor, error) {
|
||||
if r == nil {
|
||||
r = (*protoregistry.Files)(nil) // empty resolver
|
||||
}
|
||||
|
||||
// Handle the file descriptor content.
|
||||
f := &filedesc.File{L2: &filedesc.FileL2{}}
|
||||
switch fd.GetSyntax() {
|
||||
case "proto2", "":
|
||||
f.L1.Syntax = protoreflect.Proto2
|
||||
case "proto3":
|
||||
f.L1.Syntax = protoreflect.Proto3
|
||||
case "editions":
|
||||
f.L1.Syntax = protoreflect.Editions
|
||||
f.L1.Edition = fromEditionProto(fd.GetEdition())
|
||||
default:
|
||||
return nil, errors.New("invalid syntax: %q", fd.GetSyntax())
|
||||
}
|
||||
if f.L1.Syntax == protoreflect.Editions && (fd.GetEdition() < SupportedEditionsMinimum || fd.GetEdition() > SupportedEditionsMaximum) {
|
||||
return nil, errors.New("use of edition %v not yet supported by the Go Protobuf runtime", fd.GetEdition())
|
||||
}
|
||||
f.L1.Path = fd.GetName()
|
||||
if f.L1.Path == "" {
|
||||
return nil, errors.New("file path must be populated")
|
||||
}
|
||||
f.L1.Package = protoreflect.FullName(fd.GetPackage())
|
||||
if !f.L1.Package.IsValid() && f.L1.Package != "" {
|
||||
return nil, errors.New("invalid package: %q", f.L1.Package)
|
||||
}
|
||||
if opts := fd.GetOptions(); opts != nil {
|
||||
opts = proto.Clone(opts).(*descriptorpb.FileOptions)
|
||||
f.L2.Options = func() protoreflect.ProtoMessage { return opts }
|
||||
}
|
||||
if f.L1.Syntax == protoreflect.Editions {
|
||||
initFileDescFromFeatureSet(f, fd.GetOptions().GetFeatures())
|
||||
}
|
||||
|
||||
f.L2.Imports = make(filedesc.FileImports, len(fd.GetDependency()))
|
||||
for _, i := range fd.GetPublicDependency() {
|
||||
if !(0 <= i && int(i) < len(f.L2.Imports)) || f.L2.Imports[i].IsPublic {
|
||||
return nil, errors.New("invalid or duplicate public import index: %d", i)
|
||||
}
|
||||
f.L2.Imports[i].IsPublic = true
|
||||
}
|
||||
for _, i := range fd.GetWeakDependency() {
|
||||
if !(0 <= i && int(i) < len(f.L2.Imports)) || f.L2.Imports[i].IsWeak {
|
||||
return nil, errors.New("invalid or duplicate weak import index: %d", i)
|
||||
}
|
||||
f.L2.Imports[i].IsWeak = true
|
||||
}
|
||||
imps := importSet{f.Path(): true}
|
||||
for i, path := range fd.GetDependency() {
|
||||
imp := &f.L2.Imports[i]
|
||||
f, err := r.FindFileByPath(path)
|
||||
if err == protoregistry.NotFound && (o.AllowUnresolvable || imp.IsWeak) {
|
||||
f = filedesc.PlaceholderFile(path)
|
||||
} else if err != nil {
|
||||
return nil, errors.New("could not resolve import %q: %v", path, err)
|
||||
}
|
||||
imp.FileDescriptor = f
|
||||
|
||||
if imps[imp.Path()] {
|
||||
return nil, errors.New("already imported %q", path)
|
||||
}
|
||||
imps[imp.Path()] = true
|
||||
}
|
||||
for i := range fd.GetDependency() {
|
||||
imp := &f.L2.Imports[i]
|
||||
imps.importPublic(imp.Imports())
|
||||
}
|
||||
|
||||
// Handle source locations.
|
||||
f.L2.Locations.File = f
|
||||
for _, loc := range fd.GetSourceCodeInfo().GetLocation() {
|
||||
var l protoreflect.SourceLocation
|
||||
// TODO: Validate that the path points to an actual declaration?
|
||||
l.Path = protoreflect.SourcePath(loc.GetPath())
|
||||
s := loc.GetSpan()
|
||||
switch len(s) {
|
||||
case 3:
|
||||
l.StartLine, l.StartColumn, l.EndLine, l.EndColumn = int(s[0]), int(s[1]), int(s[0]), int(s[2])
|
||||
case 4:
|
||||
l.StartLine, l.StartColumn, l.EndLine, l.EndColumn = int(s[0]), int(s[1]), int(s[2]), int(s[3])
|
||||
default:
|
||||
return nil, errors.New("invalid span: %v", s)
|
||||
}
|
||||
// TODO: Validate that the span information is sensible?
|
||||
// See https://github.com/protocolbuffers/protobuf/issues/6378.
|
||||
if false && (l.EndLine < l.StartLine || l.StartLine < 0 || l.StartColumn < 0 || l.EndColumn < 0 ||
|
||||
(l.StartLine == l.EndLine && l.EndColumn <= l.StartColumn)) {
|
||||
return nil, errors.New("invalid span: %v", s)
|
||||
}
|
||||
l.LeadingDetachedComments = loc.GetLeadingDetachedComments()
|
||||
l.LeadingComments = loc.GetLeadingComments()
|
||||
l.TrailingComments = loc.GetTrailingComments()
|
||||
f.L2.Locations.List = append(f.L2.Locations.List, l)
|
||||
}
|
||||
|
||||
// Step 1: Allocate and derive the names for all declarations.
|
||||
// This copies all fields from the descriptor proto except:
|
||||
// google.protobuf.FieldDescriptorProto.type_name
|
||||
// google.protobuf.FieldDescriptorProto.default_value
|
||||
// google.protobuf.FieldDescriptorProto.oneof_index
|
||||
// google.protobuf.FieldDescriptorProto.extendee
|
||||
// google.protobuf.MethodDescriptorProto.input
|
||||
// google.protobuf.MethodDescriptorProto.output
|
||||
var err error
|
||||
sb := new(strs.Builder)
|
||||
r1 := make(descsByName)
|
||||
if f.L1.Enums.List, err = r1.initEnumDeclarations(fd.GetEnumType(), f, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if f.L1.Messages.List, err = r1.initMessagesDeclarations(fd.GetMessageType(), f, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if f.L1.Extensions.List, err = r1.initExtensionDeclarations(fd.GetExtension(), f, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if f.L1.Services.List, err = r1.initServiceDeclarations(fd.GetService(), f, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Step 2: Resolve every dependency reference not handled by step 1.
|
||||
r2 := &resolver{local: r1, remote: r, imports: imps, allowUnresolvable: o.AllowUnresolvable}
|
||||
if err := r2.resolveMessageDependencies(f.L1.Messages.List, fd.GetMessageType()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := r2.resolveExtensionDependencies(f.L1.Extensions.List, fd.GetExtension()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := r2.resolveServiceDependencies(f.L1.Services.List, fd.GetService()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Step 3: Validate every enum, message, and extension declaration.
|
||||
if err := validateEnumDeclarations(f.L1.Enums.List, fd.GetEnumType()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := validateMessageDeclarations(f.L1.Messages.List, fd.GetMessageType()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := validateExtensionDeclarations(f.L1.Extensions.List, fd.GetExtension()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return f, nil
|
||||
}
|
||||
|
||||
type importSet map[string]bool
|
||||
|
||||
func (is importSet) importPublic(imps protoreflect.FileImports) {
|
||||
for i := 0; i < imps.Len(); i++ {
|
||||
if imp := imps.Get(i); imp.IsPublic {
|
||||
is[imp.Path()] = true
|
||||
is.importPublic(imp.Imports())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NewFiles creates a new [protoregistry.Files] from the provided
|
||||
// FileDescriptorSet message. The descriptor set must include only
|
||||
// valid files according to protobuf semantics. The returned descriptors
|
||||
// are a deep copy of the input.
|
||||
func (o FileOptions) NewFiles(fds *descriptorpb.FileDescriptorSet) (*protoregistry.Files, error) {
|
||||
files := make(map[string]*descriptorpb.FileDescriptorProto)
|
||||
for _, fd := range fds.File {
|
||||
if _, ok := files[fd.GetName()]; ok {
|
||||
return nil, errors.New("file appears multiple times: %q", fd.GetName())
|
||||
}
|
||||
files[fd.GetName()] = fd
|
||||
}
|
||||
r := &protoregistry.Files{}
|
||||
for _, fd := range files {
|
||||
if err := o.addFileDeps(r, fd, files); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
func (o FileOptions) addFileDeps(r *protoregistry.Files, fd *descriptorpb.FileDescriptorProto, files map[string]*descriptorpb.FileDescriptorProto) error {
|
||||
// Set the entry to nil while descending into a file's dependencies to detect cycles.
|
||||
files[fd.GetName()] = nil
|
||||
for _, dep := range fd.Dependency {
|
||||
depfd, ok := files[dep]
|
||||
if depfd == nil {
|
||||
if ok {
|
||||
return errors.New("import cycle in file: %q", dep)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if err := o.addFileDeps(r, depfd, files); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// Delete the entry once dependencies are processed.
|
||||
delete(files, fd.GetName())
|
||||
f, err := o.New(fd, r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return r.RegisterFile(f)
|
||||
}
|
304
vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go
generated
vendored
304
vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go
generated
vendored
@ -1,304 +0,0 @@
|
||||
// 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 protodesc
|
||||
|
||||
import (
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
"google.golang.org/protobuf/internal/filedesc"
|
||||
"google.golang.org/protobuf/internal/strs"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
)
|
||||
|
||||
type descsByName map[protoreflect.FullName]protoreflect.Descriptor
|
||||
|
||||
func (r descsByName) initEnumDeclarations(eds []*descriptorpb.EnumDescriptorProto, parent protoreflect.Descriptor, sb *strs.Builder) (es []filedesc.Enum, err error) {
|
||||
es = make([]filedesc.Enum, len(eds)) // allocate up-front to ensure stable pointers
|
||||
for i, ed := range eds {
|
||||
e := &es[i]
|
||||
e.L2 = new(filedesc.EnumL2)
|
||||
if e.L0, err = r.makeBase(e, parent, ed.GetName(), i, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if opts := ed.GetOptions(); opts != nil {
|
||||
opts = proto.Clone(opts).(*descriptorpb.EnumOptions)
|
||||
e.L2.Options = func() protoreflect.ProtoMessage { return opts }
|
||||
}
|
||||
e.L1.EditionFeatures = mergeEditionFeatures(parent, ed.GetOptions().GetFeatures())
|
||||
for _, s := range ed.GetReservedName() {
|
||||
e.L2.ReservedNames.List = append(e.L2.ReservedNames.List, protoreflect.Name(s))
|
||||
}
|
||||
for _, rr := range ed.GetReservedRange() {
|
||||
e.L2.ReservedRanges.List = append(e.L2.ReservedRanges.List, [2]protoreflect.EnumNumber{
|
||||
protoreflect.EnumNumber(rr.GetStart()),
|
||||
protoreflect.EnumNumber(rr.GetEnd()),
|
||||
})
|
||||
}
|
||||
if e.L2.Values.List, err = r.initEnumValuesFromDescriptorProto(ed.GetValue(), e, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return es, nil
|
||||
}
|
||||
|
||||
func (r descsByName) initEnumValuesFromDescriptorProto(vds []*descriptorpb.EnumValueDescriptorProto, parent protoreflect.Descriptor, sb *strs.Builder) (vs []filedesc.EnumValue, err error) {
|
||||
vs = make([]filedesc.EnumValue, len(vds)) // allocate up-front to ensure stable pointers
|
||||
for i, vd := range vds {
|
||||
v := &vs[i]
|
||||
if v.L0, err = r.makeBase(v, parent, vd.GetName(), i, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if opts := vd.GetOptions(); opts != nil {
|
||||
opts = proto.Clone(opts).(*descriptorpb.EnumValueOptions)
|
||||
v.L1.Options = func() protoreflect.ProtoMessage { return opts }
|
||||
}
|
||||
v.L1.Number = protoreflect.EnumNumber(vd.GetNumber())
|
||||
}
|
||||
return vs, nil
|
||||
}
|
||||
|
||||
func (r descsByName) initMessagesDeclarations(mds []*descriptorpb.DescriptorProto, parent protoreflect.Descriptor, sb *strs.Builder) (ms []filedesc.Message, err error) {
|
||||
ms = make([]filedesc.Message, len(mds)) // allocate up-front to ensure stable pointers
|
||||
for i, md := range mds {
|
||||
m := &ms[i]
|
||||
m.L2 = new(filedesc.MessageL2)
|
||||
if m.L0, err = r.makeBase(m, parent, md.GetName(), i, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if m.Base.L0.ParentFile.Syntax() == protoreflect.Editions {
|
||||
m.L1.EditionFeatures = mergeEditionFeatures(parent, md.GetOptions().GetFeatures())
|
||||
}
|
||||
if opts := md.GetOptions(); opts != nil {
|
||||
opts = proto.Clone(opts).(*descriptorpb.MessageOptions)
|
||||
m.L2.Options = func() protoreflect.ProtoMessage { return opts }
|
||||
m.L1.IsMapEntry = opts.GetMapEntry()
|
||||
m.L1.IsMessageSet = opts.GetMessageSetWireFormat()
|
||||
}
|
||||
for _, s := range md.GetReservedName() {
|
||||
m.L2.ReservedNames.List = append(m.L2.ReservedNames.List, protoreflect.Name(s))
|
||||
}
|
||||
for _, rr := range md.GetReservedRange() {
|
||||
m.L2.ReservedRanges.List = append(m.L2.ReservedRanges.List, [2]protoreflect.FieldNumber{
|
||||
protoreflect.FieldNumber(rr.GetStart()),
|
||||
protoreflect.FieldNumber(rr.GetEnd()),
|
||||
})
|
||||
}
|
||||
for _, xr := range md.GetExtensionRange() {
|
||||
m.L2.ExtensionRanges.List = append(m.L2.ExtensionRanges.List, [2]protoreflect.FieldNumber{
|
||||
protoreflect.FieldNumber(xr.GetStart()),
|
||||
protoreflect.FieldNumber(xr.GetEnd()),
|
||||
})
|
||||
var optsFunc func() protoreflect.ProtoMessage
|
||||
if opts := xr.GetOptions(); opts != nil {
|
||||
opts = proto.Clone(opts).(*descriptorpb.ExtensionRangeOptions)
|
||||
optsFunc = func() protoreflect.ProtoMessage { return opts }
|
||||
}
|
||||
m.L2.ExtensionRangeOptions = append(m.L2.ExtensionRangeOptions, optsFunc)
|
||||
}
|
||||
if m.L2.Fields.List, err = r.initFieldsFromDescriptorProto(md.GetField(), m, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if m.L2.Oneofs.List, err = r.initOneofsFromDescriptorProto(md.GetOneofDecl(), m, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if m.L1.Enums.List, err = r.initEnumDeclarations(md.GetEnumType(), m, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if m.L1.Messages.List, err = r.initMessagesDeclarations(md.GetNestedType(), m, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if m.L1.Extensions.List, err = r.initExtensionDeclarations(md.GetExtension(), m, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return ms, nil
|
||||
}
|
||||
|
||||
// canBePacked returns whether the field can use packed encoding:
|
||||
// https://protobuf.dev/programming-guides/encoding/#packed
|
||||
func canBePacked(fd *descriptorpb.FieldDescriptorProto) bool {
|
||||
if fd.GetLabel() != descriptorpb.FieldDescriptorProto_LABEL_REPEATED {
|
||||
return false // not a repeated field
|
||||
}
|
||||
|
||||
switch protoreflect.Kind(fd.GetType()) {
|
||||
case protoreflect.MessageKind, protoreflect.GroupKind:
|
||||
return false // not a scalar type field
|
||||
|
||||
case protoreflect.StringKind, protoreflect.BytesKind:
|
||||
// string and bytes can explicitly not be declared as packed,
|
||||
// see https://protobuf.dev/programming-guides/encoding/#packed
|
||||
return false
|
||||
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func (r descsByName) initFieldsFromDescriptorProto(fds []*descriptorpb.FieldDescriptorProto, parent protoreflect.Descriptor, sb *strs.Builder) (fs []filedesc.Field, err error) {
|
||||
fs = make([]filedesc.Field, len(fds)) // allocate up-front to ensure stable pointers
|
||||
for i, fd := range fds {
|
||||
f := &fs[i]
|
||||
if f.L0, err = r.makeBase(f, parent, fd.GetName(), i, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f.L1.IsProto3Optional = fd.GetProto3Optional()
|
||||
if opts := fd.GetOptions(); opts != nil {
|
||||
opts = proto.Clone(opts).(*descriptorpb.FieldOptions)
|
||||
f.L1.Options = func() protoreflect.ProtoMessage { return opts }
|
||||
f.L1.IsWeak = opts.GetWeak()
|
||||
f.L1.HasPacked = opts.Packed != nil
|
||||
f.L1.IsPacked = opts.GetPacked()
|
||||
}
|
||||
f.L1.Number = protoreflect.FieldNumber(fd.GetNumber())
|
||||
f.L1.Cardinality = protoreflect.Cardinality(fd.GetLabel())
|
||||
if fd.Type != nil {
|
||||
f.L1.Kind = protoreflect.Kind(fd.GetType())
|
||||
}
|
||||
if fd.JsonName != nil {
|
||||
f.L1.StringName.InitJSON(fd.GetJsonName())
|
||||
}
|
||||
|
||||
if f.Base.L0.ParentFile.Syntax() == protoreflect.Editions {
|
||||
f.L1.EditionFeatures = mergeEditionFeatures(parent, fd.GetOptions().GetFeatures())
|
||||
|
||||
if f.L1.EditionFeatures.IsLegacyRequired {
|
||||
f.L1.Cardinality = protoreflect.Required
|
||||
}
|
||||
// We reuse the existing field because the old option `[packed =
|
||||
// true]` is mutually exclusive with the editions feature.
|
||||
if canBePacked(fd) {
|
||||
f.L1.HasPacked = true
|
||||
f.L1.IsPacked = f.L1.EditionFeatures.IsPacked
|
||||
}
|
||||
|
||||
// We pretend this option is always explicitly set because the only
|
||||
// use of HasEnforceUTF8 is to determine whether to use EnforceUTF8
|
||||
// or to return the appropriate default.
|
||||
// When using editions we either parse the option or resolve the
|
||||
// appropriate default here (instead of later when this option is
|
||||
// requested from the descriptor).
|
||||
// In proto2/proto3 syntax HasEnforceUTF8 might be false.
|
||||
f.L1.HasEnforceUTF8 = true
|
||||
f.L1.EnforceUTF8 = f.L1.EditionFeatures.IsUTF8Validated
|
||||
|
||||
if f.L1.Kind == protoreflect.MessageKind && f.L1.EditionFeatures.IsDelimitedEncoded {
|
||||
f.L1.Kind = protoreflect.GroupKind
|
||||
}
|
||||
}
|
||||
}
|
||||
return fs, nil
|
||||
}
|
||||
|
||||
func (r descsByName) initOneofsFromDescriptorProto(ods []*descriptorpb.OneofDescriptorProto, parent protoreflect.Descriptor, sb *strs.Builder) (os []filedesc.Oneof, err error) {
|
||||
os = make([]filedesc.Oneof, len(ods)) // allocate up-front to ensure stable pointers
|
||||
for i, od := range ods {
|
||||
o := &os[i]
|
||||
if o.L0, err = r.makeBase(o, parent, od.GetName(), i, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if opts := od.GetOptions(); opts != nil {
|
||||
opts = proto.Clone(opts).(*descriptorpb.OneofOptions)
|
||||
o.L1.Options = func() protoreflect.ProtoMessage { return opts }
|
||||
if parent.Syntax() == protoreflect.Editions {
|
||||
o.L1.EditionFeatures = mergeEditionFeatures(parent, opts.GetFeatures())
|
||||
}
|
||||
}
|
||||
}
|
||||
return os, nil
|
||||
}
|
||||
|
||||
func (r descsByName) initExtensionDeclarations(xds []*descriptorpb.FieldDescriptorProto, parent protoreflect.Descriptor, sb *strs.Builder) (xs []filedesc.Extension, err error) {
|
||||
xs = make([]filedesc.Extension, len(xds)) // allocate up-front to ensure stable pointers
|
||||
for i, xd := range xds {
|
||||
x := &xs[i]
|
||||
x.L2 = new(filedesc.ExtensionL2)
|
||||
if x.L0, err = r.makeBase(x, parent, xd.GetName(), i, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if opts := xd.GetOptions(); opts != nil {
|
||||
opts = proto.Clone(opts).(*descriptorpb.FieldOptions)
|
||||
x.L2.Options = func() protoreflect.ProtoMessage { return opts }
|
||||
x.L2.IsPacked = opts.GetPacked()
|
||||
}
|
||||
x.L1.Number = protoreflect.FieldNumber(xd.GetNumber())
|
||||
x.L1.Cardinality = protoreflect.Cardinality(xd.GetLabel())
|
||||
if xd.Type != nil {
|
||||
x.L1.Kind = protoreflect.Kind(xd.GetType())
|
||||
}
|
||||
if xd.JsonName != nil {
|
||||
x.L2.StringName.InitJSON(xd.GetJsonName())
|
||||
}
|
||||
}
|
||||
return xs, nil
|
||||
}
|
||||
|
||||
func (r descsByName) initServiceDeclarations(sds []*descriptorpb.ServiceDescriptorProto, parent protoreflect.Descriptor, sb *strs.Builder) (ss []filedesc.Service, err error) {
|
||||
ss = make([]filedesc.Service, len(sds)) // allocate up-front to ensure stable pointers
|
||||
for i, sd := range sds {
|
||||
s := &ss[i]
|
||||
s.L2 = new(filedesc.ServiceL2)
|
||||
if s.L0, err = r.makeBase(s, parent, sd.GetName(), i, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if opts := sd.GetOptions(); opts != nil {
|
||||
opts = proto.Clone(opts).(*descriptorpb.ServiceOptions)
|
||||
s.L2.Options = func() protoreflect.ProtoMessage { return opts }
|
||||
}
|
||||
if s.L2.Methods.List, err = r.initMethodsFromDescriptorProto(sd.GetMethod(), s, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return ss, nil
|
||||
}
|
||||
|
||||
func (r descsByName) initMethodsFromDescriptorProto(mds []*descriptorpb.MethodDescriptorProto, parent protoreflect.Descriptor, sb *strs.Builder) (ms []filedesc.Method, err error) {
|
||||
ms = make([]filedesc.Method, len(mds)) // allocate up-front to ensure stable pointers
|
||||
for i, md := range mds {
|
||||
m := &ms[i]
|
||||
if m.L0, err = r.makeBase(m, parent, md.GetName(), i, sb); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if opts := md.GetOptions(); opts != nil {
|
||||
opts = proto.Clone(opts).(*descriptorpb.MethodOptions)
|
||||
m.L1.Options = func() protoreflect.ProtoMessage { return opts }
|
||||
}
|
||||
m.L1.IsStreamingClient = md.GetClientStreaming()
|
||||
m.L1.IsStreamingServer = md.GetServerStreaming()
|
||||
}
|
||||
return ms, nil
|
||||
}
|
||||
|
||||
func (r descsByName) makeBase(child, parent protoreflect.Descriptor, name string, idx int, sb *strs.Builder) (filedesc.BaseL0, error) {
|
||||
if !protoreflect.Name(name).IsValid() {
|
||||
return filedesc.BaseL0{}, errors.New("descriptor %q has an invalid nested name: %q", parent.FullName(), name)
|
||||
}
|
||||
|
||||
// Derive the full name of the child.
|
||||
// Note that enum values are a sibling to the enum parent in the namespace.
|
||||
var fullName protoreflect.FullName
|
||||
if _, ok := parent.(protoreflect.EnumDescriptor); ok {
|
||||
fullName = sb.AppendFullName(parent.FullName().Parent(), protoreflect.Name(name))
|
||||
} else {
|
||||
fullName = sb.AppendFullName(parent.FullName(), protoreflect.Name(name))
|
||||
}
|
||||
if _, ok := r[fullName]; ok {
|
||||
return filedesc.BaseL0{}, errors.New("descriptor %q already declared", fullName)
|
||||
}
|
||||
r[fullName] = child
|
||||
|
||||
// TODO: Verify that the full name does not already exist in the resolver?
|
||||
// This is not as critical since most usages of NewFile will register
|
||||
// the created file back into the registry, which will perform this check.
|
||||
|
||||
return filedesc.BaseL0{
|
||||
FullName: fullName,
|
||||
ParentFile: parent.ParentFile().(*filedesc.File),
|
||||
Parent: parent,
|
||||
Index: idx,
|
||||
}, nil
|
||||
}
|
286
vendor/google.golang.org/protobuf/reflect/protodesc/desc_resolve.go
generated
vendored
286
vendor/google.golang.org/protobuf/reflect/protodesc/desc_resolve.go
generated
vendored
@ -1,286 +0,0 @@
|
||||
// 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 protodesc
|
||||
|
||||
import (
|
||||
"google.golang.org/protobuf/internal/encoding/defval"
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
"google.golang.org/protobuf/internal/filedesc"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/reflect/protoregistry"
|
||||
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
)
|
||||
|
||||
// resolver is a wrapper around a local registry of declarations within the file
|
||||
// and the remote resolver. The remote resolver is restricted to only return
|
||||
// descriptors that have been imported.
|
||||
type resolver struct {
|
||||
local descsByName
|
||||
remote Resolver
|
||||
imports importSet
|
||||
|
||||
allowUnresolvable bool
|
||||
}
|
||||
|
||||
func (r *resolver) resolveMessageDependencies(ms []filedesc.Message, mds []*descriptorpb.DescriptorProto) (err error) {
|
||||
for i, md := range mds {
|
||||
m := &ms[i]
|
||||
for j, fd := range md.GetField() {
|
||||
f := &m.L2.Fields.List[j]
|
||||
if f.L1.Cardinality == protoreflect.Required {
|
||||
m.L2.RequiredNumbers.List = append(m.L2.RequiredNumbers.List, f.L1.Number)
|
||||
}
|
||||
if fd.OneofIndex != nil {
|
||||
k := int(fd.GetOneofIndex())
|
||||
if !(0 <= k && k < len(md.GetOneofDecl())) {
|
||||
return errors.New("message field %q has an invalid oneof index: %d", f.FullName(), k)
|
||||
}
|
||||
o := &m.L2.Oneofs.List[k]
|
||||
f.L1.ContainingOneof = o
|
||||
o.L1.Fields.List = append(o.L1.Fields.List, f)
|
||||
}
|
||||
|
||||
if f.L1.Kind, f.L1.Enum, f.L1.Message, err = r.findTarget(f.Kind(), f.Parent().FullName(), partialName(fd.GetTypeName()), f.IsWeak()); err != nil {
|
||||
return errors.New("message field %q cannot resolve type: %v", f.FullName(), err)
|
||||
}
|
||||
if fd.DefaultValue != nil {
|
||||
v, ev, err := unmarshalDefault(fd.GetDefaultValue(), f, r.allowUnresolvable)
|
||||
if err != nil {
|
||||
return errors.New("message field %q has invalid default: %v", f.FullName(), err)
|
||||
}
|
||||
f.L1.Default = filedesc.DefaultValue(v, ev)
|
||||
}
|
||||
}
|
||||
|
||||
if err := r.resolveMessageDependencies(m.L1.Messages.List, md.GetNestedType()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := r.resolveExtensionDependencies(m.L1.Extensions.List, md.GetExtension()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *resolver) resolveExtensionDependencies(xs []filedesc.Extension, xds []*descriptorpb.FieldDescriptorProto) (err error) {
|
||||
for i, xd := range xds {
|
||||
x := &xs[i]
|
||||
if x.L1.Extendee, err = r.findMessageDescriptor(x.Parent().FullName(), partialName(xd.GetExtendee()), false); err != nil {
|
||||
return errors.New("extension field %q cannot resolve extendee: %v", x.FullName(), err)
|
||||
}
|
||||
if x.L1.Kind, x.L2.Enum, x.L2.Message, err = r.findTarget(x.Kind(), x.Parent().FullName(), partialName(xd.GetTypeName()), false); err != nil {
|
||||
return errors.New("extension field %q cannot resolve type: %v", x.FullName(), err)
|
||||
}
|
||||
if xd.DefaultValue != nil {
|
||||
v, ev, err := unmarshalDefault(xd.GetDefaultValue(), x, r.allowUnresolvable)
|
||||
if err != nil {
|
||||
return errors.New("extension field %q has invalid default: %v", x.FullName(), err)
|
||||
}
|
||||
x.L2.Default = filedesc.DefaultValue(v, ev)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *resolver) resolveServiceDependencies(ss []filedesc.Service, sds []*descriptorpb.ServiceDescriptorProto) (err error) {
|
||||
for i, sd := range sds {
|
||||
s := &ss[i]
|
||||
for j, md := range sd.GetMethod() {
|
||||
m := &s.L2.Methods.List[j]
|
||||
m.L1.Input, err = r.findMessageDescriptor(m.Parent().FullName(), partialName(md.GetInputType()), false)
|
||||
if err != nil {
|
||||
return errors.New("service method %q cannot resolve input: %v", m.FullName(), err)
|
||||
}
|
||||
m.L1.Output, err = r.findMessageDescriptor(s.FullName(), partialName(md.GetOutputType()), false)
|
||||
if err != nil {
|
||||
return errors.New("service method %q cannot resolve output: %v", m.FullName(), err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// findTarget finds an enum or message descriptor if k is an enum, message,
|
||||
// group, or unknown. If unknown, and the name could be resolved, the kind
|
||||
// returned kind is set based on the type of the resolved descriptor.
|
||||
func (r *resolver) findTarget(k protoreflect.Kind, scope protoreflect.FullName, ref partialName, isWeak bool) (protoreflect.Kind, protoreflect.EnumDescriptor, protoreflect.MessageDescriptor, error) {
|
||||
switch k {
|
||||
case protoreflect.EnumKind:
|
||||
ed, err := r.findEnumDescriptor(scope, ref, isWeak)
|
||||
if err != nil {
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
return k, ed, nil, nil
|
||||
case protoreflect.MessageKind, protoreflect.GroupKind:
|
||||
md, err := r.findMessageDescriptor(scope, ref, isWeak)
|
||||
if err != nil {
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
return k, nil, md, nil
|
||||
case 0:
|
||||
// Handle unspecified kinds (possible with parsers that operate
|
||||
// on a per-file basis without knowledge of dependencies).
|
||||
d, err := r.findDescriptor(scope, ref)
|
||||
if err == protoregistry.NotFound && (r.allowUnresolvable || isWeak) {
|
||||
return k, filedesc.PlaceholderEnum(ref.FullName()), filedesc.PlaceholderMessage(ref.FullName()), nil
|
||||
} else if err == protoregistry.NotFound {
|
||||
return 0, nil, nil, errors.New("%q not found", ref.FullName())
|
||||
} else if err != nil {
|
||||
return 0, nil, nil, err
|
||||
}
|
||||
switch d := d.(type) {
|
||||
case protoreflect.EnumDescriptor:
|
||||
return protoreflect.EnumKind, d, nil, nil
|
||||
case protoreflect.MessageDescriptor:
|
||||
return protoreflect.MessageKind, nil, d, nil
|
||||
default:
|
||||
return 0, nil, nil, errors.New("unknown kind")
|
||||
}
|
||||
default:
|
||||
if ref != "" {
|
||||
return 0, nil, nil, errors.New("target name cannot be specified for %v", k)
|
||||
}
|
||||
if !k.IsValid() {
|
||||
return 0, nil, nil, errors.New("invalid kind: %d", k)
|
||||
}
|
||||
return k, nil, nil, nil
|
||||
}
|
||||
}
|
||||
|
||||
// findDescriptor finds the descriptor by name,
|
||||
// which may be a relative name within some scope.
|
||||
//
|
||||
// Suppose the scope was "fizz.buzz" and the reference was "Foo.Bar",
|
||||
// then the following full names are searched:
|
||||
// - fizz.buzz.Foo.Bar
|
||||
// - fizz.Foo.Bar
|
||||
// - Foo.Bar
|
||||
func (r *resolver) findDescriptor(scope protoreflect.FullName, ref partialName) (protoreflect.Descriptor, error) {
|
||||
if !ref.IsValid() {
|
||||
return nil, errors.New("invalid name reference: %q", ref)
|
||||
}
|
||||
if ref.IsFull() {
|
||||
scope, ref = "", ref[1:]
|
||||
}
|
||||
var foundButNotImported protoreflect.Descriptor
|
||||
for {
|
||||
// Derive the full name to search.
|
||||
s := protoreflect.FullName(ref)
|
||||
if scope != "" {
|
||||
s = scope + "." + s
|
||||
}
|
||||
|
||||
// Check the current file for the descriptor.
|
||||
if d, ok := r.local[s]; ok {
|
||||
return d, nil
|
||||
}
|
||||
|
||||
// Check the remote registry for the descriptor.
|
||||
d, err := r.remote.FindDescriptorByName(s)
|
||||
if err == nil {
|
||||
// Only allow descriptors covered by one of the imports.
|
||||
if r.imports[d.ParentFile().Path()] {
|
||||
return d, nil
|
||||
}
|
||||
foundButNotImported = d
|
||||
} else if err != protoregistry.NotFound {
|
||||
return nil, errors.Wrap(err, "%q", s)
|
||||
}
|
||||
|
||||
// Continue on at a higher level of scoping.
|
||||
if scope == "" {
|
||||
if d := foundButNotImported; d != nil {
|
||||
return nil, errors.New("resolved %q, but %q is not imported", d.FullName(), d.ParentFile().Path())
|
||||
}
|
||||
return nil, protoregistry.NotFound
|
||||
}
|
||||
scope = scope.Parent()
|
||||
}
|
||||
}
|
||||
|
||||
func (r *resolver) findEnumDescriptor(scope protoreflect.FullName, ref partialName, isWeak bool) (protoreflect.EnumDescriptor, error) {
|
||||
d, err := r.findDescriptor(scope, ref)
|
||||
if err == protoregistry.NotFound && (r.allowUnresolvable || isWeak) {
|
||||
return filedesc.PlaceholderEnum(ref.FullName()), nil
|
||||
} else if err == protoregistry.NotFound {
|
||||
return nil, errors.New("%q not found", ref.FullName())
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ed, ok := d.(protoreflect.EnumDescriptor)
|
||||
if !ok {
|
||||
return nil, errors.New("resolved %q, but it is not an enum", d.FullName())
|
||||
}
|
||||
return ed, nil
|
||||
}
|
||||
|
||||
func (r *resolver) findMessageDescriptor(scope protoreflect.FullName, ref partialName, isWeak bool) (protoreflect.MessageDescriptor, error) {
|
||||
d, err := r.findDescriptor(scope, ref)
|
||||
if err == protoregistry.NotFound && (r.allowUnresolvable || isWeak) {
|
||||
return filedesc.PlaceholderMessage(ref.FullName()), nil
|
||||
} else if err == protoregistry.NotFound {
|
||||
return nil, errors.New("%q not found", ref.FullName())
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
md, ok := d.(protoreflect.MessageDescriptor)
|
||||
if !ok {
|
||||
return nil, errors.New("resolved %q, but it is not an message", d.FullName())
|
||||
}
|
||||
return md, nil
|
||||
}
|
||||
|
||||
// partialName is the partial name. A leading dot means that the name is full,
|
||||
// otherwise the name is relative to some current scope.
|
||||
// See google.protobuf.FieldDescriptorProto.type_name.
|
||||
type partialName string
|
||||
|
||||
func (s partialName) IsFull() bool {
|
||||
return len(s) > 0 && s[0] == '.'
|
||||
}
|
||||
|
||||
func (s partialName) IsValid() bool {
|
||||
if s.IsFull() {
|
||||
return protoreflect.FullName(s[1:]).IsValid()
|
||||
}
|
||||
return protoreflect.FullName(s).IsValid()
|
||||
}
|
||||
|
||||
const unknownPrefix = "*."
|
||||
|
||||
// FullName converts the partial name to a full name on a best-effort basis.
|
||||
// If relative, it creates an invalid full name, using a "*." prefix
|
||||
// to indicate that the start of the full name is unknown.
|
||||
func (s partialName) FullName() protoreflect.FullName {
|
||||
if s.IsFull() {
|
||||
return protoreflect.FullName(s[1:])
|
||||
}
|
||||
return protoreflect.FullName(unknownPrefix + s)
|
||||
}
|
||||
|
||||
func unmarshalDefault(s string, fd protoreflect.FieldDescriptor, allowUnresolvable bool) (protoreflect.Value, protoreflect.EnumValueDescriptor, error) {
|
||||
var evs protoreflect.EnumValueDescriptors
|
||||
if fd.Enum() != nil {
|
||||
evs = fd.Enum().Values()
|
||||
}
|
||||
v, ev, err := defval.Unmarshal(s, fd.Kind(), evs, defval.Descriptor)
|
||||
if err != nil && allowUnresolvable && evs != nil && protoreflect.Name(s).IsValid() {
|
||||
v = protoreflect.ValueOfEnum(0)
|
||||
if evs.Len() > 0 {
|
||||
v = protoreflect.ValueOfEnum(evs.Get(0).Number())
|
||||
}
|
||||
ev = filedesc.PlaceholderEnumValue(fd.Enum().FullName().Parent().Append(protoreflect.Name(s)))
|
||||
} else if err != nil {
|
||||
return v, ev, err
|
||||
}
|
||||
if !fd.HasPresence() {
|
||||
return v, ev, errors.New("cannot be specified with implicit field presence")
|
||||
}
|
||||
if fd.Kind() == protoreflect.MessageKind || fd.Kind() == protoreflect.GroupKind || fd.Cardinality() == protoreflect.Repeated {
|
||||
return v, ev, errors.New("cannot be specified on composite types")
|
||||
}
|
||||
return v, ev, nil
|
||||
}
|
374
vendor/google.golang.org/protobuf/reflect/protodesc/desc_validate.go
generated
vendored
374
vendor/google.golang.org/protobuf/reflect/protodesc/desc_validate.go
generated
vendored
@ -1,374 +0,0 @@
|
||||
// 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 protodesc
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"google.golang.org/protobuf/encoding/protowire"
|
||||
"google.golang.org/protobuf/internal/errors"
|
||||
"google.golang.org/protobuf/internal/filedesc"
|
||||
"google.golang.org/protobuf/internal/flags"
|
||||
"google.golang.org/protobuf/internal/genid"
|
||||
"google.golang.org/protobuf/internal/strs"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
)
|
||||
|
||||
func validateEnumDeclarations(es []filedesc.Enum, eds []*descriptorpb.EnumDescriptorProto) error {
|
||||
for i, ed := range eds {
|
||||
e := &es[i]
|
||||
if err := e.L2.ReservedNames.CheckValid(); err != nil {
|
||||
return errors.New("enum %q reserved names has %v", e.FullName(), err)
|
||||
}
|
||||
if err := e.L2.ReservedRanges.CheckValid(); err != nil {
|
||||
return errors.New("enum %q reserved ranges has %v", e.FullName(), err)
|
||||
}
|
||||
if len(ed.GetValue()) == 0 {
|
||||
return errors.New("enum %q must contain at least one value declaration", e.FullName())
|
||||
}
|
||||
allowAlias := ed.GetOptions().GetAllowAlias()
|
||||
foundAlias := false
|
||||
for i := 0; i < e.Values().Len(); i++ {
|
||||
v1 := e.Values().Get(i)
|
||||
if v2 := e.Values().ByNumber(v1.Number()); v1 != v2 {
|
||||
foundAlias = true
|
||||
if !allowAlias {
|
||||
return errors.New("enum %q has conflicting non-aliased values on number %d: %q with %q", e.FullName(), v1.Number(), v1.Name(), v2.Name())
|
||||
}
|
||||
}
|
||||
}
|
||||
if allowAlias && !foundAlias {
|
||||
return errors.New("enum %q allows aliases, but none were found", e.FullName())
|
||||
}
|
||||
if e.Syntax() == protoreflect.Proto3 {
|
||||
if v := e.Values().Get(0); v.Number() != 0 {
|
||||
return errors.New("enum %q using proto3 semantics must have zero number for the first value", v.FullName())
|
||||
}
|
||||
// Verify that value names in proto3 do not conflict if the
|
||||
// case-insensitive prefix is removed.
|
||||
// See protoc v3.8.0: src/google/protobuf/descriptor.cc:4991-5055
|
||||
names := map[string]protoreflect.EnumValueDescriptor{}
|
||||
prefix := strings.Replace(strings.ToLower(string(e.Name())), "_", "", -1)
|
||||
for i := 0; i < e.Values().Len(); i++ {
|
||||
v1 := e.Values().Get(i)
|
||||
s := strs.EnumValueName(strs.TrimEnumPrefix(string(v1.Name()), prefix))
|
||||
if v2, ok := names[s]; ok && v1.Number() != v2.Number() {
|
||||
return errors.New("enum %q using proto3 semantics has conflict: %q with %q", e.FullName(), v1.Name(), v2.Name())
|
||||
}
|
||||
names[s] = v1
|
||||
}
|
||||
}
|
||||
|
||||
for j, vd := range ed.GetValue() {
|
||||
v := &e.L2.Values.List[j]
|
||||
if vd.Number == nil {
|
||||
return errors.New("enum value %q must have a specified number", v.FullName())
|
||||
}
|
||||
if e.L2.ReservedNames.Has(v.Name()) {
|
||||
return errors.New("enum value %q must not use reserved name", v.FullName())
|
||||
}
|
||||
if e.L2.ReservedRanges.Has(v.Number()) {
|
||||
return errors.New("enum value %q must not use reserved number %d", v.FullName(), v.Number())
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateMessageDeclarations(ms []filedesc.Message, mds []*descriptorpb.DescriptorProto) error {
|
||||
for i, md := range mds {
|
||||
m := &ms[i]
|
||||
|
||||
// Handle the message descriptor itself.
|
||||
isMessageSet := md.GetOptions().GetMessageSetWireFormat()
|
||||
if err := m.L2.ReservedNames.CheckValid(); err != nil {
|
||||
return errors.New("message %q reserved names has %v", m.FullName(), err)
|
||||
}
|
||||
if err := m.L2.ReservedRanges.CheckValid(isMessageSet); err != nil {
|
||||
return errors.New("message %q reserved ranges has %v", m.FullName(), err)
|
||||
}
|
||||
if err := m.L2.ExtensionRanges.CheckValid(isMessageSet); err != nil {
|
||||
return errors.New("message %q extension ranges has %v", m.FullName(), err)
|
||||
}
|
||||
if err := (*filedesc.FieldRanges).CheckOverlap(&m.L2.ReservedRanges, &m.L2.ExtensionRanges); err != nil {
|
||||
return errors.New("message %q reserved and extension ranges has %v", m.FullName(), err)
|
||||
}
|
||||
for i := 0; i < m.Fields().Len(); i++ {
|
||||
f1 := m.Fields().Get(i)
|
||||
if f2 := m.Fields().ByNumber(f1.Number()); f1 != f2 {
|
||||
return errors.New("message %q has conflicting fields: %q with %q", m.FullName(), f1.Name(), f2.Name())
|
||||
}
|
||||
}
|
||||
if isMessageSet && !flags.ProtoLegacy {
|
||||
return errors.New("message %q is a MessageSet, which is a legacy proto1 feature that is no longer supported", m.FullName())
|
||||
}
|
||||
if isMessageSet && (m.Syntax() == protoreflect.Proto3 || m.Fields().Len() > 0 || m.ExtensionRanges().Len() == 0) {
|
||||
return errors.New("message %q is an invalid proto1 MessageSet", m.FullName())
|
||||
}
|
||||
if m.Syntax() == protoreflect.Proto3 {
|
||||
if m.ExtensionRanges().Len() > 0 {
|
||||
return errors.New("message %q using proto3 semantics cannot have extension ranges", m.FullName())
|
||||
}
|
||||
// Verify that field names in proto3 do not conflict if lowercased
|
||||
// with all underscores removed.
|
||||
// See protoc v3.8.0: src/google/protobuf/descriptor.cc:5830-5847
|
||||
names := map[string]protoreflect.FieldDescriptor{}
|
||||
for i := 0; i < m.Fields().Len(); i++ {
|
||||
f1 := m.Fields().Get(i)
|
||||
s := strings.Replace(strings.ToLower(string(f1.Name())), "_", "", -1)
|
||||
if f2, ok := names[s]; ok {
|
||||
return errors.New("message %q using proto3 semantics has conflict: %q with %q", m.FullName(), f1.Name(), f2.Name())
|
||||
}
|
||||
names[s] = f1
|
||||
}
|
||||
}
|
||||
|
||||
for j, fd := range md.GetField() {
|
||||
f := &m.L2.Fields.List[j]
|
||||
if m.L2.ReservedNames.Has(f.Name()) {
|
||||
return errors.New("message field %q must not use reserved name", f.FullName())
|
||||
}
|
||||
if !f.Number().IsValid() {
|
||||
return errors.New("message field %q has an invalid number: %d", f.FullName(), f.Number())
|
||||
}
|
||||
if !f.Cardinality().IsValid() {
|
||||
return errors.New("message field %q has an invalid cardinality: %d", f.FullName(), f.Cardinality())
|
||||
}
|
||||
if m.L2.ReservedRanges.Has(f.Number()) {
|
||||
return errors.New("message field %q must not use reserved number %d", f.FullName(), f.Number())
|
||||
}
|
||||
if m.L2.ExtensionRanges.Has(f.Number()) {
|
||||
return errors.New("message field %q with number %d in extension range", f.FullName(), f.Number())
|
||||
}
|
||||
if fd.Extendee != nil {
|
||||
return errors.New("message field %q may not have extendee: %q", f.FullName(), fd.GetExtendee())
|
||||
}
|
||||
if f.L1.IsProto3Optional {
|
||||
if f.Syntax() != protoreflect.Proto3 {
|
||||
return errors.New("message field %q under proto3 optional semantics must be specified in the proto3 syntax", f.FullName())
|
||||
}
|
||||
if f.Cardinality() != protoreflect.Optional {
|
||||
return errors.New("message field %q under proto3 optional semantics must have optional cardinality", f.FullName())
|
||||
}
|
||||
if f.ContainingOneof() != nil && f.ContainingOneof().Fields().Len() != 1 {
|
||||
return errors.New("message field %q under proto3 optional semantics must be within a single element oneof", f.FullName())
|
||||
}
|
||||
}
|
||||
if f.IsWeak() && !flags.ProtoLegacy {
|
||||
return errors.New("message field %q is a weak field, which is a legacy proto1 feature that is no longer supported", f.FullName())
|
||||
}
|
||||
if f.IsWeak() && (f.Syntax() != protoreflect.Proto2 || !isOptionalMessage(f) || f.ContainingOneof() != nil) {
|
||||
return errors.New("message field %q may only be weak for an optional message", f.FullName())
|
||||
}
|
||||
if f.IsPacked() && !isPackable(f) {
|
||||
return errors.New("message field %q is not packable", f.FullName())
|
||||
}
|
||||
if err := checkValidGroup(f); err != nil {
|
||||
return errors.New("message field %q is an invalid group: %v", f.FullName(), err)
|
||||
}
|
||||
if err := checkValidMap(f); err != nil {
|
||||
return errors.New("message field %q is an invalid map: %v", f.FullName(), err)
|
||||
}
|
||||
if f.Syntax() == protoreflect.Proto3 {
|
||||
if f.Cardinality() == protoreflect.Required {
|
||||
return errors.New("message field %q using proto3 semantics cannot be required", f.FullName())
|
||||
}
|
||||
if f.Enum() != nil && !f.Enum().IsPlaceholder() && f.Enum().Syntax() != protoreflect.Proto3 {
|
||||
return errors.New("message field %q using proto3 semantics may only depend on a proto3 enum", f.FullName())
|
||||
}
|
||||
}
|
||||
}
|
||||
seenSynthetic := false // synthetic oneofs for proto3 optional must come after real oneofs
|
||||
for j := range md.GetOneofDecl() {
|
||||
o := &m.L2.Oneofs.List[j]
|
||||
if o.Fields().Len() == 0 {
|
||||
return errors.New("message oneof %q must contain at least one field declaration", o.FullName())
|
||||
}
|
||||
if n := o.Fields().Len(); n-1 != (o.Fields().Get(n-1).Index() - o.Fields().Get(0).Index()) {
|
||||
return errors.New("message oneof %q must have consecutively declared fields", o.FullName())
|
||||
}
|
||||
|
||||
if o.IsSynthetic() {
|
||||
seenSynthetic = true
|
||||
continue
|
||||
}
|
||||
if !o.IsSynthetic() && seenSynthetic {
|
||||
return errors.New("message oneof %q must be declared before synthetic oneofs", o.FullName())
|
||||
}
|
||||
|
||||
for i := 0; i < o.Fields().Len(); i++ {
|
||||
f := o.Fields().Get(i)
|
||||
if f.Cardinality() != protoreflect.Optional {
|
||||
return errors.New("message field %q belongs in a oneof and must be optional", f.FullName())
|
||||
}
|
||||
if f.IsWeak() {
|
||||
return errors.New("message field %q belongs in a oneof and must not be a weak reference", f.FullName())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err := validateEnumDeclarations(m.L1.Enums.List, md.GetEnumType()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateMessageDeclarations(m.L1.Messages.List, md.GetNestedType()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateExtensionDeclarations(m.L1.Extensions.List, md.GetExtension()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateExtensionDeclarations(xs []filedesc.Extension, xds []*descriptorpb.FieldDescriptorProto) error {
|
||||
for i, xd := range xds {
|
||||
x := &xs[i]
|
||||
// NOTE: Avoid using the IsValid method since extensions to MessageSet
|
||||
// may have a field number higher than normal. This check only verifies
|
||||
// that the number is not negative or reserved. We check again later
|
||||
// if we know that the extendee is definitely not a MessageSet.
|
||||
if n := x.Number(); n < 0 || (protowire.FirstReservedNumber <= n && n <= protowire.LastReservedNumber) {
|
||||
return errors.New("extension field %q has an invalid number: %d", x.FullName(), x.Number())
|
||||
}
|
||||
if !x.Cardinality().IsValid() || x.Cardinality() == protoreflect.Required {
|
||||
return errors.New("extension field %q has an invalid cardinality: %d", x.FullName(), x.Cardinality())
|
||||
}
|
||||
if xd.JsonName != nil {
|
||||
// A bug in older versions of protoc would always populate the
|
||||
// "json_name" option for extensions when it is meaningless.
|
||||
// When it did so, it would always use the camel-cased field name.
|
||||
if xd.GetJsonName() != strs.JSONCamelCase(string(x.Name())) {
|
||||
return errors.New("extension field %q may not have an explicitly set JSON name: %q", x.FullName(), xd.GetJsonName())
|
||||
}
|
||||
}
|
||||
if xd.OneofIndex != nil {
|
||||
return errors.New("extension field %q may not be part of a oneof", x.FullName())
|
||||
}
|
||||
if md := x.ContainingMessage(); !md.IsPlaceholder() {
|
||||
if !md.ExtensionRanges().Has(x.Number()) {
|
||||
return errors.New("extension field %q extends %q with non-extension field number: %d", x.FullName(), md.FullName(), x.Number())
|
||||
}
|
||||
isMessageSet := md.Options().(*descriptorpb.MessageOptions).GetMessageSetWireFormat()
|
||||
if isMessageSet && !isOptionalMessage(x) {
|
||||
return errors.New("extension field %q extends MessageSet and must be an optional message", x.FullName())
|
||||
}
|
||||
if !isMessageSet && !x.Number().IsValid() {
|
||||
return errors.New("extension field %q has an invalid number: %d", x.FullName(), x.Number())
|
||||
}
|
||||
}
|
||||
if xd.GetOptions().GetWeak() {
|
||||
return errors.New("extension field %q cannot be a weak reference", x.FullName())
|
||||
}
|
||||
if x.IsPacked() && !isPackable(x) {
|
||||
return errors.New("extension field %q is not packable", x.FullName())
|
||||
}
|
||||
if err := checkValidGroup(x); err != nil {
|
||||
return errors.New("extension field %q is an invalid group: %v", x.FullName(), err)
|
||||
}
|
||||
if md := x.Message(); md != nil && md.IsMapEntry() {
|
||||
return errors.New("extension field %q cannot be a map entry", x.FullName())
|
||||
}
|
||||
if x.Syntax() == protoreflect.Proto3 {
|
||||
switch x.ContainingMessage().FullName() {
|
||||
case (*descriptorpb.FileOptions)(nil).ProtoReflect().Descriptor().FullName():
|
||||
case (*descriptorpb.EnumOptions)(nil).ProtoReflect().Descriptor().FullName():
|
||||
case (*descriptorpb.EnumValueOptions)(nil).ProtoReflect().Descriptor().FullName():
|
||||
case (*descriptorpb.MessageOptions)(nil).ProtoReflect().Descriptor().FullName():
|
||||
case (*descriptorpb.FieldOptions)(nil).ProtoReflect().Descriptor().FullName():
|
||||
case (*descriptorpb.OneofOptions)(nil).ProtoReflect().Descriptor().FullName():
|
||||
case (*descriptorpb.ExtensionRangeOptions)(nil).ProtoReflect().Descriptor().FullName():
|
||||
case (*descriptorpb.ServiceOptions)(nil).ProtoReflect().Descriptor().FullName():
|
||||
case (*descriptorpb.MethodOptions)(nil).ProtoReflect().Descriptor().FullName():
|
||||
default:
|
||||
return errors.New("extension field %q cannot be declared in proto3 unless extended descriptor options", x.FullName())
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// isOptionalMessage reports whether this is an optional message.
|
||||
// If the kind is unknown, it is assumed to be a message.
|
||||
func isOptionalMessage(fd protoreflect.FieldDescriptor) bool {
|
||||
return (fd.Kind() == 0 || fd.Kind() == protoreflect.MessageKind) && fd.Cardinality() == protoreflect.Optional
|
||||
}
|
||||
|
||||
// isPackable checks whether the pack option can be specified.
|
||||
func isPackable(fd protoreflect.FieldDescriptor) bool {
|
||||
switch fd.Kind() {
|
||||
case protoreflect.StringKind, protoreflect.BytesKind, protoreflect.MessageKind, protoreflect.GroupKind:
|
||||
return false
|
||||
}
|
||||
return fd.IsList()
|
||||
}
|
||||
|
||||
// checkValidGroup reports whether fd is a valid group according to the same
|
||||
// rules that protoc imposes.
|
||||
func checkValidGroup(fd protoreflect.FieldDescriptor) error {
|
||||
md := fd.Message()
|
||||
switch {
|
||||
case fd.Kind() != protoreflect.GroupKind:
|
||||
return nil
|
||||
case fd.Syntax() == protoreflect.Proto3:
|
||||
return errors.New("invalid under proto3 semantics")
|
||||
case md == nil || md.IsPlaceholder():
|
||||
return errors.New("message must be resolvable")
|
||||
case fd.FullName().Parent() != md.FullName().Parent():
|
||||
return errors.New("message and field must be declared in the same scope")
|
||||
case !unicode.IsUpper(rune(md.Name()[0])):
|
||||
return errors.New("message name must start with an uppercase")
|
||||
case fd.Name() != protoreflect.Name(strings.ToLower(string(md.Name()))):
|
||||
return errors.New("field name must be lowercased form of the message name")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkValidMap checks whether the field is a valid map according to the same
|
||||
// rules that protoc imposes.
|
||||
// See protoc v3.8.0: src/google/protobuf/descriptor.cc:6045-6115
|
||||
func checkValidMap(fd protoreflect.FieldDescriptor) error {
|
||||
md := fd.Message()
|
||||
switch {
|
||||
case md == nil || !md.IsMapEntry():
|
||||
return nil
|
||||
case fd.FullName().Parent() != md.FullName().Parent():
|
||||
return errors.New("message and field must be declared in the same scope")
|
||||
case md.Name() != protoreflect.Name(strs.MapEntryName(string(fd.Name()))):
|
||||
return errors.New("incorrect implicit map entry name")
|
||||
case fd.Cardinality() != protoreflect.Repeated:
|
||||
return errors.New("field must be repeated")
|
||||
case md.Fields().Len() != 2:
|
||||
return errors.New("message must have exactly two fields")
|
||||
case md.ExtensionRanges().Len() > 0:
|
||||
return errors.New("message must not have any extension ranges")
|
||||
case md.Enums().Len()+md.Messages().Len()+md.Extensions().Len() > 0:
|
||||
return errors.New("message must not have any nested declarations")
|
||||
}
|
||||
kf := md.Fields().Get(0)
|
||||
vf := md.Fields().Get(1)
|
||||
switch {
|
||||
case kf.Name() != genid.MapEntry_Key_field_name || kf.Number() != genid.MapEntry_Key_field_number || kf.Cardinality() != protoreflect.Optional || kf.ContainingOneof() != nil || kf.HasDefault():
|
||||
return errors.New("invalid key field")
|
||||
case vf.Name() != genid.MapEntry_Value_field_name || vf.Number() != genid.MapEntry_Value_field_number || vf.Cardinality() != protoreflect.Optional || vf.ContainingOneof() != nil || vf.HasDefault():
|
||||
return errors.New("invalid value field")
|
||||
}
|
||||
switch kf.Kind() {
|
||||
case protoreflect.BoolKind: // bool
|
||||
case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: // int32
|
||||
case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: // int64
|
||||
case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: // uint32
|
||||
case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: // uint64
|
||||
case protoreflect.StringKind: // string
|
||||
default:
|
||||
return errors.New("invalid key kind: %v", kf.Kind())
|
||||
}
|
||||
if e := vf.Enum(); e != nil && e.Values().Len() > 0 && e.Values().Get(0).Number() != 0 {
|
||||
return errors.New("map enum value must have zero number for the first value")
|
||||
}
|
||||
return nil
|
||||
}
|
148
vendor/google.golang.org/protobuf/reflect/protodesc/editions.go
generated
vendored
148
vendor/google.golang.org/protobuf/reflect/protodesc/editions.go
generated
vendored
@ -1,148 +0,0 @@
|
||||
// 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 protodesc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"google.golang.org/protobuf/internal/editiondefaults"
|
||||
"google.golang.org/protobuf/internal/filedesc"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
gofeaturespb "google.golang.org/protobuf/types/gofeaturespb"
|
||||
)
|
||||
|
||||
const (
|
||||
SupportedEditionsMinimum = descriptorpb.Edition_EDITION_PROTO2
|
||||
SupportedEditionsMaximum = descriptorpb.Edition_EDITION_2023
|
||||
)
|
||||
|
||||
var defaults = &descriptorpb.FeatureSetDefaults{}
|
||||
var defaultsCacheMu sync.Mutex
|
||||
var defaultsCache = make(map[filedesc.Edition]*descriptorpb.FeatureSet)
|
||||
|
||||
func init() {
|
||||
err := proto.Unmarshal(editiondefaults.Defaults, defaults)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "unmarshal editions defaults: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func fromEditionProto(epb descriptorpb.Edition) filedesc.Edition {
|
||||
return filedesc.Edition(epb)
|
||||
}
|
||||
|
||||
func toEditionProto(ed filedesc.Edition) descriptorpb.Edition {
|
||||
switch ed {
|
||||
case filedesc.EditionUnknown:
|
||||
return descriptorpb.Edition_EDITION_UNKNOWN
|
||||
case filedesc.EditionProto2:
|
||||
return descriptorpb.Edition_EDITION_PROTO2
|
||||
case filedesc.EditionProto3:
|
||||
return descriptorpb.Edition_EDITION_PROTO3
|
||||
case filedesc.Edition2023:
|
||||
return descriptorpb.Edition_EDITION_2023
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown value for edition: %v", ed))
|
||||
}
|
||||
}
|
||||
|
||||
func getFeatureSetFor(ed filedesc.Edition) *descriptorpb.FeatureSet {
|
||||
defaultsCacheMu.Lock()
|
||||
defer defaultsCacheMu.Unlock()
|
||||
if def, ok := defaultsCache[ed]; ok {
|
||||
return def
|
||||
}
|
||||
edpb := toEditionProto(ed)
|
||||
if defaults.GetMinimumEdition() > edpb || defaults.GetMaximumEdition() < edpb {
|
||||
// This should never happen protodesc.(FileOptions).New would fail when
|
||||
// initializing the file descriptor.
|
||||
// This most likely means the embedded defaults were not updated.
|
||||
fmt.Fprintf(os.Stderr, "internal error: unsupported edition %v (did you forget to update the embedded defaults (i.e. the bootstrap descriptor proto)?)\n", edpb)
|
||||
os.Exit(1)
|
||||
}
|
||||
fs := defaults.GetDefaults()[0].GetFeatures()
|
||||
// Using a linear search for now.
|
||||
// Editions are guaranteed to be sorted and thus we could use a binary search.
|
||||
// Given that there are only a handful of editions (with one more per year)
|
||||
// there is not much reason to use a binary search.
|
||||
for _, def := range defaults.GetDefaults() {
|
||||
if def.GetEdition() <= edpb {
|
||||
fs = def.GetFeatures()
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
defaultsCache[ed] = fs
|
||||
return fs
|
||||
}
|
||||
|
||||
// mergeEditionFeatures merges the parent and child feature sets. This function
|
||||
// should be used when initializing Go descriptors from descriptor protos which
|
||||
// is why the parent is a filedesc.EditionsFeatures (Go representation) while
|
||||
// the child is a descriptorproto.FeatureSet (protoc representation).
|
||||
// Any feature set by the child overwrites what is set by the parent.
|
||||
func mergeEditionFeatures(parentDesc protoreflect.Descriptor, child *descriptorpb.FeatureSet) filedesc.EditionFeatures {
|
||||
var parentFS filedesc.EditionFeatures
|
||||
switch p := parentDesc.(type) {
|
||||
case *filedesc.File:
|
||||
parentFS = p.L1.EditionFeatures
|
||||
case *filedesc.Message:
|
||||
parentFS = p.L1.EditionFeatures
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown parent type %T", parentDesc))
|
||||
}
|
||||
if child == nil {
|
||||
return parentFS
|
||||
}
|
||||
if fp := child.FieldPresence; fp != nil {
|
||||
parentFS.IsFieldPresence = *fp == descriptorpb.FeatureSet_LEGACY_REQUIRED ||
|
||||
*fp == descriptorpb.FeatureSet_EXPLICIT
|
||||
parentFS.IsLegacyRequired = *fp == descriptorpb.FeatureSet_LEGACY_REQUIRED
|
||||
}
|
||||
if et := child.EnumType; et != nil {
|
||||
parentFS.IsOpenEnum = *et == descriptorpb.FeatureSet_OPEN
|
||||
}
|
||||
|
||||
if rfe := child.RepeatedFieldEncoding; rfe != nil {
|
||||
parentFS.IsPacked = *rfe == descriptorpb.FeatureSet_PACKED
|
||||
}
|
||||
|
||||
if utf8val := child.Utf8Validation; utf8val != nil {
|
||||
parentFS.IsUTF8Validated = *utf8val == descriptorpb.FeatureSet_VERIFY
|
||||
}
|
||||
|
||||
if me := child.MessageEncoding; me != nil {
|
||||
parentFS.IsDelimitedEncoded = *me == descriptorpb.FeatureSet_DELIMITED
|
||||
}
|
||||
|
||||
if jf := child.JsonFormat; jf != nil {
|
||||
parentFS.IsJSONCompliant = *jf == descriptorpb.FeatureSet_ALLOW
|
||||
}
|
||||
|
||||
if goFeatures, ok := proto.GetExtension(child, gofeaturespb.E_Go).(*gofeaturespb.GoFeatures); ok && goFeatures != nil {
|
||||
if luje := goFeatures.LegacyUnmarshalJsonEnum; luje != nil {
|
||||
parentFS.GenerateLegacyUnmarshalJSON = *luje
|
||||
}
|
||||
}
|
||||
|
||||
return parentFS
|
||||
}
|
||||
|
||||
// initFileDescFromFeatureSet initializes editions related fields in fd based
|
||||
// on fs. If fs is nil it is assumed to be an empty featureset and all fields
|
||||
// will be initialized with the appropriate default. fd.L1.Edition must be set
|
||||
// before calling this function.
|
||||
func initFileDescFromFeatureSet(fd *filedesc.File, fs *descriptorpb.FeatureSet) {
|
||||
dfs := getFeatureSetFor(fd.L1.Edition)
|
||||
// initialize the featureset with the defaults
|
||||
fd.L1.EditionFeatures = mergeEditionFeatures(fd, dfs)
|
||||
// overwrite any options explicitly specified
|
||||
fd.L1.EditionFeatures = mergeEditionFeatures(fd, fs)
|
||||
}
|
252
vendor/google.golang.org/protobuf/reflect/protodesc/proto.go
generated
vendored
252
vendor/google.golang.org/protobuf/reflect/protodesc/proto.go
generated
vendored
@ -1,252 +0,0 @@
|
||||
// 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 protodesc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/protobuf/internal/encoding/defval"
|
||||
"google.golang.org/protobuf/internal/strs"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/reflect/protoreflect"
|
||||
|
||||
"google.golang.org/protobuf/types/descriptorpb"
|
||||
)
|
||||
|
||||
// ToFileDescriptorProto copies a [protoreflect.FileDescriptor] into a
|
||||
// google.protobuf.FileDescriptorProto message.
|
||||
func ToFileDescriptorProto(file protoreflect.FileDescriptor) *descriptorpb.FileDescriptorProto {
|
||||
p := &descriptorpb.FileDescriptorProto{
|
||||
Name: proto.String(file.Path()),
|
||||
Options: proto.Clone(file.Options()).(*descriptorpb.FileOptions),
|
||||
}
|
||||
if file.Package() != "" {
|
||||
p.Package = proto.String(string(file.Package()))
|
||||
}
|
||||
for i, imports := 0, file.Imports(); i < imports.Len(); i++ {
|
||||
imp := imports.Get(i)
|
||||
p.Dependency = append(p.Dependency, imp.Path())
|
||||
if imp.IsPublic {
|
||||
p.PublicDependency = append(p.PublicDependency, int32(i))
|
||||
}
|
||||
if imp.IsWeak {
|
||||
p.WeakDependency = append(p.WeakDependency, int32(i))
|
||||
}
|
||||
}
|
||||
for i, locs := 0, file.SourceLocations(); i < locs.Len(); i++ {
|
||||
loc := locs.Get(i)
|
||||
l := &descriptorpb.SourceCodeInfo_Location{}
|
||||
l.Path = append(l.Path, loc.Path...)
|
||||
if loc.StartLine == loc.EndLine {
|
||||
l.Span = []int32{int32(loc.StartLine), int32(loc.StartColumn), int32(loc.EndColumn)}
|
||||
} else {
|
||||
l.Span = []int32{int32(loc.StartLine), int32(loc.StartColumn), int32(loc.EndLine), int32(loc.EndColumn)}
|
||||
}
|
||||
l.LeadingDetachedComments = append([]string(nil), loc.LeadingDetachedComments...)
|
||||
if loc.LeadingComments != "" {
|
||||
l.LeadingComments = proto.String(loc.LeadingComments)
|
||||
}
|
||||
if loc.TrailingComments != "" {
|
||||
l.TrailingComments = proto.String(loc.TrailingComments)
|
||||
}
|
||||
if p.SourceCodeInfo == nil {
|
||||
p.SourceCodeInfo = &descriptorpb.SourceCodeInfo{}
|
||||
}
|
||||
p.SourceCodeInfo.Location = append(p.SourceCodeInfo.Location, l)
|
||||
|
||||
}
|
||||
for i, messages := 0, file.Messages(); i < messages.Len(); i++ {
|
||||
p.MessageType = append(p.MessageType, ToDescriptorProto(messages.Get(i)))
|
||||
}
|
||||
for i, enums := 0, file.Enums(); i < enums.Len(); i++ {
|
||||
p.EnumType = append(p.EnumType, ToEnumDescriptorProto(enums.Get(i)))
|
||||
}
|
||||
for i, services := 0, file.Services(); i < services.Len(); i++ {
|
||||
p.Service = append(p.Service, ToServiceDescriptorProto(services.Get(i)))
|
||||
}
|
||||
for i, exts := 0, file.Extensions(); i < exts.Len(); i++ {
|
||||
p.Extension = append(p.Extension, ToFieldDescriptorProto(exts.Get(i)))
|
||||
}
|
||||
if syntax := file.Syntax(); syntax != protoreflect.Proto2 && syntax.IsValid() {
|
||||
p.Syntax = proto.String(file.Syntax().String())
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// ToDescriptorProto copies a [protoreflect.MessageDescriptor] into a
|
||||
// google.protobuf.DescriptorProto message.
|
||||
func ToDescriptorProto(message protoreflect.MessageDescriptor) *descriptorpb.DescriptorProto {
|
||||
p := &descriptorpb.DescriptorProto{
|
||||
Name: proto.String(string(message.Name())),
|
||||
Options: proto.Clone(message.Options()).(*descriptorpb.MessageOptions),
|
||||
}
|
||||
for i, fields := 0, message.Fields(); i < fields.Len(); i++ {
|
||||
p.Field = append(p.Field, ToFieldDescriptorProto(fields.Get(i)))
|
||||
}
|
||||
for i, exts := 0, message.Extensions(); i < exts.Len(); i++ {
|
||||
p.Extension = append(p.Extension, ToFieldDescriptorProto(exts.Get(i)))
|
||||
}
|
||||
for i, messages := 0, message.Messages(); i < messages.Len(); i++ {
|
||||
p.NestedType = append(p.NestedType, ToDescriptorProto(messages.Get(i)))
|
||||
}
|
||||
for i, enums := 0, message.Enums(); i < enums.Len(); i++ {
|
||||
p.EnumType = append(p.EnumType, ToEnumDescriptorProto(enums.Get(i)))
|
||||
}
|
||||
for i, xranges := 0, message.ExtensionRanges(); i < xranges.Len(); i++ {
|
||||
xrange := xranges.Get(i)
|
||||
p.ExtensionRange = append(p.ExtensionRange, &descriptorpb.DescriptorProto_ExtensionRange{
|
||||
Start: proto.Int32(int32(xrange[0])),
|
||||
End: proto.Int32(int32(xrange[1])),
|
||||
Options: proto.Clone(message.ExtensionRangeOptions(i)).(*descriptorpb.ExtensionRangeOptions),
|
||||
})
|
||||
}
|
||||
for i, oneofs := 0, message.Oneofs(); i < oneofs.Len(); i++ {
|
||||
p.OneofDecl = append(p.OneofDecl, ToOneofDescriptorProto(oneofs.Get(i)))
|
||||
}
|
||||
for i, ranges := 0, message.ReservedRanges(); i < ranges.Len(); i++ {
|
||||
rrange := ranges.Get(i)
|
||||
p.ReservedRange = append(p.ReservedRange, &descriptorpb.DescriptorProto_ReservedRange{
|
||||
Start: proto.Int32(int32(rrange[0])),
|
||||
End: proto.Int32(int32(rrange[1])),
|
||||
})
|
||||
}
|
||||
for i, names := 0, message.ReservedNames(); i < names.Len(); i++ {
|
||||
p.ReservedName = append(p.ReservedName, string(names.Get(i)))
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// ToFieldDescriptorProto copies a [protoreflect.FieldDescriptor] into a
|
||||
// google.protobuf.FieldDescriptorProto message.
|
||||
func ToFieldDescriptorProto(field protoreflect.FieldDescriptor) *descriptorpb.FieldDescriptorProto {
|
||||
p := &descriptorpb.FieldDescriptorProto{
|
||||
Name: proto.String(string(field.Name())),
|
||||
Number: proto.Int32(int32(field.Number())),
|
||||
Label: descriptorpb.FieldDescriptorProto_Label(field.Cardinality()).Enum(),
|
||||
Options: proto.Clone(field.Options()).(*descriptorpb.FieldOptions),
|
||||
}
|
||||
if field.IsExtension() {
|
||||
p.Extendee = fullNameOf(field.ContainingMessage())
|
||||
}
|
||||
if field.Kind().IsValid() {
|
||||
p.Type = descriptorpb.FieldDescriptorProto_Type(field.Kind()).Enum()
|
||||
}
|
||||
if field.Enum() != nil {
|
||||
p.TypeName = fullNameOf(field.Enum())
|
||||
}
|
||||
if field.Message() != nil {
|
||||
p.TypeName = fullNameOf(field.Message())
|
||||
}
|
||||
if field.HasJSONName() {
|
||||
// A bug in older versions of protoc would always populate the
|
||||
// "json_name" option for extensions when it is meaningless.
|
||||
// When it did so, it would always use the camel-cased field name.
|
||||
if field.IsExtension() {
|
||||
p.JsonName = proto.String(strs.JSONCamelCase(string(field.Name())))
|
||||
} else {
|
||||
p.JsonName = proto.String(field.JSONName())
|
||||
}
|
||||
}
|
||||
if field.Syntax() == protoreflect.Proto3 && field.HasOptionalKeyword() {
|
||||
p.Proto3Optional = proto.Bool(true)
|
||||
}
|
||||
if field.HasDefault() {
|
||||
def, err := defval.Marshal(field.Default(), field.DefaultEnumValue(), field.Kind(), defval.Descriptor)
|
||||
if err != nil && field.DefaultEnumValue() != nil {
|
||||
def = string(field.DefaultEnumValue().Name()) // occurs for unresolved enum values
|
||||
} else if err != nil {
|
||||
panic(fmt.Sprintf("%v: %v", field.FullName(), err))
|
||||
}
|
||||
p.DefaultValue = proto.String(def)
|
||||
}
|
||||
if oneof := field.ContainingOneof(); oneof != nil {
|
||||
p.OneofIndex = proto.Int32(int32(oneof.Index()))
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// ToOneofDescriptorProto copies a [protoreflect.OneofDescriptor] into a
|
||||
// google.protobuf.OneofDescriptorProto message.
|
||||
func ToOneofDescriptorProto(oneof protoreflect.OneofDescriptor) *descriptorpb.OneofDescriptorProto {
|
||||
return &descriptorpb.OneofDescriptorProto{
|
||||
Name: proto.String(string(oneof.Name())),
|
||||
Options: proto.Clone(oneof.Options()).(*descriptorpb.OneofOptions),
|
||||
}
|
||||
}
|
||||
|
||||
// ToEnumDescriptorProto copies a [protoreflect.EnumDescriptor] into a
|
||||
// google.protobuf.EnumDescriptorProto message.
|
||||
func ToEnumDescriptorProto(enum protoreflect.EnumDescriptor) *descriptorpb.EnumDescriptorProto {
|
||||
p := &descriptorpb.EnumDescriptorProto{
|
||||
Name: proto.String(string(enum.Name())),
|
||||
Options: proto.Clone(enum.Options()).(*descriptorpb.EnumOptions),
|
||||
}
|
||||
for i, values := 0, enum.Values(); i < values.Len(); i++ {
|
||||
p.Value = append(p.Value, ToEnumValueDescriptorProto(values.Get(i)))
|
||||
}
|
||||
for i, ranges := 0, enum.ReservedRanges(); i < ranges.Len(); i++ {
|
||||
rrange := ranges.Get(i)
|
||||
p.ReservedRange = append(p.ReservedRange, &descriptorpb.EnumDescriptorProto_EnumReservedRange{
|
||||
Start: proto.Int32(int32(rrange[0])),
|
||||
End: proto.Int32(int32(rrange[1])),
|
||||
})
|
||||
}
|
||||
for i, names := 0, enum.ReservedNames(); i < names.Len(); i++ {
|
||||
p.ReservedName = append(p.ReservedName, string(names.Get(i)))
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// ToEnumValueDescriptorProto copies a [protoreflect.EnumValueDescriptor] into a
|
||||
// google.protobuf.EnumValueDescriptorProto message.
|
||||
func ToEnumValueDescriptorProto(value protoreflect.EnumValueDescriptor) *descriptorpb.EnumValueDescriptorProto {
|
||||
return &descriptorpb.EnumValueDescriptorProto{
|
||||
Name: proto.String(string(value.Name())),
|
||||
Number: proto.Int32(int32(value.Number())),
|
||||
Options: proto.Clone(value.Options()).(*descriptorpb.EnumValueOptions),
|
||||
}
|
||||
}
|
||||
|
||||
// ToServiceDescriptorProto copies a [protoreflect.ServiceDescriptor] into a
|
||||
// google.protobuf.ServiceDescriptorProto message.
|
||||
func ToServiceDescriptorProto(service protoreflect.ServiceDescriptor) *descriptorpb.ServiceDescriptorProto {
|
||||
p := &descriptorpb.ServiceDescriptorProto{
|
||||
Name: proto.String(string(service.Name())),
|
||||
Options: proto.Clone(service.Options()).(*descriptorpb.ServiceOptions),
|
||||
}
|
||||
for i, methods := 0, service.Methods(); i < methods.Len(); i++ {
|
||||
p.Method = append(p.Method, ToMethodDescriptorProto(methods.Get(i)))
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// ToMethodDescriptorProto copies a [protoreflect.MethodDescriptor] into a
|
||||
// google.protobuf.MethodDescriptorProto message.
|
||||
func ToMethodDescriptorProto(method protoreflect.MethodDescriptor) *descriptorpb.MethodDescriptorProto {
|
||||
p := &descriptorpb.MethodDescriptorProto{
|
||||
Name: proto.String(string(method.Name())),
|
||||
InputType: fullNameOf(method.Input()),
|
||||
OutputType: fullNameOf(method.Output()),
|
||||
Options: proto.Clone(method.Options()).(*descriptorpb.MethodOptions),
|
||||
}
|
||||
if method.IsStreamingClient() {
|
||||
p.ClientStreaming = proto.Bool(true)
|
||||
}
|
||||
if method.IsStreamingServer() {
|
||||
p.ServerStreaming = proto.Bool(true)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func fullNameOf(d protoreflect.Descriptor) *string {
|
||||
if d == nil {
|
||||
return nil
|
||||
}
|
||||
if strings.HasPrefix(string(d.FullName()), unknownPrefix) {
|
||||
return proto.String(string(d.FullName()[len(unknownPrefix):]))
|
||||
}
|
||||
return proto.String("." + string(d.FullName()))
|
||||
}
|
2
vendor/google.golang.org/protobuf/reflect/protoreflect/proto.go
generated
vendored
2
vendor/google.golang.org/protobuf/reflect/protoreflect/proto.go
generated
vendored
@ -161,7 +161,7 @@ const (
|
||||
// IsValid reports whether the syntax is valid.
|
||||
func (s Syntax) IsValid() bool {
|
||||
switch s {
|
||||
case Proto2, Proto3:
|
||||
case Proto2, Proto3, Editions:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
21
vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go
generated
vendored
21
vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go
generated
vendored
@ -373,6 +373,8 @@ func (p *SourcePath) appendFieldOptions(b []byte) []byte {
|
||||
b = p.appendRepeatedField(b, "edition_defaults", (*SourcePath).appendFieldOptions_EditionDefault)
|
||||
case 21:
|
||||
b = p.appendSingularField(b, "features", (*SourcePath).appendFeatureSet)
|
||||
case 22:
|
||||
b = p.appendSingularField(b, "feature_support", (*SourcePath).appendFieldOptions_FeatureSupport)
|
||||
case 999:
|
||||
b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
|
||||
}
|
||||
@ -483,6 +485,8 @@ func (p *SourcePath) appendEnumValueOptions(b []byte) []byte {
|
||||
b = p.appendSingularField(b, "features", (*SourcePath).appendFeatureSet)
|
||||
case 3:
|
||||
b = p.appendSingularField(b, "debug_redact", nil)
|
||||
case 4:
|
||||
b = p.appendSingularField(b, "feature_support", (*SourcePath).appendFieldOptions_FeatureSupport)
|
||||
case 999:
|
||||
b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
|
||||
}
|
||||
@ -519,6 +523,23 @@ func (p *SourcePath) appendFieldOptions_EditionDefault(b []byte) []byte {
|
||||
return b
|
||||
}
|
||||
|
||||
func (p *SourcePath) appendFieldOptions_FeatureSupport(b []byte) []byte {
|
||||
if len(*p) == 0 {
|
||||
return b
|
||||
}
|
||||
switch (*p)[0] {
|
||||
case 1:
|
||||
b = p.appendSingularField(b, "edition_introduced", nil)
|
||||
case 2:
|
||||
b = p.appendSingularField(b, "edition_deprecated", nil)
|
||||
case 3:
|
||||
b = p.appendSingularField(b, "deprecation_warning", nil)
|
||||
case 4:
|
||||
b = p.appendSingularField(b, "edition_removed", nil)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (p *SourcePath) appendUninterpretedOption_NamePart(b []byte) []byte {
|
||||
if len(*p) == 0 {
|
||||
return b
|
||||
|
12
vendor/google.golang.org/protobuf/reflect/protoreflect/type.go
generated
vendored
12
vendor/google.golang.org/protobuf/reflect/protoreflect/type.go
generated
vendored
@ -510,7 +510,7 @@ type ExtensionType interface {
|
||||
//
|
||||
// ValueOf is more extensive than protoreflect.ValueOf for a given field's
|
||||
// value as it has more type information available.
|
||||
ValueOf(interface{}) Value
|
||||
ValueOf(any) Value
|
||||
|
||||
// InterfaceOf completely unwraps the Value to the underlying Go type.
|
||||
// InterfaceOf panics if the input is nil or does not represent the
|
||||
@ -519,13 +519,13 @@ type ExtensionType interface {
|
||||
//
|
||||
// InterfaceOf is able to unwrap the Value further than Value.Interface
|
||||
// as it has more type information available.
|
||||
InterfaceOf(Value) interface{}
|
||||
InterfaceOf(Value) any
|
||||
|
||||
// IsValidValue reports whether the Value is valid to assign to the field.
|
||||
IsValidValue(Value) bool
|
||||
|
||||
// IsValidInterface reports whether the input is valid to assign to the field.
|
||||
IsValidInterface(interface{}) bool
|
||||
IsValidInterface(any) bool
|
||||
}
|
||||
|
||||
// EnumDescriptor describes an enum and
|
||||
@ -544,6 +544,12 @@ type EnumDescriptor interface {
|
||||
// ReservedRanges is a list of reserved ranges of enum numbers.
|
||||
ReservedRanges() EnumRanges
|
||||
|
||||
// IsClosed reports whether this enum uses closed semantics.
|
||||
// See https://protobuf.dev/programming-guides/enum/#definitions.
|
||||
// Note: the Go protobuf implementation is not spec compliant and treats
|
||||
// all enums as open enums.
|
||||
IsClosed() bool
|
||||
|
||||
isEnumDescriptor
|
||||
}
|
||||
type isEnumDescriptor interface{ ProtoType(EnumDescriptor) }
|
||||
|
14
vendor/google.golang.org/protobuf/reflect/protoreflect/value_pure.go
generated
vendored
14
vendor/google.golang.org/protobuf/reflect/protoreflect/value_pure.go
generated
vendored
@ -32,11 +32,11 @@ const (
|
||||
type value struct {
|
||||
pragma.DoNotCompare // 0B
|
||||
|
||||
typ valueType // 8B
|
||||
num uint64 // 8B
|
||||
str string // 16B
|
||||
bin []byte // 24B
|
||||
iface interface{} // 16B
|
||||
typ valueType // 8B
|
||||
num uint64 // 8B
|
||||
str string // 16B
|
||||
bin []byte // 24B
|
||||
iface any // 16B
|
||||
}
|
||||
|
||||
func valueOfString(v string) Value {
|
||||
@ -45,7 +45,7 @@ func valueOfString(v string) Value {
|
||||
func valueOfBytes(v []byte) Value {
|
||||
return Value{typ: bytesType, bin: v}
|
||||
}
|
||||
func valueOfIface(v interface{}) Value {
|
||||
func valueOfIface(v any) Value {
|
||||
return Value{typ: ifaceType, iface: v}
|
||||
}
|
||||
|
||||
@ -55,6 +55,6 @@ func (v Value) getString() string {
|
||||
func (v Value) getBytes() []byte {
|
||||
return v.bin
|
||||
}
|
||||
func (v Value) getIface() interface{} {
|
||||
func (v Value) getIface() any {
|
||||
return v.iface
|
||||
}
|
||||
|
14
vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go
generated
vendored
14
vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go
generated
vendored
@ -69,8 +69,8 @@ import (
|
||||
// composite Value. Modifying an empty, read-only value panics.
|
||||
type Value value
|
||||
|
||||
// The protoreflect API uses a custom Value union type instead of interface{}
|
||||
// to keep the future open for performance optimizations. Using an interface{}
|
||||
// The protoreflect API uses a custom Value union type instead of any
|
||||
// to keep the future open for performance optimizations. Using an any
|
||||
// always incurs an allocation for primitives (e.g., int64) since it needs to
|
||||
// be boxed on the heap (as interfaces can only contain pointers natively).
|
||||
// Instead, we represent the Value union as a flat struct that internally keeps
|
||||
@ -85,7 +85,7 @@ type Value value
|
||||
// ValueOf returns a Value initialized with the concrete value stored in v.
|
||||
// This panics if the type does not match one of the allowed types in the
|
||||
// Value union.
|
||||
func ValueOf(v interface{}) Value {
|
||||
func ValueOf(v any) Value {
|
||||
switch v := v.(type) {
|
||||
case nil:
|
||||
return Value{}
|
||||
@ -192,10 +192,10 @@ func (v Value) IsValid() bool {
|
||||
return v.typ != nilType
|
||||
}
|
||||
|
||||
// Interface returns v as an interface{}.
|
||||
// Interface returns v as an any.
|
||||
//
|
||||
// Invariant: v == ValueOf(v).Interface()
|
||||
func (v Value) Interface() interface{} {
|
||||
func (v Value) Interface() any {
|
||||
switch v.typ {
|
||||
case nilType:
|
||||
return nil
|
||||
@ -406,8 +406,8 @@ func (k MapKey) IsValid() bool {
|
||||
return Value(k).IsValid()
|
||||
}
|
||||
|
||||
// Interface returns k as an interface{}.
|
||||
func (k MapKey) Interface() interface{} {
|
||||
// Interface returns k as an any.
|
||||
func (k MapKey) Interface() any {
|
||||
return Value(k).Interface()
|
||||
}
|
||||
|
||||
|
6
vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe_go120.go
generated
vendored
6
vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe_go120.go
generated
vendored
@ -45,7 +45,7 @@ var (
|
||||
|
||||
// typeOf returns a pointer to the Go type information.
|
||||
// The pointer is comparable and equal if and only if the types are identical.
|
||||
func typeOf(t interface{}) unsafe.Pointer {
|
||||
func typeOf(t any) unsafe.Pointer {
|
||||
return (*ifaceHeader)(unsafe.Pointer(&t)).Type
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ func valueOfBytes(v []byte) Value {
|
||||
p := (*sliceHeader)(unsafe.Pointer(&v))
|
||||
return Value{typ: bytesType, ptr: p.Data, num: uint64(len(v))}
|
||||
}
|
||||
func valueOfIface(v interface{}) Value {
|
||||
func valueOfIface(v any) Value {
|
||||
p := (*ifaceHeader)(unsafe.Pointer(&v))
|
||||
return Value{typ: p.Type, ptr: p.Data}
|
||||
}
|
||||
@ -93,7 +93,7 @@ func (v Value) getBytes() (x []byte) {
|
||||
*(*sliceHeader)(unsafe.Pointer(&x)) = sliceHeader{Data: v.ptr, Len: int(v.num), Cap: int(v.num)}
|
||||
return x
|
||||
}
|
||||
func (v Value) getIface() (x interface{}) {
|
||||
func (v Value) getIface() (x any) {
|
||||
*(*ifaceHeader)(unsafe.Pointer(&x)) = ifaceHeader{Type: v.typ, Data: v.ptr}
|
||||
return x
|
||||
}
|
||||
|
8
vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe_go121.go
generated
vendored
8
vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe_go121.go
generated
vendored
@ -15,7 +15,7 @@ import (
|
||||
|
||||
type (
|
||||
ifaceHeader struct {
|
||||
_ [0]interface{} // if interfaces have greater alignment than unsafe.Pointer, this will enforce it.
|
||||
_ [0]any // if interfaces have greater alignment than unsafe.Pointer, this will enforce it.
|
||||
Type unsafe.Pointer
|
||||
Data unsafe.Pointer
|
||||
}
|
||||
@ -37,7 +37,7 @@ var (
|
||||
|
||||
// typeOf returns a pointer to the Go type information.
|
||||
// The pointer is comparable and equal if and only if the types are identical.
|
||||
func typeOf(t interface{}) unsafe.Pointer {
|
||||
func typeOf(t any) unsafe.Pointer {
|
||||
return (*ifaceHeader)(unsafe.Pointer(&t)).Type
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ func valueOfString(v string) Value {
|
||||
func valueOfBytes(v []byte) Value {
|
||||
return Value{typ: bytesType, ptr: unsafe.Pointer(unsafe.SliceData(v)), num: uint64(len(v))}
|
||||
}
|
||||
func valueOfIface(v interface{}) Value {
|
||||
func valueOfIface(v any) Value {
|
||||
p := (*ifaceHeader)(unsafe.Pointer(&v))
|
||||
return Value{typ: p.Type, ptr: p.Data}
|
||||
}
|
||||
@ -81,7 +81,7 @@ func (v Value) getString() string {
|
||||
func (v Value) getBytes() []byte {
|
||||
return unsafe.Slice((*byte)(v.ptr), v.num)
|
||||
}
|
||||
func (v Value) getIface() (x interface{}) {
|
||||
func (v Value) getIface() (x any) {
|
||||
*(*ifaceHeader)(unsafe.Pointer(&x)) = ifaceHeader{Type: v.typ, Data: v.ptr}
|
||||
return x
|
||||
}
|
||||
|
14
vendor/google.golang.org/protobuf/reflect/protoregistry/registry.go
generated
vendored
14
vendor/google.golang.org/protobuf/reflect/protoregistry/registry.go
generated
vendored
@ -95,7 +95,7 @@ type Files struct {
|
||||
// multiple files. Only top-level declarations are registered.
|
||||
// Note that enum values are in the top-level since that are in the same
|
||||
// scope as the parent enum.
|
||||
descsByName map[protoreflect.FullName]interface{}
|
||||
descsByName map[protoreflect.FullName]any
|
||||
filesByPath map[string][]protoreflect.FileDescriptor
|
||||
numFiles int
|
||||
}
|
||||
@ -117,7 +117,7 @@ func (r *Files) RegisterFile(file protoreflect.FileDescriptor) error {
|
||||
defer globalMutex.Unlock()
|
||||
}
|
||||
if r.descsByName == nil {
|
||||
r.descsByName = map[protoreflect.FullName]interface{}{
|
||||
r.descsByName = map[protoreflect.FullName]any{
|
||||
"": &packageDescriptor{},
|
||||
}
|
||||
r.filesByPath = make(map[string][]protoreflect.FileDescriptor)
|
||||
@ -485,7 +485,7 @@ type Types struct {
|
||||
}
|
||||
|
||||
type (
|
||||
typesByName map[protoreflect.FullName]interface{}
|
||||
typesByName map[protoreflect.FullName]any
|
||||
extensionsByMessage map[protoreflect.FullName]extensionsByNumber
|
||||
extensionsByNumber map[protoreflect.FieldNumber]protoreflect.ExtensionType
|
||||
)
|
||||
@ -570,7 +570,7 @@ func (r *Types) RegisterExtension(xt protoreflect.ExtensionType) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Types) register(kind string, desc protoreflect.Descriptor, typ interface{}) error {
|
||||
func (r *Types) register(kind string, desc protoreflect.Descriptor, typ any) error {
|
||||
name := desc.FullName()
|
||||
prev := r.typesByName[name]
|
||||
if prev != nil {
|
||||
@ -841,7 +841,7 @@ func (r *Types) RangeExtensionsByMessage(message protoreflect.FullName, f func(p
|
||||
}
|
||||
}
|
||||
|
||||
func typeName(t interface{}) string {
|
||||
func typeName(t any) string {
|
||||
switch t.(type) {
|
||||
case protoreflect.EnumType:
|
||||
return "enum"
|
||||
@ -854,7 +854,7 @@ func typeName(t interface{}) string {
|
||||
}
|
||||
}
|
||||
|
||||
func amendErrorWithCaller(err error, prev, curr interface{}) error {
|
||||
func amendErrorWithCaller(err error, prev, curr any) error {
|
||||
prevPkg := goPackage(prev)
|
||||
currPkg := goPackage(curr)
|
||||
if prevPkg == "" || currPkg == "" || prevPkg == currPkg {
|
||||
@ -863,7 +863,7 @@ func amendErrorWithCaller(err error, prev, curr interface{}) error {
|
||||
return errors.New("%s\n\tpreviously from: %q\n\tcurrently from: %q", err, prevPkg, currPkg)
|
||||
}
|
||||
|
||||
func goPackage(v interface{}) string {
|
||||
func goPackage(v any) string {
|
||||
switch d := v.(type) {
|
||||
case protoreflect.EnumType:
|
||||
v = d.Descriptor()
|
||||
|
Reference in New Issue
Block a user