diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2024-01-30 11:20:39 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2024-01-30 12:12:51 +0300 |
commit | be737fd8956853e06bd2c4f9fcd4a85188f4c172 (patch) | |
tree | 5bd76802fac1096dfd90983c7739d50de367a79f /vendor/google.golang.org/protobuf/reflect | |
parent | fe62880c46b1f2c9fec779b0dc39f8a92ce256a5 (diff) | |
download | ydb-be737fd8956853e06bd2c4f9fcd4a85188f4c172.tar.gz |
Update vendor/github.com/envoyproxy/go-control-plane to 0.12.0
Diffstat (limited to 'vendor/google.golang.org/protobuf/reflect')
30 files changed, 449 insertions, 2932 deletions
diff --git a/vendor/google.golang.org/protobuf/reflect/protodesc/desc.go b/vendor/google.golang.org/protobuf/reflect/protodesc/desc.go index e4dfb12050..baa0cc6218 100644 --- a/vendor/google.golang.org/protobuf/reflect/protodesc/desc.go +++ b/vendor/google.golang.org/protobuf/reflect/protodesc/desc.go @@ -3,11 +3,11 @@ // license that can be found in the LICENSE file. // Package protodesc provides functionality for converting -// FileDescriptorProto messages to/from protoreflect.FileDescriptor values. +// 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 [protoreflect.FileDescriptor] is a more structured representation of // the FileDescriptorProto message where references and remote dependencies // can be directly followed. package protodesc @@ -24,11 +24,11 @@ import ( "google.golang.org/protobuf/types/descriptorpb" ) -// Resolver is the resolver used by NewFile to resolve dependencies. +// 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. +// It is implemented by [protoregistry.Files]. type Resolver interface { FindFileByPath(string) (protoreflect.FileDescriptor, error) FindDescriptorByName(protoreflect.FullName) (protoreflect.Descriptor, error) @@ -61,19 +61,19 @@ type FileOptions struct { AllowUnresolvable bool } -// NewFile creates a new protoreflect.FileDescriptor from the provided -// file descriptor message. See FileOptions.New for more information. +// 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. +// 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 +// 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. // @@ -93,9 +93,15 @@ func (o FileOptions) New(fd *descriptorpb.FileDescriptorProto, r Resolver) (prot 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") @@ -108,6 +114,9 @@ func (o FileOptions) New(fd *descriptorpb.FileDescriptorProto, r Resolver) (prot 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() { @@ -231,7 +240,7 @@ func (is importSet) importPublic(imps protoreflect.FileImports) { } } -// NewFiles creates a new protoregistry.Files from the provided +// 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. diff --git a/vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go b/vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go index 37efda1afe..aff6fd4900 100644 --- a/vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go +++ b/vendor/google.golang.org/protobuf/reflect/protodesc/desc_init.go @@ -137,6 +137,30 @@ func (r descsByName) initFieldsFromDescriptorProto(fds []*descriptorpb.FieldDesc if fd.JsonName != nil { f.L1.StringName.InitJSON(fd.GetJsonName()) } + + if f.Base.L0.ParentFile.Syntax() == protoreflect.Editions { + f.L1.Presence = resolveFeatureHasFieldPresence(f.Base.L0.ParentFile, fd) + // We reuse the existing field because the old option `[packed = + // true]` is mutually exclusive with the editions feature. + if fd.GetLabel() == descriptorpb.FieldDescriptorProto_LABEL_REPEATED { + f.L1.HasPacked = true + f.L1.IsPacked = resolveFeatureRepeatedFieldEncodingPacked(f.Base.L0.ParentFile, fd) + } + + // 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 = resolveFeatureEnforceUTF8(f.Base.L0.ParentFile, fd) + + if f.L1.Kind == protoreflect.MessageKind && resolveFeatureDelimitedEncoding(f.Base.L0.ParentFile, fd) { + f.L1.Kind = protoreflect.GroupKind + } + } } return fs, nil } diff --git a/vendor/google.golang.org/protobuf/reflect/protodesc/editions.go b/vendor/google.golang.org/protobuf/reflect/protodesc/editions.go new file mode 100644 index 0000000000..7352926cab --- /dev/null +++ b/vendor/google.golang.org/protobuf/reflect/protodesc/editions.go @@ -0,0 +1,177 @@ +// 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 ( + _ "embed" + "fmt" + "os" + "sync" + + "google.golang.org/protobuf/internal/filedesc" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/descriptorpb" +) + +const ( + SupportedEditionsMinimum = descriptorpb.Edition_EDITION_PROTO2 + SupportedEditionsMaximum = descriptorpb.Edition_EDITION_2023 +) + +//go:embed editions_defaults.binpb +var binaryEditionDefaults []byte +var defaults = &descriptorpb.FeatureSetDefaults{} +var defaultsCacheMu sync.Mutex +var defaultsCache = make(map[filedesc.Edition]*descriptorpb.FeatureSet) + +func init() { + err := proto.Unmarshal(binaryEditionDefaults, 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 +} + +func resolveFeatureHasFieldPresence(fileDesc *filedesc.File, fieldDesc *descriptorpb.FieldDescriptorProto) bool { + fs := fieldDesc.GetOptions().GetFeatures() + if fs == nil || fs.FieldPresence == nil { + return fileDesc.L1.EditionFeatures.IsFieldPresence + } + return fs.GetFieldPresence() == descriptorpb.FeatureSet_LEGACY_REQUIRED || + fs.GetFieldPresence() == descriptorpb.FeatureSet_EXPLICIT +} + +func resolveFeatureRepeatedFieldEncodingPacked(fileDesc *filedesc.File, fieldDesc *descriptorpb.FieldDescriptorProto) bool { + fs := fieldDesc.GetOptions().GetFeatures() + if fs == nil || fs.RepeatedFieldEncoding == nil { + return fileDesc.L1.EditionFeatures.IsPacked + } + return fs.GetRepeatedFieldEncoding() == descriptorpb.FeatureSet_PACKED +} + +func resolveFeatureEnforceUTF8(fileDesc *filedesc.File, fieldDesc *descriptorpb.FieldDescriptorProto) bool { + fs := fieldDesc.GetOptions().GetFeatures() + if fs == nil || fs.Utf8Validation == nil { + return fileDesc.L1.EditionFeatures.IsUTF8Validated + } + return fs.GetUtf8Validation() == descriptorpb.FeatureSet_VERIFY +} + +func resolveFeatureDelimitedEncoding(fileDesc *filedesc.File, fieldDesc *descriptorpb.FieldDescriptorProto) bool { + fs := fieldDesc.GetOptions().GetFeatures() + if fs == nil || fs.MessageEncoding == nil { + return fileDesc.L1.EditionFeatures.IsDelimitedEncoded + } + return fs.GetMessageEncoding() == descriptorpb.FeatureSet_DELIMITED +} + +// 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) + if fs == nil { + fs = &descriptorpb.FeatureSet{} + } + + var fieldPresence descriptorpb.FeatureSet_FieldPresence + if fp := fs.FieldPresence; fp != nil { + fieldPresence = *fp + } else { + fieldPresence = *dfs.FieldPresence + } + fd.L1.EditionFeatures.IsFieldPresence = fieldPresence == descriptorpb.FeatureSet_LEGACY_REQUIRED || + fieldPresence == descriptorpb.FeatureSet_EXPLICIT + + var enumType descriptorpb.FeatureSet_EnumType + if et := fs.EnumType; et != nil { + enumType = *et + } else { + enumType = *dfs.EnumType + } + fd.L1.EditionFeatures.IsOpenEnum = enumType == descriptorpb.FeatureSet_OPEN + + var respeatedFieldEncoding descriptorpb.FeatureSet_RepeatedFieldEncoding + if rfe := fs.RepeatedFieldEncoding; rfe != nil { + respeatedFieldEncoding = *rfe + } else { + respeatedFieldEncoding = *dfs.RepeatedFieldEncoding + } + fd.L1.EditionFeatures.IsPacked = respeatedFieldEncoding == descriptorpb.FeatureSet_PACKED + + var isUTF8Validated descriptorpb.FeatureSet_Utf8Validation + if utf8val := fs.Utf8Validation; utf8val != nil { + isUTF8Validated = *utf8val + } else { + isUTF8Validated = *dfs.Utf8Validation + } + fd.L1.EditionFeatures.IsUTF8Validated = isUTF8Validated == descriptorpb.FeatureSet_VERIFY + + var messageEncoding descriptorpb.FeatureSet_MessageEncoding + if me := fs.MessageEncoding; me != nil { + messageEncoding = *me + } else { + messageEncoding = *dfs.MessageEncoding + } + fd.L1.EditionFeatures.IsDelimitedEncoded = messageEncoding == descriptorpb.FeatureSet_DELIMITED + + var jsonFormat descriptorpb.FeatureSet_JsonFormat + if jf := fs.JsonFormat; jf != nil { + jsonFormat = *jf + } else { + jsonFormat = *dfs.JsonFormat + } + fd.L1.EditionFeatures.IsJSONCompliant = jsonFormat == descriptorpb.FeatureSet_ALLOW +} diff --git a/vendor/google.golang.org/protobuf/reflect/protodesc/editions_defaults.binpb b/vendor/google.golang.org/protobuf/reflect/protodesc/editions_defaults.binpb new file mode 100644 index 0000000000..1a8610a843 --- /dev/null +++ b/vendor/google.golang.org/protobuf/reflect/protodesc/editions_defaults.binpb @@ -0,0 +1,4 @@ + + (0ๆ + (0็ + (0่ ๆ(่
\ No newline at end of file diff --git a/vendor/google.golang.org/protobuf/reflect/protodesc/file_test.go b/vendor/google.golang.org/protobuf/reflect/protodesc/file_test.go deleted file mode 100644 index 29b4fa722c..0000000000 --- a/vendor/google.golang.org/protobuf/reflect/protodesc/file_test.go +++ /dev/null @@ -1,1182 +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" - "testing" - - "google.golang.org/protobuf/encoding/prototext" - "google.golang.org/protobuf/internal/flags" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - - "google.golang.org/protobuf/types/descriptorpb" -) - -func mustParseFile(s string) *descriptorpb.FileDescriptorProto { - pb := new(descriptorpb.FileDescriptorProto) - if err := prototext.Unmarshal([]byte(s), pb); err != nil { - panic(err) - } - return pb -} - -func cloneFile(in *descriptorpb.FileDescriptorProto) *descriptorpb.FileDescriptorProto { - return proto.Clone(in).(*descriptorpb.FileDescriptorProto) -} - -var ( - proto2Enum = mustParseFile(` - syntax: "proto2" - name: "proto2_enum.proto" - package: "test.proto2" - enum_type: [{name:"Enum" value:[{name:"ONE" number:1}]}] - `) - proto3Message = mustParseFile(` - syntax: "proto3" - name: "proto3_message.proto" - package: "test.proto3" - message_type: [{ - name: "Message" - field: [ - {name:"foo" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, - {name:"bar" number:2 label:LABEL_OPTIONAL type:TYPE_STRING} - ] - }] - `) - extendableMessage = mustParseFile(` - syntax: "proto2" - name: "extendable_message.proto" - package: "test.proto2" - message_type: [{name:"Message" extension_range:[{start:1 end:1000}]}] - `) - importPublicFile1 = mustParseFile(` - syntax: "proto3" - name: "import_public1.proto" - dependency: ["proto2_enum.proto", "proto3_message.proto", "extendable_message.proto"] - message_type: [{name:"Public1"}] - `) - importPublicFile2 = mustParseFile(` - syntax: "proto3" - name: "import_public2.proto" - dependency: ["import_public1.proto"] - public_dependency: [0] - message_type: [{name:"Public2"}] - `) - importPublicFile3 = mustParseFile(` - syntax: "proto3" - name: "import_public3.proto" - dependency: ["import_public2.proto", "extendable_message.proto"] - public_dependency: [0] - message_type: [{name:"Public3"}] - `) - importPublicFile4 = mustParseFile(` - syntax: "proto3" - name: "import_public4.proto" - dependency: ["import_public2.proto", "import_public3.proto", "proto2_enum.proto"] - public_dependency: [0, 1] - message_type: [{name:"Public4"}] - `) -) - -func TestNewFile(t *testing.T) { - tests := []struct { - label string - inDeps []*descriptorpb.FileDescriptorProto - inDesc *descriptorpb.FileDescriptorProto - inOpts FileOptions - wantDesc *descriptorpb.FileDescriptorProto - wantErr string - }{{ - label: "empty path", - inDesc: mustParseFile(``), - wantErr: `path must be populated`, - }, { - label: "empty package and syntax", - inDesc: mustParseFile(`name:"weird"`), - }, { - label: "invalid syntax", - inDesc: mustParseFile(`name:"weird" syntax:"proto9"`), - wantErr: `invalid syntax: "proto9"`, - }, { - label: "bad package", - inDesc: mustParseFile(`name:"weird" package:"$"`), - wantErr: `invalid package: "$"`, - }, { - label: "unresolvable import", - inDesc: mustParseFile(` - name: "test.proto" - dependency: "dep.proto" - `), - wantErr: `could not resolve import "dep.proto": not found`, - }, { - label: "unresolvable import but allowed", - inDesc: mustParseFile(` - name: "test.proto" - dependency: "dep.proto" - `), - inOpts: FileOptions{AllowUnresolvable: true}, - }, { - label: "duplicate import", - inDesc: mustParseFile(` - name: "test.proto" - dependency: ["dep.proto", "dep.proto"] - `), - inOpts: FileOptions{AllowUnresolvable: true}, - wantErr: `already imported "dep.proto"`, - }, { - label: "invalid weak import", - inDesc: mustParseFile(` - name: "test.proto" - dependency: "dep.proto" - weak_dependency: [-23] - `), - inOpts: FileOptions{AllowUnresolvable: true}, - wantErr: `invalid or duplicate weak import index: -23`, - }, { - label: "normal weak and public import", - inDesc: mustParseFile(` - name: "test.proto" - dependency: "dep.proto" - weak_dependency: [0] - public_dependency: [0] - `), - inOpts: FileOptions{AllowUnresolvable: true}, - }, { - label: "import public indirect dependency duplicate", - inDeps: []*descriptorpb.FileDescriptorProto{ - mustParseFile(`name:"leaf.proto"`), - mustParseFile(`name:"public.proto" dependency:"leaf.proto" public_dependency:0`), - }, - inDesc: mustParseFile(` - name: "test.proto" - dependency: ["public.proto", "leaf.proto"] - `), - }, { - label: "import public graph", - inDeps: []*descriptorpb.FileDescriptorProto{ - cloneFile(proto2Enum), - cloneFile(proto3Message), - cloneFile(extendableMessage), - cloneFile(importPublicFile1), - cloneFile(importPublicFile2), - cloneFile(importPublicFile3), - cloneFile(importPublicFile4), - }, - inDesc: mustParseFile(` - name: "test.proto" - package: "test.graph" - dependency: ["import_public4.proto"], - `), - // TODO: Test import public - }, { - label: "preserve source code locations", - inDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - source_code_info: {location: [{ - span: [39,0,882,1] - }, { - path: [12] - span: [39,0,18] - leading_detached_comments: [" foo\n"," bar\n"] - }, { - path: [8,9] - span: [51,0,28] - leading_comments: " Comment\n" - }]} - `), - }, { - label: "invalid source code span", - inDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - source_code_info: {location: [{ - span: [39] - }]} - `), - wantErr: `invalid span: [39]`, - }, { - label: "resolve relative reference", - inDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - message_type: [{ - name: "A" - field: [{name:"F" number:1 label:LABEL_OPTIONAL type:TYPE_MESSAGE type_name:"B.C"}] - nested_type: [{name: "B"}] - }, { - name: "B" - nested_type: [{name: "C"}] - }] - `), - wantDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - message_type: [{ - name: "A" - field: [{name:"F" number:1 label:LABEL_OPTIONAL type:TYPE_MESSAGE type_name:".fizz.buzz.B.C"}] - nested_type: [{name: "B"}] - }, { - name: "B" - nested_type: [{name: "C"}] - }] - `), - }, { - label: "resolve the wrong type", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{ - name: "M" - field: [{name:"F" number:1 label:LABEL_OPTIONAL type:TYPE_MESSAGE type_name:"E"}] - enum_type: [{name: "E" value: [{name:"V0" number:0}, {name:"V1" number:1}]}] - }] - `), - wantErr: `message field "M.F" cannot resolve type: resolved "M.E", but it is not an message`, - }, { - label: "auto-resolve unknown kind", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{ - name: "M" - field: [{name:"F" number:1 label:LABEL_OPTIONAL type_name:"E"}] - enum_type: [{name: "E" value: [{name:"V0" number:0}, {name:"V1" number:1}]}] - }] - `), - wantDesc: mustParseFile(` - name: "test.proto" - message_type: [{ - name: "M" - field: [{name:"F" number:1 label:LABEL_OPTIONAL type:TYPE_ENUM type_name:".M.E"}] - enum_type: [{name: "E" value: [{name:"V0" number:0}, {name:"V1" number:1}]}] - }] - `), - }, { - label: "unresolved import", - inDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - dependency: "remote.proto" - `), - wantErr: `could not resolve import "remote.proto": not found`, - }, { - label: "unresolved message field", - inDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - message_type: [{ - name: "M" - field: [{name:"F1" number:1 label:LABEL_OPTIONAL type:TYPE_ENUM type_name:"some.other.enum" default_value:"UNKNOWN"}] - }] - `), - wantErr: `message field "fizz.buzz.M.F1" cannot resolve type: "*.some.other.enum" not found`, - }, { - label: "unresolved default enum value", - inDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - message_type: [{ - name: "M" - field: [{name:"F1" number:1 label:LABEL_OPTIONAL type:TYPE_ENUM type_name:"E" default_value:"UNKNOWN"}] - enum_type: [{name:"E" value:[{name:"V0" number:0}]}] - }] - `), - wantErr: `message field "fizz.buzz.M.F1" has invalid default: could not parse value for enum: "UNKNOWN"`, - }, { - label: "allowed unresolved default enum value", - inDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - message_type: [{ - name: "M" - field: [{name:"F1" number:1 label:LABEL_OPTIONAL type:TYPE_ENUM type_name:".fizz.buzz.M.E" default_value:"UNKNOWN"}] - enum_type: [{name:"E" value:[{name:"V0" number:0}]}] - }] - `), - inOpts: FileOptions{AllowUnresolvable: true}, - }, { - label: "unresolved extendee", - inDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - extension: [{name:"X" number:1 label:LABEL_OPTIONAL extendee:"some.extended.message" type:TYPE_MESSAGE type_name:"some.other.message"}] - `), - wantErr: `extension field "fizz.buzz.X" cannot resolve extendee: "*.some.extended.message" not found`, - }, { - label: "unresolved method input", - inDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - service: [{ - name: "S" - method: [{name:"M" input_type:"foo.bar.input" output_type:".absolute.foo.bar.output"}] - }] - `), - wantErr: `service method "fizz.buzz.S.M" cannot resolve input: "*.foo.bar.input" not found`, - }, { - label: "allowed unresolved references", - inDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - dependency: "remote.proto" - message_type: [{ - name: "M" - field: [{name:"F1" number:1 label:LABEL_OPTIONAL type_name:"some.other.enum" default_value:"UNKNOWN"}] - }] - extension: [{name:"X" number:1 label:LABEL_OPTIONAL extendee:"some.extended.message" type:TYPE_MESSAGE type_name:"some.other.message"}] - service: [{ - name: "S" - method: [{name:"M" input_type:"foo.bar.input" output_type:".absolute.foo.bar.output"}] - }] - `), - inOpts: FileOptions{AllowUnresolvable: true}, - }, { - label: "resolved but not imported", - inDeps: []*descriptorpb.FileDescriptorProto{mustParseFile(` - name: "dep.proto" - package: "fizz" - message_type: [{name:"M" nested_type:[{name:"M"}]}] - `)}, - inDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - message_type: [{ - name: "M" - field: [{name:"F" number:1 label:LABEL_OPTIONAL type:TYPE_MESSAGE type_name:"M.M"}] - }] - `), - wantErr: `message field "fizz.buzz.M.F" cannot resolve type: resolved "fizz.M.M", but "dep.proto" is not imported`, - }, { - label: "resolved from remote import", - inDeps: []*descriptorpb.FileDescriptorProto{mustParseFile(` - name: "dep.proto" - package: "fizz" - message_type: [{name:"M" nested_type:[{name:"M"}]}] - `)}, - inDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - dependency: "dep.proto" - message_type: [{ - name: "M" - field: [{name:"F" number:1 label:LABEL_OPTIONAL type:TYPE_MESSAGE type_name:"M.M"}] - }] - `), - wantDesc: mustParseFile(` - name: "test.proto" - package: "fizz.buzz" - dependency: "dep.proto" - message_type: [{ - name: "M" - field: [{name:"F" number:1 label:LABEL_OPTIONAL type:TYPE_MESSAGE type_name:".fizz.M.M"}] - }] - `), - }, { - label: "namespace conflict on enum value", - inDesc: mustParseFile(` - name: "test.proto" - enum_type: [{ - name: "foo" - value: [{name:"foo" number:0}] - }] - `), - wantErr: `descriptor "foo" already declared`, - }, { - label: "no namespace conflict on message field", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{ - name: "foo" - field: [{name:"foo" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}] - }] - `), - }, { - label: "invalid name", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name: "$"}] - `), - wantErr: `descriptor "" has an invalid nested name: "$"`, - }, { - label: "invalid empty enum", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{name:"E"}]}] - `), - wantErr: `enum "M.E" must contain at least one value declaration`, - }, { - label: "invalid enum value without number", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{name:"E" value:[{name:"one"}]}]}] - `), - wantErr: `enum value "M.one" must have a specified number`, - }, { - label: "valid enum", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{name:"E" value:[{name:"one" number:1}]}]}] - `), - }, { - label: "invalid enum reserved names", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - reserved_name: [""] - value: [{name:"V" number:0}] - }]}] - `), - // NOTE: In theory this should be an error. - // See https://github.com/protocolbuffers/protobuf/issues/6335. - /*wantErr: `enum "M.E" reserved names has invalid name: ""`,*/ - }, { - label: "duplicate enum reserved names", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - reserved_name: ["foo", "foo"] - }]}] - `), - wantErr: `enum "M.E" reserved names has duplicate name: "foo"`, - }, { - label: "valid enum reserved names", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - reserved_name: ["foo", "bar"] - value: [{name:"baz" number:1}] - }]}] - `), - }, { - label: "use of enum reserved names", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - reserved_name: ["foo", "bar"] - value: [{name:"foo" number:1}] - }]}] - `), - wantErr: `enum value "M.foo" must not use reserved name`, - }, { - label: "invalid enum reserved ranges", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - reserved_range: [{start:5 end:4}] - }]}] - `), - wantErr: `enum "M.E" reserved ranges has invalid range: 5 to 4`, - }, { - label: "overlapping enum reserved ranges", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - reserved_range: [{start:1 end:1000}, {start:10 end:100}] - }]}] - `), - wantErr: `enum "M.E" reserved ranges has overlapping ranges: 1 to 1000 with 10 to 100`, - }, { - label: "valid enum reserved names", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - reserved_range: [{start:1 end:10}, {start:100 end:1000}] - value: [{name:"baz" number:50}] - }]}] - `), - }, { - label: "use of enum reserved range", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - reserved_range: [{start:1 end:10}, {start:100 end:1000}] - value: [{name:"baz" number:500}] - }]}] - `), - wantErr: `enum value "M.baz" must not use reserved number 500`, - }, { - label: "unused enum alias feature", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - value: [{name:"baz" number:500}] - options: {allow_alias:true} - }]}] - `), - wantErr: `enum "M.E" allows aliases, but none were found`, - }, { - label: "enum number conflicts", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - value: [{name:"foo" number:0}, {name:"bar" number:1}, {name:"baz" number:1}] - }]}] - `), - wantErr: `enum "M.E" has conflicting non-aliased values on number 1: "baz" with "bar"`, - }, { - label: "aliased enum numbers", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - value: [{name:"foo" number:0}, {name:"bar" number:1}, {name:"baz" number:1}] - options: {allow_alias:true} - }]}] - `), - }, { - label: "invalid proto3 enum", - inDesc: mustParseFile(` - syntax: "proto3" - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - value: [{name:"baz" number:500}] - }]}] - `), - wantErr: `enum "M.baz" using proto3 semantics must have zero number for the first value`, - }, { - label: "valid proto3 enum", - inDesc: mustParseFile(` - syntax: "proto3" - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - value: [{name:"baz" number:0}] - }]}] - `), - }, { - label: "proto3 enum name prefix conflict", - inDesc: mustParseFile(` - syntax: "proto3" - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - value: [{name:"e_Foo" number:0}, {name:"fOo" number:1}] - }]}] - `), - wantErr: `enum "M.E" using proto3 semantics has conflict: "fOo" with "e_Foo"`, - }, { - label: "proto2 enum has name prefix check", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - value: [{name:"e_Foo" number:0}, {name:"fOo" number:1}] - }]}] - `), - }, { - label: "proto3 enum same name prefix with number conflict", - inDesc: mustParseFile(` - syntax: "proto3" - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - value: [{name:"e_Foo" number:0}, {name:"fOo" number:0}] - }]}] - `), - wantErr: `enum "M.E" has conflicting non-aliased values on number 0: "fOo" with "e_Foo"`, - }, { - label: "proto3 enum same name prefix with alias numbers", - inDesc: mustParseFile(` - syntax: "proto3" - name: "test.proto" - message_type: [{name:"M" enum_type:[{ - name: "E" - value: [{name:"e_Foo" number:0}, {name:"fOo" number:0}] - options: {allow_alias: true} - }]}] - `), - }, { - label: "invalid message reserved names", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - reserved_name: ["$"] - }]}] - `), - // NOTE: In theory this should be an error. - // See https://github.com/protocolbuffers/protobuf/issues/6335. - /*wantErr: `message "M.M" reserved names has invalid name: "$"`,*/ - }, { - label: "valid message reserved names", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - reserved_name: ["foo", "bar"] - field: [{name:"foo" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}] - }]}] - `), - wantErr: `message field "M.M.foo" must not use reserved name`, - }, { - label: "valid message reserved names", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - reserved_name: ["foo", "bar"] - field: [{name:"baz" number:1 label:LABEL_OPTIONAL type:TYPE_STRING oneof_index:0}] - oneof_decl: [{name:"foo"}] # not affected by reserved_name - }]}] - `), - }, { - label: "invalid reserved number", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - reserved_range: [{start:1 end:1}] - field: [{name:"baz" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}] - }]}] - `), - wantErr: `message "M.M" reserved ranges has invalid field number: 0`, - }, { - label: "invalid reserved ranges", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - reserved_range: [{start:2 end:2}] - field: [{name:"baz" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}] - }]}] - `), - wantErr: `message "M.M" reserved ranges has invalid range: 2 to 1`, - }, { - label: "overlapping reserved ranges", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - reserved_range: [{start:1 end:10}, {start:2 end:9}] - field: [{name:"baz" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}] - }]}] - `), - wantErr: `message "M.M" reserved ranges has overlapping ranges: 1 to 9 with 2 to 8`, - }, { - label: "use of reserved message field number", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - reserved_range: [{start:10 end:20}, {start:20 end:30}, {start:30 end:31}] - field: [{name:"baz" number:30 label:LABEL_OPTIONAL type:TYPE_STRING}] - }]}] - `), - wantErr: `message field "M.M.baz" must not use reserved number 30`, - }, { - label: "invalid extension ranges", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - extension_range: [{start:-500 end:2}] - field: [{name:"baz" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}] - }]}] - `), - wantErr: `message "M.M" extension ranges has invalid field number: -500`, - }, { - label: "overlapping reserved and extension ranges", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - reserved_range: [{start:15 end:20}, {start:1 end:3}, {start:7 end:10}] - extension_range: [{start:8 end:9}, {start:3 end:5}] - }]}] - `), - wantErr: `message "M.M" reserved and extension ranges has overlapping ranges: 7 to 9 with 8`, - }, { - label: "message field conflicting number", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - field: [ - {name:"one" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, - {name:"One" number:1 label:LABEL_OPTIONAL type:TYPE_STRING} - ] - }]}] - `), - wantErr: `message "M.M" has conflicting fields: "One" with "one"`, - }, { - label: "invalid MessageSet", - inDesc: mustParseFile(` - syntax: "proto3" - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - options: {message_set_wire_format:true} - }]}] - `), - wantErr: func() string { - if flags.ProtoLegacy { - return `message "M.M" is an invalid proto1 MessageSet` - } else { - return `message "M.M" is a MessageSet, which is a legacy proto1 feature that is no longer supported` - } - }(), - }, { - label: "valid MessageSet", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - extension_range: [{start:1 end:100000}] - options: {message_set_wire_format:true} - }]}] - `), - wantErr: func() string { - if flags.ProtoLegacy { - return "" - } else { - return `message "M.M" is a MessageSet, which is a legacy proto1 feature that is no longer supported` - } - }(), - }, { - label: "invalid extension ranges in proto3", - inDesc: mustParseFile(` - syntax: "proto3" - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - extension_range: [{start:1 end:100000}] - }]}] - `), - wantErr: `message "M.M" using proto3 semantics cannot have extension ranges`, - }, { - label: "proto3 message fields conflict", - inDesc: mustParseFile(` - syntax: "proto3" - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - field: [ - {name:"_b_a_z_" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, - {name:"baz" number:2 label:LABEL_OPTIONAL type:TYPE_STRING} - ] - }]}] - `), - wantErr: `message "M.M" using proto3 semantics has conflict: "baz" with "_b_a_z_"`, - }, { - label: "proto3 message fields", - inDesc: mustParseFile(` - syntax: "proto3" - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - field: [{name:"_b_a_z_" number:1 label:LABEL_OPTIONAL type:TYPE_STRING oneof_index:0}] - oneof_decl: [{name:"baz"}] # proto3 name conflict logic does not include oneof - }]}] - `), - }, { - label: "proto2 message fields with no conflict", - inDesc: mustParseFile(` - name: "test.proto" - message_type: [{name:"M" nested_type:[{ - name: "M" - field: [ - {name:"_b_a_z_" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, - {name:"baz" number:2 label:LABEL_OPTIONAL type:TYPE_STRING} - ] - }]}] - `), - }, { - label: "proto3 message with unresolved enum", - inDesc: mustParseFile(` - name: "test.proto" - syntax: "proto3" - message_type: [{ - name: "M" - field: [ - {name:"enum" number:1 label:LABEL_OPTIONAL type:TYPE_ENUM type_name:".fizz.buzz.Enum"} - ] - }] - `), - inOpts: FileOptions{AllowUnresolvable: true}, - // TODO: Test field and oneof handling in validateMessageDeclarations - // TODO: Test unmarshalDefault - // TODO: Test validateExtensionDeclarations - // TODO: Test checkValidGroup - // TODO: Test checkValidMap - }, { - label: "empty service", - inDesc: mustParseFile(` - name: "test.proto" - service: [{name:"service"}] - `), - }, { - label: "service with method with unresolved", - inDesc: mustParseFile(` - name: "test.proto" - service: [{ - name: "service" - method: [{ - name:"method" - input_type:"foo" - output_type:".foo.bar.baz" - }] - }] - `), - inOpts: FileOptions{AllowUnresolvable: true}, - }, { - label: "service with wrong reference type", - inDeps: []*descriptorpb.FileDescriptorProto{ - cloneFile(proto3Message), - cloneFile(proto2Enum), - }, - inDesc: mustParseFile(` - name: "test.proto" - dependency: ["proto2_enum.proto", "proto3_message.proto"] - service: [{ - name: "service" - method: [{ - name: "method" - input_type: ".test.proto2.Enum", - output_type: ".test.proto3.Message" - }] - }] - `), - wantErr: `service method "service.method" cannot resolve input: resolved "test.proto2.Enum", but it is not an message`, - }} - - for _, tt := range tests { - t.Run(tt.label, func(t *testing.T) { - r := new(protoregistry.Files) - for i, dep := range tt.inDeps { - f, err := tt.inOpts.New(dep, r) - if err != nil { - t.Fatalf("dependency %d: unexpected NewFile() error: %v", i, err) - } - if err := r.RegisterFile(f); err != nil { - t.Fatalf("dependency %d: unexpected Register() error: %v", i, err) - } - } - var gotDesc *descriptorpb.FileDescriptorProto - if tt.wantErr == "" && tt.wantDesc == nil { - tt.wantDesc = cloneFile(tt.inDesc) - } - gotFile, err := tt.inOpts.New(tt.inDesc, r) - if gotFile != nil { - gotDesc = ToFileDescriptorProto(gotFile) - } - if !proto.Equal(gotDesc, tt.wantDesc) { - t.Errorf("NewFile() mismatch:\ngot %v\nwant %v", gotDesc, tt.wantDesc) - } - if ((err == nil) != (tt.wantErr == "")) || !strings.Contains(fmt.Sprint(err), tt.wantErr) { - t.Errorf("NewFile() error:\ngot: %v\nwant: %v", err, tt.wantErr) - } - }) - } -} - -func TestNewFiles(t *testing.T) { - fdset := &descriptorpb.FileDescriptorSet{ - File: []*descriptorpb.FileDescriptorProto{ - mustParseFile(` - name: "test.proto" - package: "fizz" - dependency: "dep.proto" - message_type: [{ - name: "M2" - field: [{name:"F" number:1 label:LABEL_OPTIONAL type:TYPE_MESSAGE type_name:"M1"}] - }] - `), - // Inputs deliberately out of order. - mustParseFile(` - name: "dep.proto" - package: "fizz" - message_type: [{name:"M1"}] - `), - }, - } - f, err := NewFiles(fdset) - if err != nil { - t.Fatal(err) - } - m1, err := f.FindDescriptorByName("fizz.M1") - if err != nil { - t.Fatalf(`f.FindDescriptorByName("fizz.M1") = %v`, err) - } - m2, err := f.FindDescriptorByName("fizz.M2") - if err != nil { - t.Fatalf(`f.FindDescriptorByName("fizz.M2") = %v`, err) - } - if m2.(protoreflect.MessageDescriptor).Fields().ByName("F").Message() != m1 { - t.Fatalf(`m1.Fields().ByName("F").Message() != m2`) - } -} - -func TestNewFilesImportCycle(t *testing.T) { - fdset := &descriptorpb.FileDescriptorSet{ - File: []*descriptorpb.FileDescriptorProto{ - mustParseFile(` - name: "test.proto" - package: "fizz" - dependency: "dep.proto" - `), - mustParseFile(` - name: "dep.proto" - package: "fizz" - dependency: "test.proto" - `), - }, - } - _, err := NewFiles(fdset) - if err == nil { - t.Fatal("NewFiles with import cycle: success, want error") - } -} - -func TestSourceLocations(t *testing.T) { - fd := mustParseFile(` - name: "comments.proto" - message_type: [{ - name: "Message1" - field: [ - {name:"field1" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}, - {name:"field2" number:2 label:LABEL_OPTIONAL type:TYPE_STRING}, - {name:"field3" number:3 label:LABEL_OPTIONAL type:TYPE_STRING oneof_index:0}, - {name:"field4" number:4 label:LABEL_OPTIONAL type:TYPE_STRING oneof_index:0}, - {name:"field5" number:5 label:LABEL_OPTIONAL type:TYPE_STRING oneof_index:1}, - {name:"field6" number:6 label:LABEL_OPTIONAL type:TYPE_STRING oneof_index:1} - ] - extension: [ - {name:"extension1" number:100 label:LABEL_OPTIONAL type:TYPE_STRING extendee:".Message1"}, - {name:"extension2" number:101 label:LABEL_OPTIONAL type:TYPE_STRING extendee:".Message1"} - ] - nested_type: [{name:"Message1"}, {name:"Message2"}] - extension_range: {start:100 end:536870912} - oneof_decl: [{name:"oneof1"}, {name:"oneof2"}] - }, { - name: "Message2" - enum_type: { - name: "Enum1" - value: [ - {name: "FOO", number: 0}, - {name: "BAR", number: 1} - ] - } - }] - enum_type: { - name: "Enum1" - value: [ - {name: "FOO", number: 0}, - {name: "BAR", number: 1} - ] - } - service: { - name: "Service1" - method: [ - {name:"Method1" input_type:".Message1" output_type:".Message1"}, - {name:"Method2" input_type:".Message2" output_type:".Message2"} - ] - } - extension: [ - {name:"extension1" number:102 label:LABEL_OPTIONAL type:TYPE_STRING extendee:".Message1"}, - {name:"extension2" number:103 label:LABEL_OPTIONAL type:TYPE_STRING extendee:".Message1"} - ] - source_code_info: { - location: [ - {span:[0,0,69,1]}, - {path:[12] span:[0,0,18]}, - {path:[5,0] span:[3,0,8,1] leading_comments:" Enum1\r\n"}, - {path:[5,0,1] span:[3,5,10]}, - {path:[5,0,2,0] span:[5,2,10] leading_comments:" FOO\r\n"}, - {path:[5,0,2,0,1] span:[5,2,5]}, - {path:[5,0,2,0,2] span:[5,8,9]}, - {path:[5,0,2,1] span:[7,2,10] leading_comments:" BAR\r\n"}, - {path:[5,0,2,1,1] span:[7,2,5]}, - {path:[5,0,2,1,2] span:[7,8,9]}, - {path:[4,0] span:[11,0,43,1] leading_comments:" Message1\r\n"}, - {path:[4,0,1] span:[11,8,16]}, - {path:[4,0,3,0] span:[13,2,21] leading_comments:" Message1.Message1\r\n"}, - {path:[4,0,3,0,1] span:[13,10,18]}, - {path:[4,0,3,1] span:[15,2,21] leading_comments:" Message1.Message2\r\n"}, - {path:[4,0,3,1,1] span:[15,10,18]}, - {path:[4,0,2,0] span:[18,2,29] leading_comments:" Message1.field1\r\n"}, - {path:[4,0,2,0,4] span:[18,2,10]}, - {path:[4,0,2,0,5] span:[18,11,17]}, - {path:[4,0,2,0,1] span:[18,18,24]}, - {path:[4,0,2,0,3] span:[18,27,28]}, - {path:[4,0,2,1] span:[20,2,29] leading_comments:" Message1.field2\r\n"}, - {path:[4,0,2,1,4] span:[20,2,10]}, - {path:[4,0,2,1,5] span:[20,11,17]}, - {path:[4,0,2,1,1] span:[20,18,24]}, - {path:[4,0,2,1,3] span:[20,27,28]}, - {path:[4,0,8,0] span:[22,2,27,3] leading_comments:" Message1.oneof1\r\n"}, - {path:[4,0,8,0,1] span:[22,8,14]}, - {path:[4,0,2,2] span:[24,4,22] leading_comments:" Message1.field3\r\n"}, - {path:[4,0,2,2,5] span:[24,4,10]}, - {path:[4,0,2,2,1] span:[24,11,17]}, - {path:[4,0,2,2,3] span:[24,20,21]}, - {path:[4,0,2,3] span:[26,4,22] leading_comments:" Message1.field4\r\n"}, - {path:[4,0,2,3,5] span:[26,4,10]}, - {path:[4,0,2,3,1] span:[26,11,17]}, - {path:[4,0,2,3,3] span:[26,20,21]}, - {path:[4,0,8,1] span:[29,2,34,3] leading_comments:" Message1.oneof2\r\n"}, - {path:[4,0,8,1,1] span:[29,8,14]}, - {path:[4,0,2,4] span:[31,4,22] leading_comments:" Message1.field5\r\n"}, - {path:[4,0,2,4,5] span:[31,4,10]}, - {path:[4,0,2,4,1] span:[31,11,17]}, - {path:[4,0,2,4,3] span:[31,20,21]}, - {path:[4,0,2,5] span:[33,4,22] leading_comments:" Message1.field6\r\n"}, - {path:[4,0,2,5,5] span:[33,4,10]}, - {path:[4,0,2,5,1] span:[33,11,17]}, - {path:[4,0,2,5,3] span:[33,20,21]}, - {path:[4,0,5] span:[36,2,24]}, - {path:[4,0,5,0] span:[36,13,23]}, - {path:[4,0,5,0,1] span:[36,13,16]}, - {path:[4,0,5,0,2] span:[36,20,23]}, - {path:[4,0,6] span:[37,2,42,3]}, - {path:[4,0,6,0] span:[39,4,37] leading_comments:" Message1.extension1\r\n"}, - {path:[4,0,6,0,2] span:[37,9,18]}, - {path:[4,0,6,0,4] span:[39,4,12]}, - {path:[4,0,6,0,5] span:[39,13,19]}, - {path:[4,0,6,0,1] span:[39,20,30]}, - {path:[4,0,6,0,3] span:[39,33,36]}, - {path:[4,0,6,1] span:[41,4,37] leading_comments:" Message1.extension2\r\n"}, - {path:[4,0,6,1,2] span:[37,9,18]}, - {path:[4,0,6,1,4] span:[41,4,12]}, - {path:[4,0,6,1,5] span:[41,13,19]}, - {path:[4,0,6,1,1] span:[41,20,30]}, - {path:[4,0,6,1,3] span:[41,33,36]}, - {path:[7] span:[45,0,50,1]}, - {path:[7,0] span:[47,2,35] leading_comments:" extension1\r\n"}, - {path:[7,0,2] span:[45,7,15]}, - {path:[7,0,4] span:[47,2,10]}, - {path:[7,0,5] span:[47,11,17]}, - {path:[7,0,1] span:[47,18,28]}, - {path:[7,0,3] span:[47,31,34]}, - {path:[7,1] span:[49,2,35] leading_comments:" extension2\r\n"}, - {path:[7,1,2] span:[45,7,15]}, - {path:[7,1,4] span:[49,2,10]}, - {path:[7,1,5] span:[49,11,17]}, - {path:[7,1,1] span:[49,18,28]}, - {path:[7,1,3] span:[49,31,34]}, - {path:[4,1] span:[53,0,61,1] leading_comments:" Message2\r\n"}, - {path:[4,1,1] span:[53,8,16]}, - {path:[4,1,4,0] span:[55,2,60,3] leading_comments:" Message2.Enum1\r\n"}, - {path:[4,1,4,0,1] span:[55,7,12]}, - {path:[4,1,4,0,2,0] span:[57,4,12] leading_comments:" Message2.FOO\r\n"}, - {path:[4,1,4,0,2,0,1] span:[57,4,7]}, - {path:[4,1,4,0,2,0,2] span:[57,10,11]}, - {path:[4,1,4,0,2,1] span:[59,4,12] leading_comments:" Message2.BAR\r\n"}, - {path:[4,1,4,0,2,1,1] span:[59,4,7]}, - {path:[4,1,4,0,2,1,2] span:[59,10,11]}, - {path:[6,0] span:[64,0,69,1] leading_comments:" Service1\r\n"}, - {path:[6,0,1] span:[64,8,16]}, - {path:[6,0,2,0] span:[66,2,43] leading_comments:" Service1.Method1\r\n"}, - {path:[6,0,2,0,1] span:[66,6,13]}, - {path:[6,0,2,0,2] span:[66,14,22]}, - {path:[6,0,2,0,3] span:[66,33,41]}, - {path:[6,0,2,1] span:[68,2,43] leading_comments:" Service1.Method2\r\n"}, - {path:[6,0,2,1,1] span:[68,6,13]}, - {path:[6,0,2,1,2] span:[68,14,22]}, - {path:[6,0,2,1,3] span:[68,33,41]} - ] - } - `) - fileDesc, err := NewFile(fd, nil) - if err != nil { - t.Fatalf("NewFile error: %v", err) - } - - var walkDescs func(protoreflect.Descriptor, func(protoreflect.Descriptor)) - walkDescs = func(d protoreflect.Descriptor, f func(protoreflect.Descriptor)) { - f(d) - if d, ok := d.(interface { - Enums() protoreflect.EnumDescriptors - }); ok { - eds := d.Enums() - for i := 0; i < eds.Len(); i++ { - walkDescs(eds.Get(i), f) - } - } - if d, ok := d.(interface { - Values() protoreflect.EnumValueDescriptors - }); ok { - vds := d.Values() - for i := 0; i < vds.Len(); i++ { - walkDescs(vds.Get(i), f) - } - } - if d, ok := d.(interface { - Messages() protoreflect.MessageDescriptors - }); ok { - mds := d.Messages() - for i := 0; i < mds.Len(); i++ { - walkDescs(mds.Get(i), f) - } - } - if d, ok := d.(interface { - Fields() protoreflect.FieldDescriptors - }); ok { - fds := d.Fields() - for i := 0; i < fds.Len(); i++ { - walkDescs(fds.Get(i), f) - } - } - if d, ok := d.(interface { - Oneofs() protoreflect.OneofDescriptors - }); ok { - ods := d.Oneofs() - for i := 0; i < ods.Len(); i++ { - walkDescs(ods.Get(i), f) - } - } - if d, ok := d.(interface { - Extensions() protoreflect.ExtensionDescriptors - }); ok { - xds := d.Extensions() - for i := 0; i < xds.Len(); i++ { - walkDescs(xds.Get(i), f) - } - } - if d, ok := d.(interface { - Services() protoreflect.ServiceDescriptors - }); ok { - sds := d.Services() - for i := 0; i < sds.Len(); i++ { - walkDescs(sds.Get(i), f) - } - } - if d, ok := d.(interface { - Methods() protoreflect.MethodDescriptors - }); ok { - mds := d.Methods() - for i := 0; i < mds.Len(); i++ { - walkDescs(mds.Get(i), f) - } - } - } - - var numDescs int - walkDescs(fileDesc, func(d protoreflect.Descriptor) { - // The comment for every descriptor should be the full name itself. - got := strings.TrimSpace(fileDesc.SourceLocations().ByDescriptor(d).LeadingComments) - want := string(d.FullName()) - if got != want { - t.Errorf("comment mismatch: got %v, want %v", got, want) - } - numDescs++ - }) - if numDescs != 30 { - t.Errorf("visited %d descriptor, expected 30", numDescs) - } -} diff --git a/vendor/google.golang.org/protobuf/reflect/protodesc/gotest/ya.make b/vendor/google.golang.org/protobuf/reflect/protodesc/gotest/ya.make deleted file mode 100644 index 18b2ef76c1..0000000000 --- a/vendor/google.golang.org/protobuf/reflect/protodesc/gotest/ya.make +++ /dev/null @@ -1,5 +0,0 @@ -GO_TEST_FOR(vendor/google.golang.org/protobuf/reflect/protodesc) - -LICENSE(BSD-3-Clause) - -END() diff --git a/vendor/google.golang.org/protobuf/reflect/protodesc/proto.go b/vendor/google.golang.org/protobuf/reflect/protodesc/proto.go index a7c5ceffc9..9d6e05420f 100644 --- a/vendor/google.golang.org/protobuf/reflect/protodesc/proto.go +++ b/vendor/google.golang.org/protobuf/reflect/protodesc/proto.go @@ -16,7 +16,7 @@ import ( "google.golang.org/protobuf/types/descriptorpb" ) -// ToFileDescriptorProto copies a protoreflect.FileDescriptor into a +// ToFileDescriptorProto copies a [protoreflect.FileDescriptor] into a // google.protobuf.FileDescriptorProto message. func ToFileDescriptorProto(file protoreflect.FileDescriptor) *descriptorpb.FileDescriptorProto { p := &descriptorpb.FileDescriptorProto{ @@ -70,13 +70,13 @@ func ToFileDescriptorProto(file protoreflect.FileDescriptor) *descriptorpb.FileD 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 { + 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 +// ToDescriptorProto copies a [protoreflect.MessageDescriptor] into a // google.protobuf.DescriptorProto message. func ToDescriptorProto(message protoreflect.MessageDescriptor) *descriptorpb.DescriptorProto { p := &descriptorpb.DescriptorProto{ @@ -119,7 +119,7 @@ func ToDescriptorProto(message protoreflect.MessageDescriptor) *descriptorpb.Des return p } -// ToFieldDescriptorProto copies a protoreflect.FieldDescriptor into a +// ToFieldDescriptorProto copies a [protoreflect.FieldDescriptor] into a // google.protobuf.FieldDescriptorProto message. func ToFieldDescriptorProto(field protoreflect.FieldDescriptor) *descriptorpb.FieldDescriptorProto { p := &descriptorpb.FieldDescriptorProto{ @@ -168,7 +168,7 @@ func ToFieldDescriptorProto(field protoreflect.FieldDescriptor) *descriptorpb.Fi return p } -// ToOneofDescriptorProto copies a protoreflect.OneofDescriptor into a +// ToOneofDescriptorProto copies a [protoreflect.OneofDescriptor] into a // google.protobuf.OneofDescriptorProto message. func ToOneofDescriptorProto(oneof protoreflect.OneofDescriptor) *descriptorpb.OneofDescriptorProto { return &descriptorpb.OneofDescriptorProto{ @@ -177,7 +177,7 @@ func ToOneofDescriptorProto(oneof protoreflect.OneofDescriptor) *descriptorpb.On } } -// ToEnumDescriptorProto copies a protoreflect.EnumDescriptor into a +// ToEnumDescriptorProto copies a [protoreflect.EnumDescriptor] into a // google.protobuf.EnumDescriptorProto message. func ToEnumDescriptorProto(enum protoreflect.EnumDescriptor) *descriptorpb.EnumDescriptorProto { p := &descriptorpb.EnumDescriptorProto{ @@ -200,7 +200,7 @@ func ToEnumDescriptorProto(enum protoreflect.EnumDescriptor) *descriptorpb.EnumD return p } -// ToEnumValueDescriptorProto copies a protoreflect.EnumValueDescriptor into a +// ToEnumValueDescriptorProto copies a [protoreflect.EnumValueDescriptor] into a // google.protobuf.EnumValueDescriptorProto message. func ToEnumValueDescriptorProto(value protoreflect.EnumValueDescriptor) *descriptorpb.EnumValueDescriptorProto { return &descriptorpb.EnumValueDescriptorProto{ @@ -210,7 +210,7 @@ func ToEnumValueDescriptorProto(value protoreflect.EnumValueDescriptor) *descrip } } -// ToServiceDescriptorProto copies a protoreflect.ServiceDescriptor into a +// ToServiceDescriptorProto copies a [protoreflect.ServiceDescriptor] into a // google.protobuf.ServiceDescriptorProto message. func ToServiceDescriptorProto(service protoreflect.ServiceDescriptor) *descriptorpb.ServiceDescriptorProto { p := &descriptorpb.ServiceDescriptorProto{ @@ -223,7 +223,7 @@ func ToServiceDescriptorProto(service protoreflect.ServiceDescriptor) *descripto return p } -// ToMethodDescriptorProto copies a protoreflect.MethodDescriptor into a +// ToMethodDescriptorProto copies a [protoreflect.MethodDescriptor] into a // google.protobuf.MethodDescriptorProto message. func ToMethodDescriptorProto(method protoreflect.MethodDescriptor) *descriptorpb.MethodDescriptorProto { p := &descriptorpb.MethodDescriptorProto{ diff --git a/vendor/google.golang.org/protobuf/reflect/protodesc/ya.make b/vendor/google.golang.org/protobuf/reflect/protodesc/ya.make index 2a4f165b31..20d7db3136 100644 --- a/vendor/google.golang.org/protobuf/reflect/protodesc/ya.make +++ b/vendor/google.golang.org/protobuf/reflect/protodesc/ya.make @@ -7,11 +7,10 @@ SRCS( desc_init.go desc_resolve.go desc_validate.go + editions.go proto.go ) -GO_TEST_SRCS(file_test.go) +GO_EMBED_PATTERN(editions_defaults.binpb) END() - -RECURSE(gotest) diff --git a/vendor/google.golang.org/protobuf/reflect/protopath/path.go b/vendor/google.golang.org/protobuf/reflect/protopath/path.go index 91562a8213..fffac00ebc 100644 --- a/vendor/google.golang.org/protobuf/reflect/protopath/path.go +++ b/vendor/google.golang.org/protobuf/reflect/protopath/path.go @@ -17,14 +17,14 @@ import ( // where you would like to "address" some value in a message with just the path // and don't have the value information available. // -// This is different from how "github.com/google/go-cmp/cmp".Path operates, +// This is different from how github.com/google/go-cmp/cmp.Path operates, // which combines both path and value information together. // Since the cmp package itself is the only one ever constructing a cmp.Path, // it will always have the value available. // Path is a sequence of protobuf reflection steps applied to some root // protobuf message value to arrive at the current value. -// The first step must be a Root step. +// The first step must be a [Root] step. type Path []Step // TODO: Provide a Parse function that parses something similar to or @@ -55,8 +55,8 @@ func (p Path) String() string { } // Values is a Path paired with a sequence of values at each step. -// The lengths of Path and Values must be identical. -// The first step must be a Root step and +// The lengths of [Values.Path] and [Values.Values] must be identical. +// The first step must be a [Root] step and // the first value must be a concrete message value. type Values struct { Path Path diff --git a/vendor/google.golang.org/protobuf/reflect/protorange/example_test.go b/vendor/google.golang.org/protobuf/reflect/protorange/example_test.go deleted file mode 100644 index 90ceec6c2d..0000000000 --- a/vendor/google.golang.org/protobuf/reflect/protorange/example_test.go +++ /dev/null @@ -1,307 +0,0 @@ -// Copyright 2020 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 protorange_test - -import ( - "fmt" - "strings" - "time" - - "google.golang.org/protobuf/encoding/protojson" - "google.golang.org/protobuf/internal/detrand" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protopath" - "google.golang.org/protobuf/reflect/protorange" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/testing/protopack" - "google.golang.org/protobuf/types/known/anypb" - "google.golang.org/protobuf/types/known/timestamppb" - - newspb "google.golang.org/protobuf/internal/testprotos/news" -) - -func init() { - detrand.Disable() -} - -func mustMarshal(m proto.Message) []byte { - b, err := proto.Marshal(m) - if err != nil { - panic(err) - } - return b -} - -// Range through every message and clear the unknown fields. -func Example_discardUnknown() { - // Populate the article with unknown fields. - m := &newspb.Article{} - m.ProtoReflect().SetUnknown(protopack.Message{ - protopack.Tag{1000, protopack.BytesType}, protopack.String("Hello, world!"), - }.Marshal()) - fmt.Println("has unknown fields?", len(m.ProtoReflect().GetUnknown()) > 0) - - // Range through the message and clear all unknown fields. - fmt.Println("clear unknown fields") - protorange.Range(m.ProtoReflect(), func(proto protopath.Values) error { - m, ok := proto.Index(-1).Value.Interface().(protoreflect.Message) - if ok && len(m.GetUnknown()) > 0 { - m.SetUnknown(nil) - } - return nil - }) - fmt.Println("has unknown fields?", len(m.ProtoReflect().GetUnknown()) > 0) - - // Output: - // has unknown fields? true - // clear unknown fields - // has unknown fields? false -} - -// Print the relative paths as Range iterates through a message -// in a depth-first order. -func Example_printPaths() { - m := &newspb.Article{ - Author: "Russ Cox", - Date: timestamppb.New(time.Date(2019, time.November, 8, 0, 0, 0, 0, time.UTC)), - Title: "Go Turns 10", - Content: "Happy birthday, Go! This weekend we celebrate the 10th anniversary of the Go release...", - Status: newspb.Article_PUBLISHED, - Tags: []string{"community", "birthday"}, - Attachments: []*anypb.Any{{ - TypeUrl: "google.golang.org.BinaryAttachment", - Value: mustMarshal(&newspb.BinaryAttachment{ - Name: "gopher-birthday.png", - Data: []byte("<binary data>"), - }), - }}, - } - - // Traverse over all reachable values and print the path. - protorange.Range(m.ProtoReflect(), func(p protopath.Values) error { - fmt.Println(p.Path[1:]) - return nil - }) - - // Output: - // .author - // .date - // .date.seconds - // .title - // .content - // .status - // .tags - // .tags[0] - // .tags[1] - // .attachments - // .attachments[0] - // .attachments[0].(google.golang.org.BinaryAttachment) - // .attachments[0].(google.golang.org.BinaryAttachment).name - // .attachments[0].(google.golang.org.BinaryAttachment).data -} - -// Implement a basic text formatter by ranging through all populated values -// in a message in depth-first order. -func Example_formatText() { - m := &newspb.Article{ - Author: "Brad Fitzpatrick", - Date: timestamppb.New(time.Date(2018, time.February, 16, 0, 0, 0, 0, time.UTC)), - Title: "Go 1.10 is released", - Content: "Happy Friday, happy weekend! Today the Go team is happy to announce the release of Go 1.10...", - Status: newspb.Article_PUBLISHED, - Tags: []string{"go1.10", "release"}, - Attachments: []*anypb.Any{{ - TypeUrl: "google.golang.org.KeyValueAttachment", - Value: mustMarshal(&newspb.KeyValueAttachment{ - Name: "checksums.txt", - Data: map[string]string{ - "go1.10.src.tar.gz": "07cbb9d0091b846c6aea40bf5bc0cea7", - "go1.10.darwin-amd64.pkg": "cbb38bb6ff6ea86279e01745984445bf", - "go1.10.linux-amd64.tar.gz": "6b3d0e4a5c77352cf4275573817f7566", - "go1.10.windows-amd64.msi": "57bda02030f58f5d2bf71943e1390123", - }, - }), - }}, - } - - // Print a message in a humanly readable format. - var indent []byte - protorange.Options{ - Stable: true, - }.Range(m.ProtoReflect(), - func(p protopath.Values) error { - // Print the key. - var fd protoreflect.FieldDescriptor - last := p.Index(-1) - beforeLast := p.Index(-2) - switch last.Step.Kind() { - case protopath.FieldAccessStep: - fd = last.Step.FieldDescriptor() - fmt.Printf("%s%s: ", indent, fd.Name()) - case protopath.ListIndexStep: - fd = beforeLast.Step.FieldDescriptor() // lists always appear in the context of a repeated field - fmt.Printf("%s%d: ", indent, last.Step.ListIndex()) - case protopath.MapIndexStep: - fd = beforeLast.Step.FieldDescriptor() // maps always appear in the context of a repeated field - fmt.Printf("%s%v: ", indent, last.Step.MapIndex().Interface()) - case protopath.AnyExpandStep: - fmt.Printf("%s[%v]: ", indent, last.Value.Message().Descriptor().FullName()) - case protopath.UnknownAccessStep: - fmt.Printf("%s?: ", indent) - } - - // Starting printing the value. - switch v := last.Value.Interface().(type) { - case protoreflect.Message: - fmt.Printf("{\n") - indent = append(indent, '\t') - case protoreflect.List: - fmt.Printf("[\n") - indent = append(indent, '\t') - case protoreflect.Map: - fmt.Printf("{\n") - indent = append(indent, '\t') - case protoreflect.EnumNumber: - var ev protoreflect.EnumValueDescriptor - if fd != nil { - ev = fd.Enum().Values().ByNumber(v) - } - if ev != nil { - fmt.Printf("%v\n", ev.Name()) - } else { - fmt.Printf("%v\n", v) - } - case string, []byte: - fmt.Printf("%q\n", v) - default: - fmt.Printf("%v\n", v) - } - return nil - }, - func(p protopath.Values) error { - // Finish printing the value. - last := p.Index(-1) - switch last.Value.Interface().(type) { - case protoreflect.Message: - indent = indent[:len(indent)-1] - fmt.Printf("%s}\n", indent) - case protoreflect.List: - indent = indent[:len(indent)-1] - fmt.Printf("%s]\n", indent) - case protoreflect.Map: - indent = indent[:len(indent)-1] - fmt.Printf("%s}\n", indent) - } - return nil - }, - ) - - // Output: - // { - // author: "Brad Fitzpatrick" - // date: { - // seconds: 1518739200 - // } - // title: "Go 1.10 is released" - // content: "Happy Friday, happy weekend! Today the Go team is happy to announce the release of Go 1.10..." - // attachments: [ - // 0: { - // [google.golang.org.KeyValueAttachment]: { - // name: "checksums.txt" - // data: { - // go1.10.darwin-amd64.pkg: "cbb38bb6ff6ea86279e01745984445bf" - // go1.10.linux-amd64.tar.gz: "6b3d0e4a5c77352cf4275573817f7566" - // go1.10.src.tar.gz: "07cbb9d0091b846c6aea40bf5bc0cea7" - // go1.10.windows-amd64.msi: "57bda02030f58f5d2bf71943e1390123" - // } - // } - // } - // ] - // tags: [ - // 0: "go1.10" - // 1: "release" - // ] - // status: PUBLISHED - // } -} - -// Scan all protobuf string values for a sensitive word and replace it with -// a suitable alternative. -func Example_sanitizeStrings() { - m := &newspb.Article{ - Author: "Hermione Granger", - Date: timestamppb.New(time.Date(1998, time.May, 2, 0, 0, 0, 0, time.UTC)), - Title: "Harry Potter vanquishes Voldemort once and for all!", - Content: "In a final duel between Harry Potter and Lord Voldemort earlier this evening...", - Tags: []string{"HarryPotter", "LordVoldemort"}, - Attachments: []*anypb.Any{{ - TypeUrl: "google.golang.org.KeyValueAttachment", - Value: mustMarshal(&newspb.KeyValueAttachment{ - Name: "aliases.txt", - Data: map[string]string{ - "Harry Potter": "The Boy Who Lived", - "Tom Riddle": "Lord Voldemort", - }, - }), - }}, - } - - protorange.Range(m.ProtoReflect(), func(p protopath.Values) error { - const ( - sensitive = "Voldemort" - alternative = "[He-Who-Must-Not-Be-Named]" - ) - - // Check if there is a sensitive word to redact. - last := p.Index(-1) - s, ok := last.Value.Interface().(string) - if !ok || !strings.Contains(s, sensitive) { - return nil - } - s = strings.Replace(s, sensitive, alternative, -1) - - // Store the redacted string back into the message. - beforeLast := p.Index(-2) - switch last.Step.Kind() { - case protopath.FieldAccessStep: - m := beforeLast.Value.Message() - fd := last.Step.FieldDescriptor() - m.Set(fd, protoreflect.ValueOfString(s)) - case protopath.ListIndexStep: - ls := beforeLast.Value.List() - i := last.Step.ListIndex() - ls.Set(i, protoreflect.ValueOfString(s)) - case protopath.MapIndexStep: - ms := beforeLast.Value.Map() - k := last.Step.MapIndex() - ms.Set(k, protoreflect.ValueOfString(s)) - } - return nil - }) - - fmt.Println(protojson.Format(m)) - - // Output: - // { - // "author": "Hermione Granger", - // "date": "1998-05-02T00:00:00Z", - // "title": "Harry Potter vanquishes [He-Who-Must-Not-Be-Named] once and for all!", - // "content": "In a final duel between Harry Potter and Lord [He-Who-Must-Not-Be-Named] earlier this evening...", - // "tags": [ - // "HarryPotter", - // "Lord[He-Who-Must-Not-Be-Named]" - // ], - // "attachments": [ - // { - // "@type": "google.golang.org.KeyValueAttachment", - // "name": "aliases.txt", - // "data": { - // "Harry Potter": "The Boy Who Lived", - // "Tom Riddle": "Lord [He-Who-Must-Not-Be-Named]" - // } - // } - // ] - // } -} diff --git a/vendor/google.golang.org/protobuf/reflect/protorange/gotest/ya.make b/vendor/google.golang.org/protobuf/reflect/protorange/gotest/ya.make deleted file mode 100644 index 261b6ab9e8..0000000000 --- a/vendor/google.golang.org/protobuf/reflect/protorange/gotest/ya.make +++ /dev/null @@ -1,5 +0,0 @@ -GO_TEST_FOR(vendor/google.golang.org/protobuf/reflect/protorange) - -LICENSE(BSD-3-Clause) - -END() diff --git a/vendor/google.golang.org/protobuf/reflect/protorange/range.go b/vendor/google.golang.org/protobuf/reflect/protorange/range.go index 6f4c58bfb7..7a032758b5 100644 --- a/vendor/google.golang.org/protobuf/reflect/protorange/range.go +++ b/vendor/google.golang.org/protobuf/reflect/protorange/range.go @@ -30,7 +30,7 @@ var ( // Range performs a depth-first traversal over reachable values in a message. // -// See Options.Range for details. +// See [Options.Range] for details. func Range(m protoreflect.Message, f func(protopath.Values) error) error { return Options{}.Range(m, f, nil) } @@ -61,33 +61,33 @@ type Options struct { } // Range performs a depth-first traversal over reachable values in a message. -// The first push and the last pop are to push/pop a protopath.Root step. -// If push or pop return any non-nil error (other than Break or Terminate), +// The first push and the last pop are to push/pop a [protopath.Root] step. +// If push or pop return any non-nil error (other than [Break] or [Terminate]), // it terminates the traversal and is returned by Range. // // The rules for traversing a message is as follows: // -// โข For messages, iterate over every populated known and extension field. -// Each field is preceded by a push of a protopath.FieldAccess step, -// followed by recursive application of the rules on the field value, -// and succeeded by a pop of that step. -// If the message has unknown fields, then push an protopath.UnknownAccess step -// followed immediately by pop of that step. +// - For messages, iterate over every populated known and extension field. +// Each field is preceded by a push of a [protopath.FieldAccess] step, +// followed by recursive application of the rules on the field value, +// and succeeded by a pop of that step. +// If the message has unknown fields, then push an [protopath.UnknownAccess] step +// followed immediately by pop of that step. // -// โข As an exception to the above rule, if the current message is a -// google.protobuf.Any message, expand the underlying message (if resolvable). -// The expanded message is preceded by a push of a protopath.AnyExpand step, -// followed by recursive application of the rules on the underlying message, -// and succeeded by a pop of that step. Mutations to the expanded message -// are written back to the Any message when popping back out. +// - As an exception to the above rule, if the current message is a +// google.protobuf.Any message, expand the underlying message (if resolvable). +// The expanded message is preceded by a push of a [protopath.AnyExpand] step, +// followed by recursive application of the rules on the underlying message, +// and succeeded by a pop of that step. Mutations to the expanded message +// are written back to the Any message when popping back out. // -// โข For lists, iterate over every element. Each element is preceded by a push -// of a protopath.ListIndex step, followed by recursive application of the rules -// on the list element, and succeeded by a pop of that step. +// - For lists, iterate over every element. Each element is preceded by a push +// of a [protopath.ListIndex] step, followed by recursive application of the rules +// on the list element, and succeeded by a pop of that step. // -// โข For maps, iterate over every entry. Each entry is preceded by a push -// of a protopath.MapIndex step, followed by recursive application of the rules -// on the map entry value, and succeeded by a pop of that step. +// - For maps, iterate over every entry. Each entry is preceded by a push +// of a [protopath.MapIndex] step, followed by recursive application of the rules +// on the map entry value, and succeeded by a pop of that step. // // Mutations should only be made to the last value, otherwise the effects on // traversal will be undefined. If the mutation is made to the last value @@ -96,7 +96,7 @@ type Options struct { // populates a few fields in that message, then the newly modified fields // will be traversed. // -// The protopath.Values provided to push functions is only valid until the +// The [protopath.Values] provided to push functions is only valid until the // corresponding pop call and the values provided to a pop call is only valid // for the duration of the pop call itself. func (o Options) Range(m protoreflect.Message, push, pop func(protopath.Values) error) error { diff --git a/vendor/google.golang.org/protobuf/reflect/protorange/range_test.go b/vendor/google.golang.org/protobuf/reflect/protorange/range_test.go deleted file mode 100644 index a8ca6a0b62..0000000000 --- a/vendor/google.golang.org/protobuf/reflect/protorange/range_test.go +++ /dev/null @@ -1,253 +0,0 @@ -// Copyright 2020 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 protorange - -import ( - "testing" - "time" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/reflect/protopath" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - "google.golang.org/protobuf/testing/protocmp" - - newspb "google.golang.org/protobuf/internal/testprotos/news" - anypb "google.golang.org/protobuf/types/known/anypb" - timestamppb "google.golang.org/protobuf/types/known/timestamppb" -) - -func mustMarshal(m proto.Message) []byte { - b, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) - if err != nil { - panic(err) - } - return b -} - -var transformReflectValue = cmp.Transformer("", func(v protoreflect.Value) interface{} { - switch v := v.Interface().(type) { - case protoreflect.Message: - return v.Interface() - case protoreflect.Map: - ms := map[interface{}]protoreflect.Value{} - v.Range(func(k protoreflect.MapKey, v protoreflect.Value) bool { - ms[k.Interface()] = v - return true - }) - return ms - case protoreflect.List: - ls := []protoreflect.Value{} - for i := 0; i < v.Len(); i++ { - ls = append(ls, v.Get(i)) - } - return ls - default: - return v - } -}) - -func TestRange(t *testing.T) { - m2 := (&newspb.KeyValueAttachment{ - Name: "checksums.txt", - Data: map[string]string{ - "go1.10.src.tar.gz": "07cbb9d0091b846c6aea40bf5bc0cea7", - "go1.10.darwin-amd64.pkg": "cbb38bb6ff6ea86279e01745984445bf", - "go1.10.linux-amd64.tar.gz": "6b3d0e4a5c77352cf4275573817f7566", - "go1.10.windows-amd64.msi": "57bda02030f58f5d2bf71943e1390123", - }, - }).ProtoReflect() - m := (&newspb.Article{ - Author: "Brad Fitzpatrick", - Date: timestamppb.New(time.Date(2018, time.February, 16, 0, 0, 0, 0, time.UTC)), - Title: "Go 1.10 is released", - Content: "Happy Friday, happy weekend! Today the Go team is happy to announce the release of Go 1.10...", - Status: newspb.Article_PUBLISHED, - Tags: []string{"go1.10", "release"}, - Attachments: []*anypb.Any{{ - TypeUrl: "google.golang.org.KeyValueAttachment", - Value: mustMarshal(m2.Interface()), - }}, - }).ProtoReflect() - - // Nil push and pop functions should not panic. - noop := func(protopath.Values) error { return nil } - Options{}.Range(m, nil, nil) - Options{}.Range(m, noop, nil) - Options{}.Range(m, nil, noop) - - getByName := func(m protoreflect.Message, s protoreflect.Name) protoreflect.Value { - fds := m.Descriptor().Fields() - return m.Get(fds.ByName(s)) - } - - wantPaths := []string{ - ``, - `.author`, - `.date`, - `.date.seconds`, - `.title`, - `.content`, - `.attachments`, - `.attachments[0]`, - `.attachments[0].(google.golang.org.KeyValueAttachment)`, - `.attachments[0].(google.golang.org.KeyValueAttachment).name`, - `.attachments[0].(google.golang.org.KeyValueAttachment).data`, - `.attachments[0].(google.golang.org.KeyValueAttachment).data["go1.10.darwin-amd64.pkg"]`, - `.attachments[0].(google.golang.org.KeyValueAttachment).data["go1.10.linux-amd64.tar.gz"]`, - `.attachments[0].(google.golang.org.KeyValueAttachment).data["go1.10.src.tar.gz"]`, - `.attachments[0].(google.golang.org.KeyValueAttachment).data["go1.10.windows-amd64.msi"]`, - `.tags`, - `.tags[0]`, - `.tags[1]`, - `.status`, - } - wantValues := []protoreflect.Value{ - protoreflect.ValueOfMessage(m), - getByName(m, "author"), - getByName(m, "date"), - getByName(getByName(m, "date").Message(), "seconds"), - getByName(m, `title`), - getByName(m, `content`), - getByName(m, `attachments`), - getByName(m, `attachments`).List().Get(0), - protoreflect.ValueOfMessage(m2), - getByName(m2, `name`), - getByName(m2, `data`), - getByName(m2, `data`).Map().Get(protoreflect.ValueOfString("go1.10.darwin-amd64.pkg").MapKey()), - getByName(m2, `data`).Map().Get(protoreflect.ValueOfString("go1.10.linux-amd64.tar.gz").MapKey()), - getByName(m2, `data`).Map().Get(protoreflect.ValueOfString("go1.10.src.tar.gz").MapKey()), - getByName(m2, `data`).Map().Get(protoreflect.ValueOfString("go1.10.windows-amd64.msi").MapKey()), - getByName(m, `tags`), - getByName(m, `tags`).List().Get(0), - getByName(m, `tags`).List().Get(1), - getByName(m, `status`), - } - - tests := []struct { - resolver interface { - protoregistry.ExtensionTypeResolver - protoregistry.MessageTypeResolver - } - - errorAt int - breakAt int - terminateAt int - - wantPaths []string - wantValues []protoreflect.Value - wantError error - }{{ - wantPaths: wantPaths, - wantValues: wantValues, - }, { - resolver: (*protoregistry.Types)(nil), - wantPaths: append(append(wantPaths[:8:8], - `.attachments[0].type_url`, - `.attachments[0].value`, - ), wantPaths[15:]...), - wantValues: append(append(wantValues[:8:8], - protoreflect.ValueOfString("google.golang.org.KeyValueAttachment"), - protoreflect.ValueOfBytes(mustMarshal(m2.Interface())), - ), wantValues[15:]...), - }, { - errorAt: 5, // return error within newspb.Article - wantPaths: wantPaths[:5], - wantValues: wantValues[:5], - wantError: cmpopts.AnyError, - }, { - terminateAt: 11, // terminate within newspb.KeyValueAttachment - wantPaths: wantPaths[:11], - wantValues: wantValues[:11], - }, { - breakAt: 11, // break within newspb.KeyValueAttachment - wantPaths: append(wantPaths[:11:11], wantPaths[15:]...), - wantValues: append(wantValues[:11:11], wantValues[15:]...), - }, { - errorAt: 17, // return error within newspb.Article.Tags - wantPaths: wantPaths[:17], - wantValues: wantValues[:17], - wantError: cmpopts.AnyError, - }, { - breakAt: 17, // break within newspb.Article.Tags - wantPaths: append(wantPaths[:17:17], wantPaths[18:]...), - wantValues: append(wantValues[:17:17], wantValues[18:]...), - }, { - terminateAt: 17, // terminate within newspb.Article.Tags - wantPaths: wantPaths[:17], - wantValues: wantValues[:17], - }, { - errorAt: 13, // return error within newspb.KeyValueAttachment.Data - wantPaths: wantPaths[:13], - wantValues: wantValues[:13], - wantError: cmpopts.AnyError, - }, { - breakAt: 13, // break within newspb.KeyValueAttachment.Data - wantPaths: append(wantPaths[:13:13], wantPaths[15:]...), - wantValues: append(wantValues[:13:13], wantValues[15:]...), - }, { - terminateAt: 13, // terminate within newspb.KeyValueAttachment.Data - wantPaths: wantPaths[:13], - wantValues: wantValues[:13], - }} - for _, tt := range tests { - t.Run("", func(t *testing.T) { - var gotPaths []string - var gotValues []protoreflect.Value - var stackPaths []string - var stackValues []protoreflect.Value - gotError := Options{ - Stable: true, - Resolver: tt.resolver, - }.Range(m, - func(p protopath.Values) error { - gotPaths = append(gotPaths, p.Path[1:].String()) - stackPaths = append(stackPaths, p.Path[1:].String()) - gotValues = append(gotValues, p.Index(-1).Value) - stackValues = append(stackValues, p.Index(-1).Value) - switch { - case tt.errorAt > 0 && tt.errorAt == len(gotPaths): - return cmpopts.AnyError - case tt.breakAt > 0 && tt.breakAt == len(gotPaths): - return Break - case tt.terminateAt > 0 && tt.terminateAt == len(gotPaths): - return Terminate - default: - return nil - } - }, - func(p protopath.Values) error { - gotPath := p.Path[1:].String() - wantPath := stackPaths[len(stackPaths)-1] - if wantPath != gotPath { - t.Errorf("%d: pop path mismatch: got %v, want %v", len(gotPaths), gotPath, wantPath) - } - gotValue := p.Index(-1).Value - wantValue := stackValues[len(stackValues)-1] - if diff := cmp.Diff(wantValue, gotValue, transformReflectValue, protocmp.Transform()); diff != "" { - t.Errorf("%d: pop value mismatch (-want +got):\n%v", len(gotValues), diff) - } - stackPaths = stackPaths[:len(stackPaths)-1] - stackValues = stackValues[:len(stackValues)-1] - return nil - }, - ) - if n := len(stackPaths) + len(stackValues); n > 0 { - t.Errorf("stack mismatch: got %d unpopped items", n) - } - if diff := cmp.Diff(tt.wantPaths, gotPaths); diff != "" { - t.Errorf("paths mismatch (-want +got):\n%s", diff) - } - if diff := cmp.Diff(tt.wantValues, gotValues, transformReflectValue, protocmp.Transform()); diff != "" { - t.Errorf("values mismatch (-want +got):\n%s", diff) - } - if !cmp.Equal(gotError, tt.wantError, cmpopts.EquateErrors()) { - t.Errorf("error mismatch: got %v, want %v", gotError, tt.wantError) - } - }) - } -} diff --git a/vendor/google.golang.org/protobuf/reflect/protorange/ya.make b/vendor/google.golang.org/protobuf/reflect/protorange/ya.make index 29c6345337..fc294f2b0e 100644 --- a/vendor/google.golang.org/protobuf/reflect/protorange/ya.make +++ b/vendor/google.golang.org/protobuf/reflect/protorange/ya.make @@ -2,12 +2,8 @@ GO_LIBRARY() LICENSE(BSD-3-Clause) -SRCS(range.go) - -GO_TEST_SRCS(range_test.go) - -GO_XTEST_SRCS(example_test.go) +SRCS( + range.go +) END() - -RECURSE(gotest) diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/gotest/ya.make b/vendor/google.golang.org/protobuf/reflect/protoreflect/gotest/ya.make deleted file mode 100644 index 5638b14678..0000000000 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/gotest/ya.make +++ /dev/null @@ -1,5 +0,0 @@ -GO_TEST_FOR(vendor/google.golang.org/protobuf/reflect/protoreflect) - -LICENSE(BSD-3-Clause) - -END() diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/proto.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/proto.go index 55aa14922b..ec6572dfda 100644 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/proto.go +++ b/vendor/google.golang.org/protobuf/reflect/protoreflect/proto.go @@ -10,46 +10,46 @@ // // # Protocol Buffer Descriptors // -// Protobuf descriptors (e.g., EnumDescriptor or MessageDescriptor) +// Protobuf descriptors (e.g., [EnumDescriptor] or [MessageDescriptor]) // are immutable objects that represent protobuf type information. // They are wrappers around the messages declared in descriptor.proto. // Protobuf descriptors alone lack any information regarding Go types. // -// Enums and messages generated by this module implement Enum and ProtoMessage, +// Enums and messages generated by this module implement [Enum] and [ProtoMessage], // where the Descriptor and ProtoReflect.Descriptor accessors respectively // return the protobuf descriptor for the values. // // The protobuf descriptor interfaces are not meant to be implemented by // user code since they might need to be extended in the future to support // additions to the protobuf language. -// The "google.golang.org/protobuf/reflect/protodesc" package converts between +// The [google.golang.org/protobuf/reflect/protodesc] package converts between // google.protobuf.DescriptorProto messages and protobuf descriptors. // // # Go Type Descriptors // -// A type descriptor (e.g., EnumType or MessageType) is a constructor for +// A type descriptor (e.g., [EnumType] or [MessageType]) is a constructor for // a concrete Go type that represents the associated protobuf descriptor. // There is commonly a one-to-one relationship between protobuf descriptors and // Go type descriptors, but it can potentially be a one-to-many relationship. // -// Enums and messages generated by this module implement Enum and ProtoMessage, +// Enums and messages generated by this module implement [Enum] and [ProtoMessage], // where the Type and ProtoReflect.Type accessors respectively // return the protobuf descriptor for the values. // -// The "google.golang.org/protobuf/types/dynamicpb" package can be used to +// The [google.golang.org/protobuf/types/dynamicpb] package can be used to // create Go type descriptors from protobuf descriptors. // // # Value Interfaces // -// The Enum and Message interfaces provide a reflective view over an +// The [Enum] and [Message] interfaces provide a reflective view over an // enum or message instance. For enums, it provides the ability to retrieve // the enum value number for any concrete enum type. For messages, it provides // the ability to access or manipulate fields of the message. // -// To convert a proto.Message to a protoreflect.Message, use the +// To convert a [google.golang.org/protobuf/proto.Message] to a [protoreflect.Message], use the // former's ProtoReflect method. Since the ProtoReflect method is new to the // v2 message interface, it may not be present on older message implementations. -// The "github.com/golang/protobuf/proto".MessageReflect function can be used +// The [github.com/golang/protobuf/proto.MessageReflect] function can be used // to obtain a reflective view on older messages. // // # Relationships @@ -71,12 +71,12 @@ // โ โ // โโโโโโโโโโโโโโโโโโโ Type() โโโโโโโโ // -// โข An EnumType describes a concrete Go enum type. +// โข An [EnumType] describes a concrete Go enum type. // It has an EnumDescriptor and can construct an Enum instance. // -// โข An EnumDescriptor describes an abstract protobuf enum type. +// โข An [EnumDescriptor] describes an abstract protobuf enum type. // -// โข An Enum is a concrete enum instance. Generated enums implement Enum. +// โข An [Enum] is a concrete enum instance. Generated enums implement Enum. // // โโโโโโโโโโโโโโโโโ New() โโโโโโโโโโโโโโโโโโ // โ โ @@ -90,24 +90,26 @@ // โ โ // โโโโโโโโโโโโโโโโโโโโ Type() โโโโโโโโโโ // -// โข A MessageType describes a concrete Go message type. -// It has a MessageDescriptor and can construct a Message instance. -// Just as how Go's reflect.Type is a reflective description of a Go type, -// a MessageType is a reflective description of a Go type for a protobuf message. +// โข A [MessageType] describes a concrete Go message type. +// It has a [MessageDescriptor] and can construct a [Message] instance. +// Just as how Go's [reflect.Type] is a reflective description of a Go type, +// a [MessageType] is a reflective description of a Go type for a protobuf message. // -// โข A MessageDescriptor describes an abstract protobuf message type. -// It has no understanding of Go types. In order to construct a MessageType -// from just a MessageDescriptor, you can consider looking up the message type -// in the global registry using protoregistry.GlobalTypes.FindMessageByName -// or constructing a dynamic MessageType using dynamicpb.NewMessageType. +// โข A [MessageDescriptor] describes an abstract protobuf message type. +// It has no understanding of Go types. In order to construct a [MessageType] +// from just a [MessageDescriptor], you can consider looking up the message type +// in the global registry using the FindMessageByName method on +// [google.golang.org/protobuf/reflect/protoregistry.GlobalTypes] +// or constructing a dynamic [MessageType] using +// [google.golang.org/protobuf/types/dynamicpb.NewMessageType]. // -// โข A Message is a reflective view over a concrete message instance. -// Generated messages implement ProtoMessage, which can convert to a Message. -// Just as how Go's reflect.Value is a reflective view over a Go value, -// a Message is a reflective view over a concrete protobuf message instance. -// Using Go reflection as an analogy, the ProtoReflect method is similar to -// calling reflect.ValueOf, and the Message.Interface method is similar to -// calling reflect.Value.Interface. +// โข A [Message] is a reflective view over a concrete message instance. +// Generated messages implement [ProtoMessage], which can convert to a [Message]. +// Just as how Go's [reflect.Value] is a reflective view over a Go value, +// a [Message] is a reflective view over a concrete protobuf message instance. +// Using Go reflection as an analogy, the [ProtoMessage.ProtoReflect] method is similar to +// calling [reflect.ValueOf], and the [Message.Interface] method is similar to +// calling [reflect.Value.Interface]. // // โโโ TypeDescriptor() โโโ โโโโโโ Descriptor() โโโโโโ // โ V โ V @@ -119,15 +121,15 @@ // โ โ // โโโโโโโ implements โโโโโโโโโ // -// โข An ExtensionType describes a concrete Go implementation of an extension. -// It has an ExtensionTypeDescriptor and can convert to/from -// abstract Values and Go values. +// โข An [ExtensionType] describes a concrete Go implementation of an extension. +// It has an [ExtensionTypeDescriptor] and can convert to/from +// an abstract [Value] and a Go value. // -// โข An ExtensionTypeDescriptor is an ExtensionDescriptor -// which also has an ExtensionType. +// โข An [ExtensionTypeDescriptor] is an [ExtensionDescriptor] +// which also has an [ExtensionType]. // -// โข An ExtensionDescriptor describes an abstract protobuf extension field and -// may not always be an ExtensionTypeDescriptor. +// โข An [ExtensionDescriptor] describes an abstract protobuf extension field and +// may not always be an [ExtensionTypeDescriptor]. package protoreflect import ( @@ -142,7 +144,7 @@ type doNotImplement pragma.DoNotImplement // ProtoMessage is the top-level interface that all proto messages implement. // This is declared in the protoreflect package to avoid a cyclic dependency; -// use the proto.Message type instead, which aliases this type. +// use the [google.golang.org/protobuf/proto.Message] type instead, which aliases this type. type ProtoMessage interface{ ProtoReflect() Message } // Syntax is the language version of the proto file. @@ -151,8 +153,9 @@ type Syntax syntax type syntax int8 // keep exact type opaque as the int type may change const ( - Proto2 Syntax = 2 - Proto3 Syntax = 3 + Proto2 Syntax = 2 + Proto3 Syntax = 3 + Editions Syntax = 4 ) // IsValid reports whether the syntax is valid. @@ -436,7 +439,7 @@ type Names interface { // FullName is a qualified name that uniquely identifies a proto declaration. // A qualified name is the concatenation of the proto package along with the // fully-declared name (i.e., name of parent preceding the name of the child), -// with a '.' delimiter placed between each Name. +// with a '.' delimiter placed between each [Name]. // // This should not have any leading or trailing dots. type FullName string // e.g., "google.protobuf.Field.Kind" @@ -480,7 +483,7 @@ func isLetterDigit(c byte) bool { } // Name returns the short name, which is the last identifier segment. -// A single segment FullName is the Name itself. +// A single segment FullName is the [Name] itself. func (n FullName) Name() Name { if i := strings.LastIndexByte(string(n), '.'); i >= 0 { return Name(n[i+1:]) diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/proto_test.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/proto_test.go deleted file mode 100644 index 97e55ccbbb..0000000000 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/proto_test.go +++ /dev/null @@ -1,82 +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 protoreflect - -import "testing" - -func TestNameIsValid(t *testing.T) { - tests := []struct { - in Name - want bool - }{ - {"", false}, - {"a", true}, - {".", false}, - {"_", true}, // odd, but permitted by protoc - {".foo", false}, - {"foo.", false}, - {"foo", true}, - {"one1_two2_three3", true}, - {"1one", false}, - } - - for _, tt := range tests { - if got := tt.in.IsValid(); got != tt.want { - t.Errorf("Name(%q).IsValid() = %v, want %v", tt.in, got, tt.want) - } - } -} - -func TestFullNameIsValid(t *testing.T) { - tests := []struct { - in FullName - want bool - }{ - {"", false}, - {"a", true}, - {"a.b", true}, - {"a.b.c", true}, - {".", false}, - {"_._._", true}, // odd, but permitted by protoc - {".foo", false}, - {"foo.", false}, - {"foo", true}, - {"one1_two2_three3", true}, - {"one1.two2.three3", true}, - {".one1.two2.three3", false}, - {"one1.two2.three3.", false}, - {"foo.1one", false}, - } - - for _, tt := range tests { - if got := tt.in.IsValid(); got != tt.want { - t.Errorf("Name(%q).IsValid() = %v, want %v", tt.in, got, tt.want) - } - } -} - -func TestNameAppend(t *testing.T) { - tests := []FullName{ - "", - "a", - "a.b", - "a.b.c", - "one1.two2.three3", - } - - for _, tt := range tests { - if got := tt.Parent().Append(tt.Name()); got != tt { - t.Errorf("FullName.Parent().Append(FullName.Name()) = %q, want %q", got, tt) - } - } -} - -var sink bool - -func BenchmarkFullNameIsValid(b *testing.B) { - for i := 0; i < b.N; i++ { - sink = FullName("google.protobuf.Any").IsValid() - } -} diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go index 717b106f3d..0c045db6ab 100644 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go +++ b/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go @@ -35,7 +35,7 @@ func (p *SourcePath) appendFileDescriptorProto(b []byte) []byte { b = p.appendSingularField(b, "source_code_info", (*SourcePath).appendSourceCodeInfo) case 12: b = p.appendSingularField(b, "syntax", nil) - case 13: + case 14: b = p.appendSingularField(b, "edition", nil) } return b @@ -180,6 +180,8 @@ func (p *SourcePath) appendFileOptions(b []byte) []byte { b = p.appendSingularField(b, "php_metadata_namespace", nil) case 45: b = p.appendSingularField(b, "ruby_package", nil) + case 50: + b = p.appendSingularField(b, "features", (*SourcePath).appendFeatureSet) case 999: b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption) } @@ -240,6 +242,8 @@ func (p *SourcePath) appendMessageOptions(b []byte) []byte { b = p.appendSingularField(b, "map_entry", nil) case 11: b = p.appendSingularField(b, "deprecated_legacy_json_field_conflicts", nil) + case 12: + b = p.appendSingularField(b, "features", (*SourcePath).appendFeatureSet) case 999: b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption) } @@ -285,6 +289,8 @@ func (p *SourcePath) appendEnumOptions(b []byte) []byte { b = p.appendSingularField(b, "deprecated", nil) case 6: b = p.appendSingularField(b, "deprecated_legacy_json_field_conflicts", nil) + case 7: + b = p.appendSingularField(b, "features", (*SourcePath).appendFeatureSet) case 999: b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption) } @@ -330,6 +336,8 @@ func (p *SourcePath) appendServiceOptions(b []byte) []byte { return b } switch (*p)[0] { + case 34: + b = p.appendSingularField(b, "features", (*SourcePath).appendFeatureSet) case 33: b = p.appendSingularField(b, "deprecated", nil) case 999: @@ -361,16 +369,39 @@ func (p *SourcePath) appendFieldOptions(b []byte) []byte { b = p.appendSingularField(b, "debug_redact", nil) case 17: b = p.appendSingularField(b, "retention", nil) - case 18: - b = p.appendSingularField(b, "target", nil) case 19: b = p.appendRepeatedField(b, "targets", nil) + case 20: + b = p.appendRepeatedField(b, "edition_defaults", (*SourcePath).appendFieldOptions_EditionDefault) + case 21: + b = p.appendSingularField(b, "features", (*SourcePath).appendFeatureSet) case 999: b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption) } return b } +func (p *SourcePath) appendFeatureSet(b []byte) []byte { + if len(*p) == 0 { + return b + } + switch (*p)[0] { + case 1: + b = p.appendSingularField(b, "field_presence", nil) + case 2: + b = p.appendSingularField(b, "enum_type", nil) + case 3: + b = p.appendSingularField(b, "repeated_field_encoding", nil) + case 4: + b = p.appendSingularField(b, "utf8_validation", nil) + case 5: + b = p.appendSingularField(b, "message_encoding", nil) + case 6: + b = p.appendSingularField(b, "json_format", nil) + } + return b +} + func (p *SourcePath) appendUninterpretedOption(b []byte) []byte { if len(*p) == 0 { return b @@ -422,6 +453,8 @@ func (p *SourcePath) appendExtensionRangeOptions(b []byte) []byte { b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption) case 2: b = p.appendRepeatedField(b, "declaration", (*SourcePath).appendExtensionRangeOptions_Declaration) + case 50: + b = p.appendSingularField(b, "features", (*SourcePath).appendFeatureSet) case 3: b = p.appendSingularField(b, "verification", nil) } @@ -433,6 +466,8 @@ func (p *SourcePath) appendOneofOptions(b []byte) []byte { return b } switch (*p)[0] { + case 1: + b = p.appendSingularField(b, "features", (*SourcePath).appendFeatureSet) case 999: b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption) } @@ -446,6 +481,10 @@ func (p *SourcePath) appendEnumValueOptions(b []byte) []byte { switch (*p)[0] { case 1: b = p.appendSingularField(b, "deprecated", nil) + case 2: + b = p.appendSingularField(b, "features", (*SourcePath).appendFeatureSet) + case 3: + b = p.appendSingularField(b, "debug_redact", nil) case 999: b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption) } @@ -461,12 +500,27 @@ func (p *SourcePath) appendMethodOptions(b []byte) []byte { b = p.appendSingularField(b, "deprecated", nil) case 34: b = p.appendSingularField(b, "idempotency_level", nil) + case 35: + b = p.appendSingularField(b, "features", (*SourcePath).appendFeatureSet) case 999: b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption) } return b } +func (p *SourcePath) appendFieldOptions_EditionDefault(b []byte) []byte { + if len(*p) == 0 { + return b + } + switch (*p)[0] { + case 3: + b = p.appendSingularField(b, "edition", nil) + case 2: + b = p.appendSingularField(b, "value", nil) + } + return b +} + func (p *SourcePath) appendUninterpretedOption_NamePart(b []byte) []byte { if len(*p) == 0 { return b @@ -491,8 +545,6 @@ func (p *SourcePath) appendExtensionRangeOptions_Declaration(b []byte) []byte { b = p.appendSingularField(b, "full_name", nil) case 3: b = p.appendSingularField(b, "type", nil) - case 4: - b = p.appendSingularField(b, "is_repeated", nil) case 5: b = p.appendSingularField(b, "reserved", nil) case 6: diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/source_test.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/source_test.go deleted file mode 100644 index 877ede5955..0000000000 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/source_test.go +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2020 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 protoreflect - -import "testing" - -func TestSourcePathString(t *testing.T) { - tests := []struct { - in SourcePath - want string - }{ - {nil, ""}, - {SourcePath{}, ""}, - {SourcePath{0}, ".0"}, - {SourcePath{1}, ".name"}, - {SourcePath{1, 1}, ".name.1"}, - {SourcePath{1, 1, -2, 3}, ".name.1.-2.3"}, - {SourcePath{3}, ".dependency"}, - {SourcePath{3, 0}, ".dependency[0]"}, - {SourcePath{3, -1}, ".dependency.-1"}, - {SourcePath{3, 1, 2}, ".dependency[1].2"}, - {SourcePath{4}, ".message_type"}, - {SourcePath{4, 0}, ".message_type[0]"}, - {SourcePath{4, -1}, ".message_type.-1"}, - {SourcePath{4, 1, 0}, ".message_type[1].0"}, - {SourcePath{4, 1, 1}, ".message_type[1].name"}, - } - for _, tt := range tests { - if got := tt.in.String(); got != tt.want { - t.Errorf("SourcePath(%d).String() = %v, want %v", tt.in, got, tt.want) - } - } -} diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/type.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/type.go index 3867470d30..60ff62b4c8 100644 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/type.go +++ b/vendor/google.golang.org/protobuf/reflect/protoreflect/type.go @@ -12,7 +12,7 @@ package protoreflect // exactly identical. However, it is possible for the same semantically // identical proto type to be represented by multiple type descriptors. // -// For example, suppose we have t1 and t2 which are both MessageDescriptors. +// For example, suppose we have t1 and t2 which are both an [MessageDescriptor]. // If t1 == t2, then the types are definitely equal and all accessors return // the same information. However, if t1 != t2, then it is still possible that // they still represent the same proto type (e.g., t1.FullName == t2.FullName). @@ -115,7 +115,7 @@ type Descriptor interface { // corresponds with the google.protobuf.FileDescriptorProto message. // // Top-level declarations: -// EnumDescriptor, MessageDescriptor, FieldDescriptor, and/or ServiceDescriptor. +// [EnumDescriptor], [MessageDescriptor], [FieldDescriptor], and/or [ServiceDescriptor]. type FileDescriptor interface { Descriptor // Descriptor.FullName is identical to Package @@ -180,8 +180,8 @@ type FileImport struct { // corresponds with the google.protobuf.DescriptorProto message. // // Nested declarations: -// FieldDescriptor, OneofDescriptor, FieldDescriptor, EnumDescriptor, -// and/or MessageDescriptor. +// [FieldDescriptor], [OneofDescriptor], [FieldDescriptor], [EnumDescriptor], +// and/or [MessageDescriptor]. type MessageDescriptor interface { Descriptor @@ -214,7 +214,7 @@ type MessageDescriptor interface { ExtensionRanges() FieldRanges // ExtensionRangeOptions returns the ith extension range options. // - // To avoid a dependency cycle, this method returns a proto.Message value, + // To avoid a dependency cycle, this method returns a proto.Message] value, // which always contains a google.protobuf.ExtensionRangeOptions message. // This method returns a typed nil-pointer if no options are present. // The caller must import the descriptorpb package to use this. @@ -231,9 +231,9 @@ type MessageDescriptor interface { } type isMessageDescriptor interface{ ProtoType(MessageDescriptor) } -// MessageType encapsulates a MessageDescriptor with a concrete Go implementation. +// MessageType encapsulates a [MessageDescriptor] with a concrete Go implementation. // It is recommended that implementations of this interface also implement the -// MessageFieldTypes interface. +// [MessageFieldTypes] interface. type MessageType interface { // New returns a newly allocated empty message. // It may return nil for synthetic messages representing a map entry. @@ -249,19 +249,19 @@ type MessageType interface { Descriptor() MessageDescriptor } -// MessageFieldTypes extends a MessageType by providing type information +// MessageFieldTypes extends a [MessageType] by providing type information // regarding enums and messages referenced by the message fields. type MessageFieldTypes interface { MessageType - // Enum returns the EnumType for the ith field in Descriptor.Fields. + // Enum returns the EnumType for the ith field in MessageDescriptor.Fields. // It returns nil if the ith field is not an enum kind. // It panics if out of bounds. // // Invariant: mt.Enum(i).Descriptor() == mt.Descriptor().Fields(i).Enum() Enum(i int) EnumType - // Message returns the MessageType for the ith field in Descriptor.Fields. + // Message returns the MessageType for the ith field in MessageDescriptor.Fields. // It returns nil if the ith field is not a message or group kind. // It panics if out of bounds. // @@ -286,8 +286,8 @@ type MessageDescriptors interface { // corresponds with the google.protobuf.FieldDescriptorProto message. // // It is used for both normal fields defined within the parent message -// (e.g., MessageDescriptor.Fields) and fields that extend some remote message -// (e.g., FileDescriptor.Extensions or MessageDescriptor.Extensions). +// (e.g., [MessageDescriptor.Fields]) and fields that extend some remote message +// (e.g., [FileDescriptor.Extensions] or [MessageDescriptor.Extensions]). type FieldDescriptor interface { Descriptor @@ -344,7 +344,7 @@ type FieldDescriptor interface { // IsMap reports whether this field represents a map, // where the value type for the associated field is a Map. // It is equivalent to checking whether Cardinality is Repeated, - // that the Kind is MessageKind, and that Message.IsMapEntry reports true. + // that the Kind is MessageKind, and that MessageDescriptor.IsMapEntry reports true. IsMap() bool // MapKey returns the field descriptor for the key in the map entry. @@ -419,7 +419,7 @@ type OneofDescriptor interface { // IsSynthetic reports whether this is a synthetic oneof created to support // proto3 optional semantics. If true, Fields contains exactly one field - // with HasOptionalKeyword specified. + // with FieldDescriptor.HasOptionalKeyword specified. IsSynthetic() bool // Fields is a list of fields belonging to this oneof. @@ -442,10 +442,10 @@ type OneofDescriptors interface { doNotImplement } -// ExtensionDescriptor is an alias of FieldDescriptor for documentation. +// ExtensionDescriptor is an alias of [FieldDescriptor] for documentation. type ExtensionDescriptor = FieldDescriptor -// ExtensionTypeDescriptor is an ExtensionDescriptor with an associated ExtensionType. +// ExtensionTypeDescriptor is an [ExtensionDescriptor] with an associated [ExtensionType]. type ExtensionTypeDescriptor interface { ExtensionDescriptor @@ -470,12 +470,12 @@ type ExtensionDescriptors interface { doNotImplement } -// ExtensionType encapsulates an ExtensionDescriptor with a concrete +// ExtensionType encapsulates an [ExtensionDescriptor] with a concrete // Go implementation. The nested field descriptor must be for a extension field. // // While a normal field is a member of the parent message that it is declared -// within (see Descriptor.Parent), an extension field is a member of some other -// target message (see ExtensionDescriptor.Extendee) and may have no +// within (see [Descriptor.Parent]), an extension field is a member of some other +// target message (see [FieldDescriptor.ContainingMessage]) and may have no // relationship with the parent. However, the full name of an extension field is // relative to the parent that it is declared within. // @@ -532,7 +532,7 @@ type ExtensionType interface { // corresponds with the google.protobuf.EnumDescriptorProto message. // // Nested declarations: -// EnumValueDescriptor. +// [EnumValueDescriptor]. type EnumDescriptor interface { Descriptor @@ -548,7 +548,7 @@ type EnumDescriptor interface { } type isEnumDescriptor interface{ ProtoType(EnumDescriptor) } -// EnumType encapsulates an EnumDescriptor with a concrete Go implementation. +// EnumType encapsulates an [EnumDescriptor] with a concrete Go implementation. type EnumType interface { // New returns an instance of this enum type with its value set to n. New(n EnumNumber) Enum @@ -610,7 +610,7 @@ type EnumValueDescriptors interface { // ServiceDescriptor describes a service and // corresponds with the google.protobuf.ServiceDescriptorProto message. // -// Nested declarations: MethodDescriptor. +// Nested declarations: [MethodDescriptor]. type ServiceDescriptor interface { Descriptor diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/value.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/value.go index 37601b7819..a7b0d06ff3 100644 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/value.go +++ b/vendor/google.golang.org/protobuf/reflect/protoreflect/value.go @@ -27,16 +27,16 @@ type Enum interface { // Message is a reflective interface for a concrete message value, // encapsulating both type and value information for the message. // -// Accessor/mutators for individual fields are keyed by FieldDescriptor. +// Accessor/mutators for individual fields are keyed by [FieldDescriptor]. // For non-extension fields, the descriptor must exactly match the // field known by the parent message. -// For extension fields, the descriptor must implement ExtensionTypeDescriptor, -// extend the parent message (i.e., have the same message FullName), and +// For extension fields, the descriptor must implement [ExtensionTypeDescriptor], +// extend the parent message (i.e., have the same message [FullName]), and // be within the parent's extension range. // -// Each field Value can be a scalar or a composite type (Message, List, or Map). -// See Value for the Go types associated with a FieldDescriptor. -// Providing a Value that is invalid or of an incorrect type panics. +// Each field [Value] can be a scalar or a composite type ([Message], [List], or [Map]). +// See [Value] for the Go types associated with a [FieldDescriptor]. +// Providing a [Value] that is invalid or of an incorrect type panics. type Message interface { // Descriptor returns message descriptor, which contains only the protobuf // type information for the message. @@ -152,7 +152,7 @@ type Message interface { // This method may return nil. // // The returned methods type is identical to - // "google.golang.org/protobuf/runtime/protoiface".Methods. + // google.golang.org/protobuf/runtime/protoiface.Methods. // Consult the protoiface package documentation for details. ProtoMethods() *methods } @@ -175,8 +175,8 @@ func (b RawFields) IsValid() bool { } // List is a zero-indexed, ordered list. -// The element Value type is determined by FieldDescriptor.Kind. -// Providing a Value that is invalid or of an incorrect type panics. +// The element [Value] type is determined by [FieldDescriptor.Kind]. +// Providing a [Value] that is invalid or of an incorrect type panics. type List interface { // Len reports the number of entries in the List. // Get, Set, and Truncate panic with out of bound indexes. @@ -226,9 +226,9 @@ type List interface { } // Map is an unordered, associative map. -// The entry MapKey type is determined by FieldDescriptor.MapKey.Kind. -// The entry Value type is determined by FieldDescriptor.MapValue.Kind. -// Providing a MapKey or Value that is invalid or of an incorrect type panics. +// The entry [MapKey] type is determined by [FieldDescriptor.MapKey].Kind. +// The entry [Value] type is determined by [FieldDescriptor.MapValue].Kind. +// Providing a [MapKey] or [Value] that is invalid or of an incorrect type panics. type Map interface { // Len reports the number of elements in the map. Len() int diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/value_equal.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/value_equal.go index 591652541f..654599d449 100644 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/value_equal.go +++ b/vendor/google.golang.org/protobuf/reflect/protoreflect/value_equal.go @@ -24,19 +24,19 @@ import ( // Unlike the == operator, a NaN is equal to another NaN. // // - Enums are equal if they contain the same number. -// Since Value does not contain an enum descriptor, +// Since [Value] does not contain an enum descriptor, // enum values do not consider the type of the enum. // // - Other scalar values are equal if they contain the same value. // -// - Message values are equal if they belong to the same message descriptor, +// - [Message] values are equal if they belong to the same message descriptor, // have the same set of populated known and extension field values, // and the same set of unknown fields values. // -// - Lists are equal if they are the same length and +// - [List] values are equal if they are the same length and // each corresponding element is equal. // -// - Maps are equal if they have the same set of keys and +// - [Map] values are equal if they have the same set of keys and // the corresponding value for each key is equal. func (v1 Value) Equal(v2 Value) bool { return equalValue(v1, v2) diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/value_test.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/value_test.go deleted file mode 100644 index d3879001db..0000000000 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/value_test.go +++ /dev/null @@ -1,191 +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 protoreflect - -import ( - "bytes" - "math" - "reflect" - "testing" -) - -var ( - fakeMessage = new(struct{ Message }) - fakeList = new(struct{ List }) - fakeMap = new(struct{ Map }) -) - -func TestValue(t *testing.T) { - - tests := []struct { - in Value - want interface{} - }{ - {in: Value{}}, - {in: ValueOf(nil)}, - {in: ValueOf(true), want: true}, - {in: ValueOf(int32(math.MaxInt32)), want: int32(math.MaxInt32)}, - {in: ValueOf(int64(math.MaxInt64)), want: int64(math.MaxInt64)}, - {in: ValueOf(uint32(math.MaxUint32)), want: uint32(math.MaxUint32)}, - {in: ValueOf(uint64(math.MaxUint64)), want: uint64(math.MaxUint64)}, - {in: ValueOf(float32(math.MaxFloat32)), want: float32(math.MaxFloat32)}, - {in: ValueOf(float64(math.MaxFloat64)), want: float64(math.MaxFloat64)}, - {in: ValueOf(string("hello")), want: string("hello")}, - {in: ValueOf([]byte("hello")), want: []byte("hello")}, - {in: ValueOf(fakeMessage), want: fakeMessage}, - {in: ValueOf(fakeList), want: fakeList}, - {in: ValueOf(fakeMap), want: fakeMap}, - } - - for _, tt := range tests { - got := tt.in.Interface() - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("Value(%v).Interface() = %v, want %v", tt.in, got, tt.want) - } - - if got := tt.in.IsValid(); got != (tt.want != nil) { - t.Errorf("Value(%v).IsValid() = %v, want %v", tt.in, got, tt.want != nil) - } - switch want := tt.want.(type) { - case int32: - if got := tt.in.Int(); got != int64(want) { - t.Errorf("Value(%v).Int() = %v, want %v", tt.in, got, tt.want) - } - case int64: - if got := tt.in.Int(); got != int64(want) { - t.Errorf("Value(%v).Int() = %v, want %v", tt.in, got, tt.want) - } - case uint32: - if got := tt.in.Uint(); got != uint64(want) { - t.Errorf("Value(%v).Uint() = %v, want %v", tt.in, got, tt.want) - } - case uint64: - if got := tt.in.Uint(); got != uint64(want) { - t.Errorf("Value(%v).Uint() = %v, want %v", tt.in, got, tt.want) - } - case float32: - if got := tt.in.Float(); got != float64(want) { - t.Errorf("Value(%v).Float() = %v, want %v", tt.in, got, tt.want) - } - case float64: - if got := tt.in.Float(); got != float64(want) { - t.Errorf("Value(%v).Float() = %v, want %v", tt.in, got, tt.want) - } - case string: - if got := tt.in.String(); got != string(want) { - t.Errorf("Value(%v).String() = %v, want %v", tt.in, got, tt.want) - } - case []byte: - if got := tt.in.Bytes(); !bytes.Equal(got, want) { - t.Errorf("Value(%v).Bytes() = %v, want %v", tt.in, got, tt.want) - } - case EnumNumber: - if got := tt.in.Enum(); got != want { - t.Errorf("Value(%v).Enum() = %v, want %v", tt.in, got, tt.want) - } - case Message: - if got := tt.in.Message(); got != want { - t.Errorf("Value(%v).Message() = %v, want %v", tt.in, got, tt.want) - } - case List: - if got := tt.in.List(); got != want { - t.Errorf("Value(%v).List() = %v, want %v", tt.in, got, tt.want) - } - case Map: - if got := tt.in.Map(); got != want { - t.Errorf("Value(%v).Map() = %v, want %v", tt.in, got, tt.want) - } - } - } -} - -func TestValueEqual(t *testing.T) { - tests := []struct { - x, y Value - want bool - }{ - {Value{}, Value{}, true}, - {Value{}, ValueOfBool(true), false}, - {ValueOfBool(true), ValueOfBool(true), true}, - {ValueOfBool(true), ValueOfBool(false), false}, - {ValueOfBool(false), ValueOfInt32(0), false}, - {ValueOfInt32(0), ValueOfInt32(0), true}, - {ValueOfInt32(0), ValueOfInt32(1), false}, - {ValueOfInt32(0), ValueOfInt64(0), false}, - {ValueOfInt64(123), ValueOfInt64(123), true}, - {ValueOfFloat64(0), ValueOfFloat64(0), true}, - {ValueOfFloat64(math.NaN()), ValueOfFloat64(math.NaN()), true}, - {ValueOfFloat64(math.NaN()), ValueOfFloat64(0), false}, - {ValueOfFloat64(math.Inf(1)), ValueOfFloat64(math.Inf(1)), true}, - {ValueOfFloat64(math.Inf(-1)), ValueOfFloat64(math.Inf(1)), false}, - {ValueOfBytes(nil), ValueOfBytes(nil), true}, - {ValueOfBytes(nil), ValueOfBytes([]byte{}), true}, - {ValueOfBytes(nil), ValueOfBytes([]byte{1}), false}, - {ValueOfEnum(0), ValueOfEnum(0), true}, - {ValueOfEnum(0), ValueOfEnum(1), false}, - {ValueOfBool(false), ValueOfMessage(fakeMessage), false}, - {ValueOfMessage(fakeMessage), ValueOfList(fakeList), false}, - {ValueOfList(fakeList), ValueOfMap(fakeMap), false}, - {ValueOfMap(fakeMap), ValueOfMessage(fakeMessage), false}, - - // Composite types are not tested here. - // See proto.TestEqual. - } - - for _, tt := range tests { - got := tt.x.Equal(tt.y) - if got != tt.want { - t.Errorf("(%v).Equal(%v) = %v, want %v", tt.x, tt.y, got, tt.want) - } - } -} - -func BenchmarkValue(b *testing.B) { - const testdata = "The quick brown fox jumped over the lazy dog." - var sink1 string - var sink2 Value - var sink3 interface{} - - // Baseline measures the time to store a string into a native variable. - b.Run("Baseline", func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - sink1 = testdata[:len(testdata)%(i+1)] - } - }) - - // Inline measures the time to store a string into a Value, - // assuming that the compiler could inline the ValueOf function call. - b.Run("Inline", func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - sink2 = valueOfString(testdata[:len(testdata)%(i+1)]) - } - }) - - // Value measures the time to store a string into a Value using the general - // ValueOf function call. This should be identical to Inline. - // - // NOTE: As of Go1.11, this is not as efficient as Inline due to the lack - // of some compiler optimizations: - // https://golang.org/issue/22310 - // https://golang.org/issue/25189 - b.Run("Value", func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - sink2 = ValueOf(string(testdata[:len(testdata)%(i+1)])) - } - }) - - // Interface measures the time to store a string into an interface. - b.Run("Interface", func(b *testing.B) { - b.ReportAllocs() - for i := 0; i < b.N; i++ { - sink3 = string(testdata[:len(testdata)%(i+1)]) - } - }) - - _, _, _ = sink1, sink2, sink3 -} diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go index 08e5ef73fc..1603097311 100644 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go +++ b/vendor/google.golang.org/protobuf/reflect/protoreflect/value_union.go @@ -11,7 +11,7 @@ import ( // Value is a union where only one Go type may be set at a time. // The Value is used to represent all possible values a field may take. -// The following shows which Go type is used to represent each proto Kind: +// The following shows which Go type is used to represent each proto [Kind]: // // โโโโโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ // โ Go type โ Protobuf kind โ @@ -31,22 +31,22 @@ import ( // // Multiple protobuf Kinds may be represented by a single Go type if the type // can losslessly represent the information for the proto kind. For example, -// Int64Kind, Sint64Kind, and Sfixed64Kind are all represented by int64, +// [Int64Kind], [Sint64Kind], and [Sfixed64Kind] are all represented by int64, // but use different integer encoding methods. // -// The List or Map types are used if the field cardinality is repeated. -// A field is a List if FieldDescriptor.IsList reports true. -// A field is a Map if FieldDescriptor.IsMap reports true. +// The [List] or [Map] types are used if the field cardinality is repeated. +// A field is a [List] if [FieldDescriptor.IsList] reports true. +// A field is a [Map] if [FieldDescriptor.IsMap] reports true. // // Converting to/from a Value and a concrete Go value panics on type mismatch. -// For example, ValueOf("hello").Int() panics because this attempts to +// For example, [ValueOf]("hello").Int() panics because this attempts to // retrieve an int64 from a string. // -// List, Map, and Message Values are called "composite" values. +// [List], [Map], and [Message] Values are called "composite" values. // // A composite Value may alias (reference) memory at some location, // such that changes to the Value updates the that location. -// A composite value acquired with a Mutable method, such as Message.Mutable, +// A composite value acquired with a Mutable method, such as [Message.Mutable], // always references the source object. // // For example: @@ -65,7 +65,7 @@ import ( // // appending to the List here may or may not modify the message. // list.Append(protoreflect.ValueOfInt32(0)) // -// Some operations, such as Message.Get, may return an "empty, read-only" +// Some operations, such as [Message.Get], may return an "empty, read-only" // composite Value. Modifying an empty, read-only value panics. type Value value @@ -306,7 +306,7 @@ func (v Value) Float() float64 { } } -// String returns v as a string. Since this method implements fmt.Stringer, +// String returns v as a string. Since this method implements [fmt.Stringer], // this returns the formatted string value for any non-string type. func (v Value) String() string { switch v.typ { @@ -327,7 +327,7 @@ func (v Value) Bytes() []byte { } } -// Enum returns v as a EnumNumber and panics if the type is not a EnumNumber. +// Enum returns v as a [EnumNumber] and panics if the type is not a [EnumNumber]. func (v Value) Enum() EnumNumber { switch v.typ { case enumType: @@ -337,7 +337,7 @@ func (v Value) Enum() EnumNumber { } } -// Message returns v as a Message and panics if the type is not a Message. +// Message returns v as a [Message] and panics if the type is not a [Message]. func (v Value) Message() Message { switch vi := v.getIface().(type) { case Message: @@ -347,7 +347,7 @@ func (v Value) Message() Message { } } -// List returns v as a List and panics if the type is not a List. +// List returns v as a [List] and panics if the type is not a [List]. func (v Value) List() List { switch vi := v.getIface().(type) { case List: @@ -357,7 +357,7 @@ func (v Value) List() List { } } -// Map returns v as a Map and panics if the type is not a Map. +// Map returns v as a [Map] and panics if the type is not a [Map]. func (v Value) Map() Map { switch vi := v.getIface().(type) { case Map: @@ -367,7 +367,7 @@ func (v Value) Map() Map { } } -// MapKey returns v as a MapKey and panics for invalid MapKey types. +// MapKey returns v as a [MapKey] and panics for invalid [MapKey] types. func (v Value) MapKey() MapKey { switch v.typ { case boolType, int32Type, int64Type, uint32Type, uint64Type, stringType: @@ -378,8 +378,8 @@ func (v Value) MapKey() MapKey { } // MapKey is used to index maps, where the Go type of the MapKey must match -// the specified key Kind (see MessageDescriptor.IsMapEntry). -// The following shows what Go type is used to represent each proto Kind: +// the specified key [Kind] (see [MessageDescriptor.IsMapEntry]). +// The following shows what Go type is used to represent each proto [Kind]: // // โโโโโโโโโโโคโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ // โ Go type โ Protobuf kind โ @@ -392,13 +392,13 @@ func (v Value) MapKey() MapKey { // โ string โ StringKind โ // โโโโโโโโโโโงโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ // -// A MapKey is constructed and accessed through a Value: +// A MapKey is constructed and accessed through a [Value]: // // k := ValueOf("hash").MapKey() // convert string to MapKey // s := k.String() // convert MapKey to string // -// The MapKey is a strict subset of valid types used in Value; -// converting a Value to a MapKey with an invalid type panics. +// The MapKey is a strict subset of valid types used in [Value]; +// converting a [Value] to a MapKey with an invalid type panics. type MapKey value // IsValid reports whether k is populated with a value. @@ -426,13 +426,13 @@ func (k MapKey) Uint() uint64 { return Value(k).Uint() } -// String returns k as a string. Since this method implements fmt.Stringer, +// String returns k as a string. Since this method implements [fmt.Stringer], // this returns the formatted string value for any non-string type. func (k MapKey) String() string { return Value(k).String() } -// Value returns k as a Value. +// Value returns k as a [Value]. func (k MapKey) Value() Value { return Value(k) } diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe_go121.go index 702ddf22a2..4354701117 100644 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe.go +++ b/vendor/google.golang.org/protobuf/reflect/protoreflect/value_unsafe_go121.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !purego && !appengine -// +build !purego,!appengine +//go:build !purego && !appengine && go1.21 +// +build !purego,!appengine,go1.21 package protoreflect @@ -14,16 +14,8 @@ import ( ) type ( - stringHeader struct { - Data unsafe.Pointer - Len int - } - sliceHeader struct { - Data unsafe.Pointer - Len int - Cap int - } ifaceHeader struct { + _ [0]interface{} // if interfaces have greater alignment than unsafe.Pointer, this will enforce it. Type unsafe.Pointer Data unsafe.Pointer } @@ -73,25 +65,21 @@ type value struct { } func valueOfString(v string) Value { - p := (*stringHeader)(unsafe.Pointer(&v)) - return Value{typ: stringType, ptr: p.Data, num: uint64(len(v))} + return Value{typ: stringType, ptr: unsafe.Pointer(unsafe.StringData(v)), num: uint64(len(v))} } func valueOfBytes(v []byte) Value { - p := (*sliceHeader)(unsafe.Pointer(&v)) - return Value{typ: bytesType, ptr: p.Data, num: uint64(len(v))} + return Value{typ: bytesType, ptr: unsafe.Pointer(unsafe.SliceData(v)), num: uint64(len(v))} } func valueOfIface(v interface{}) Value { p := (*ifaceHeader)(unsafe.Pointer(&v)) return Value{typ: p.Type, ptr: p.Data} } -func (v Value) getString() (x string) { - *(*stringHeader)(unsafe.Pointer(&x)) = stringHeader{Data: v.ptr, Len: int(v.num)} - return x +func (v Value) getString() string { + return unsafe.String((*byte)(v.ptr), v.num) } -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) getBytes() []byte { + return unsafe.Slice((*byte)(v.ptr), v.num) } func (v Value) getIface() (x interface{}) { *(*ifaceHeader)(unsafe.Pointer(&x)) = ifaceHeader{Type: v.typ, Data: v.ptr} diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/ya.make b/vendor/google.golang.org/protobuf/reflect/protoreflect/ya.make index 2ae7578304..7cef01fc14 100644 --- a/vendor/google.golang.org/protobuf/reflect/protoreflect/ya.make +++ b/vendor/google.golang.org/protobuf/reflect/protoreflect/ya.make @@ -11,15 +11,7 @@ SRCS( value.go value_equal.go value_union.go - value_unsafe.go -) - -GO_TEST_SRCS( - proto_test.go - source_test.go - value_test.go + value_unsafe_go121.go ) END() - -RECURSE(gotest) diff --git a/vendor/google.golang.org/protobuf/reflect/protoregistry/gotest/ya.make b/vendor/google.golang.org/protobuf/reflect/protoregistry/gotest/ya.make deleted file mode 100644 index a9d4a12c2a..0000000000 --- a/vendor/google.golang.org/protobuf/reflect/protoregistry/gotest/ya.make +++ /dev/null @@ -1,5 +0,0 @@ -GO_TEST_FOR(vendor/google.golang.org/protobuf/reflect/protoregistry) - -LICENSE(BSD-3-Clause) - -END() diff --git a/vendor/google.golang.org/protobuf/reflect/protoregistry/registry.go b/vendor/google.golang.org/protobuf/reflect/protoregistry/registry.go index aeb5597744..6267dc52a6 100644 --- a/vendor/google.golang.org/protobuf/reflect/protoregistry/registry.go +++ b/vendor/google.golang.org/protobuf/reflect/protoregistry/registry.go @@ -5,12 +5,12 @@ // Package protoregistry provides data structures to register and lookup // protobuf descriptor types. // -// The Files registry contains file descriptors and provides the ability +// The [Files] registry contains file descriptors and provides the ability // to iterate over the files or lookup a specific descriptor within the files. -// Files only contains protobuf descriptors and has no understanding of Go +// [Files] only contains protobuf descriptors and has no understanding of Go // type information that may be associated with each descriptor. // -// The Types registry contains descriptor types for which there is a known +// The [Types] registry contains descriptor types for which there is a known // Go type associated with that descriptor. It provides the ability to iterate // over the registered types or lookup a type by name. package protoregistry @@ -218,7 +218,7 @@ func (r *Files) checkGenProtoConflict(path string) { // FindDescriptorByName looks up a descriptor by the full name. // -// This returns (nil, NotFound) if not found. +// This returns (nil, [NotFound]) if not found. func (r *Files) FindDescriptorByName(name protoreflect.FullName) (protoreflect.Descriptor, error) { if r == nil { return nil, NotFound @@ -310,7 +310,7 @@ func (s *nameSuffix) Pop() (name protoreflect.Name) { // FindFileByPath looks up a file by the path. // -// This returns (nil, NotFound) if not found. +// This returns (nil, [NotFound]) if not found. // This returns an error if multiple files have the same path. func (r *Files) FindFileByPath(path string) (protoreflect.FileDescriptor, error) { if r == nil { @@ -431,7 +431,7 @@ func rangeTopLevelDescriptors(fd protoreflect.FileDescriptor, f func(protoreflec // A compliant implementation must deterministically return the same type // if no error is encountered. // -// The Types type implements this interface. +// The [Types] type implements this interface. type MessageTypeResolver interface { // FindMessageByName looks up a message by its full name. // E.g., "google.protobuf.Any" @@ -451,7 +451,7 @@ type MessageTypeResolver interface { // A compliant implementation must deterministically return the same type // if no error is encountered. // -// The Types type implements this interface. +// The [Types] type implements this interface. type ExtensionTypeResolver interface { // FindExtensionByName looks up a extension field by the field's full name. // Note that this is the full name of the field as determined by @@ -590,7 +590,7 @@ func (r *Types) register(kind string, desc protoreflect.Descriptor, typ interfac // FindEnumByName looks up an enum by its full name. // E.g., "google.protobuf.Field.Kind". // -// This returns (nil, NotFound) if not found. +// This returns (nil, [NotFound]) if not found. func (r *Types) FindEnumByName(enum protoreflect.FullName) (protoreflect.EnumType, error) { if r == nil { return nil, NotFound @@ -611,7 +611,7 @@ func (r *Types) FindEnumByName(enum protoreflect.FullName) (protoreflect.EnumTyp // FindMessageByName looks up a message by its full name, // e.g. "google.protobuf.Any". // -// This returns (nil, NotFound) if not found. +// This returns (nil, [NotFound]) if not found. func (r *Types) FindMessageByName(message protoreflect.FullName) (protoreflect.MessageType, error) { if r == nil { return nil, NotFound @@ -632,7 +632,7 @@ func (r *Types) FindMessageByName(message protoreflect.FullName) (protoreflect.M // FindMessageByURL looks up a message by a URL identifier. // See documentation on google.protobuf.Any.type_url for the URL format. // -// This returns (nil, NotFound) if not found. +// This returns (nil, [NotFound]) if not found. func (r *Types) FindMessageByURL(url string) (protoreflect.MessageType, error) { // This function is similar to FindMessageByName but // truncates anything before and including '/' in the URL. @@ -662,7 +662,7 @@ func (r *Types) FindMessageByURL(url string) (protoreflect.MessageType, error) { // where the extension is declared and is unrelated to the full name of the // message being extended. // -// This returns (nil, NotFound) if not found. +// This returns (nil, [NotFound]) if not found. func (r *Types) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error) { if r == nil { return nil, NotFound @@ -703,7 +703,7 @@ func (r *Types) FindExtensionByName(field protoreflect.FullName) (protoreflect.E // FindExtensionByNumber looks up a extension field by the field number // within some parent message, identified by full name. // -// This returns (nil, NotFound) if not found. +// This returns (nil, [NotFound]) if not found. func (r *Types) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error) { if r == nil { return nil, NotFound diff --git a/vendor/google.golang.org/protobuf/reflect/protoregistry/registry_test.go b/vendor/google.golang.org/protobuf/reflect/protoregistry/registry_test.go deleted file mode 100644 index 8baf12f03b..0000000000 --- a/vendor/google.golang.org/protobuf/reflect/protoregistry/registry_test.go +++ /dev/null @@ -1,655 +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 protoregistry_test - -import ( - "fmt" - "strings" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" - - "google.golang.org/protobuf/encoding/prototext" - pimpl "google.golang.org/protobuf/internal/impl" - "google.golang.org/protobuf/reflect/protodesc" - "google.golang.org/protobuf/reflect/protoreflect" - "google.golang.org/protobuf/reflect/protoregistry" - - testpb "google.golang.org/protobuf/internal/testprotos/registry" - "google.golang.org/protobuf/types/descriptorpb" -) - -func mustMakeFile(s string) protoreflect.FileDescriptor { - pb := new(descriptorpb.FileDescriptorProto) - if err := prototext.Unmarshal([]byte(s), pb); err != nil { - panic(err) - } - fd, err := protodesc.NewFile(pb, nil) - if err != nil { - panic(err) - } - return fd -} - -func TestFiles(t *testing.T) { - type ( - file struct { - Path string - Pkg protoreflect.FullName - } - testFile struct { - inFile protoreflect.FileDescriptor - wantErr string - } - testFindDesc struct { - inName protoreflect.FullName - wantFound bool - } - testRangePkg struct { - inPkg protoreflect.FullName - wantFiles []file - } - testFindPath struct { - inPath string - wantFiles []file - wantErr string - } - ) - - tests := []struct { - files []testFile - findDescs []testFindDesc - rangePkgs []testRangePkg - findPaths []testFindPath - }{{ - // Test that overlapping packages and files are permitted. - files: []testFile{ - {inFile: mustMakeFile(`syntax:"proto2" name:"test1.proto" package:"foo.bar"`)}, - {inFile: mustMakeFile(`syntax:"proto2" name:"foo/bar/test.proto" package:"my.test"`)}, - {inFile: mustMakeFile(`syntax:"proto2" name:"foo/bar/test.proto" package:"foo.bar.baz"`), wantErr: "already registered"}, - {inFile: mustMakeFile(`syntax:"proto2" name:"test2.proto" package:"my.test.package"`)}, - {inFile: mustMakeFile(`syntax:"proto2" name:"weird" package:"foo.bar"`)}, - {inFile: mustMakeFile(`syntax:"proto2" name:"foo/bar/baz/../test.proto" package:"my.test"`)}, - }, - - rangePkgs: []testRangePkg{{ - inPkg: "nothing", - }, { - inPkg: "", - }, { - inPkg: ".", - }, { - inPkg: "foo", - }, { - inPkg: "foo.", - }, { - inPkg: "foo..", - }, { - inPkg: "foo.bar", - wantFiles: []file{ - {"test1.proto", "foo.bar"}, - {"weird", "foo.bar"}, - }, - }, { - inPkg: "my.test", - wantFiles: []file{ - {"foo/bar/baz/../test.proto", "my.test"}, - {"foo/bar/test.proto", "my.test"}, - }, - }, { - inPkg: "fo", - }}, - - findPaths: []testFindPath{{ - inPath: "nothing", - wantErr: "not found", - }, { - inPath: "weird", - wantFiles: []file{ - {"weird", "foo.bar"}, - }, - }, { - inPath: "foo/bar/test.proto", - wantFiles: []file{ - {"foo/bar/test.proto", "my.test"}, - }, - }}, - }, { - // Test when new enum conflicts with existing package. - files: []testFile{{ - inFile: mustMakeFile(`syntax:"proto2" name:"test1a.proto" package:"foo.bar.baz"`), - }, { - inFile: mustMakeFile(`syntax:"proto2" name:"test1b.proto" enum_type:[{name:"foo" value:[{name:"VALUE" number:0}]}]`), - wantErr: `file "test1b.proto" has a name conflict over foo`, - }}, - }, { - // Test when new package conflicts with existing enum. - files: []testFile{{ - inFile: mustMakeFile(`syntax:"proto2" name:"test2a.proto" enum_type:[{name:"foo" value:[{name:"VALUE" number:0}]}]`), - }, { - inFile: mustMakeFile(`syntax:"proto2" name:"test2b.proto" package:"foo.bar.baz"`), - wantErr: `file "test2b.proto" has a package name conflict over foo`, - }}, - }, { - // Test when new enum conflicts with existing enum in same package. - files: []testFile{{ - inFile: mustMakeFile(`syntax:"proto2" name:"test3a.proto" package:"foo" enum_type:[{name:"BAR" value:[{name:"VALUE" number:0}]}]`), - }, { - inFile: mustMakeFile(`syntax:"proto2" name:"test3b.proto" package:"foo" enum_type:[{name:"BAR" value:[{name:"VALUE2" number:0}]}]`), - wantErr: `file "test3b.proto" has a name conflict over foo.BAR`, - }}, - }, { - files: []testFile{{ - inFile: mustMakeFile(` - syntax: "proto2" - name: "test1.proto" - package: "fizz.buzz" - message_type: [{ - name: "Message" - field: [ - {name:"Field" number:1 label:LABEL_OPTIONAL type:TYPE_STRING oneof_index:0} - ] - oneof_decl: [{name:"Oneof"}] - extension_range: [{start:1000 end:2000}] - - enum_type: [ - {name:"Enum" value:[{name:"EnumValue" number:0}]} - ] - nested_type: [ - {name:"Message" field:[{name:"Field" number:1 label:LABEL_OPTIONAL type:TYPE_STRING}]} - ] - extension: [ - {name:"Extension" number:1001 label:LABEL_OPTIONAL type:TYPE_STRING extendee:".fizz.buzz.Message"} - ] - }] - enum_type: [{ - name: "Enum" - value: [{name:"EnumValue" number:0}] - }] - extension: [ - {name:"Extension" number:1000 label:LABEL_OPTIONAL type:TYPE_STRING extendee:".fizz.buzz.Message"} - ] - service: [{ - name: "Service" - method: [{ - name: "Method" - input_type: ".fizz.buzz.Message" - output_type: ".fizz.buzz.Message" - client_streaming: true - server_streaming: true - }] - }] - `), - }, { - inFile: mustMakeFile(` - syntax: "proto2" - name: "test2.proto" - package: "fizz.buzz.gazz" - enum_type: [{ - name: "Enum" - value: [{name:"EnumValue" number:0}] - }] - `), - }, { - inFile: mustMakeFile(` - syntax: "proto2" - name: "test3.proto" - package: "fizz.buzz" - enum_type: [{ - name: "Enum1" - value: [{name:"EnumValue1" number:0}] - }, { - name: "Enum2" - value: [{name:"EnumValue2" number:0}] - }] - `), - }, { - // Make sure we can register without package name. - inFile: mustMakeFile(` - name: "weird" - syntax: "proto2" - message_type: [{ - name: "Message" - nested_type: [{ - name: "Message" - nested_type: [{ - name: "Message" - }] - }] - }] - `), - }}, - findDescs: []testFindDesc{ - {inName: "fizz.buzz.message", wantFound: false}, - {inName: "fizz.buzz.Message", wantFound: true}, - {inName: "fizz.buzz.Message.X", wantFound: false}, - {inName: "fizz.buzz.Field", wantFound: false}, - {inName: "fizz.buzz.Oneof", wantFound: false}, - {inName: "fizz.buzz.Message.Field", wantFound: true}, - {inName: "fizz.buzz.Message.Field.X", wantFound: false}, - {inName: "fizz.buzz.Message.Oneof", wantFound: true}, - {inName: "fizz.buzz.Message.Oneof.X", wantFound: false}, - {inName: "fizz.buzz.Message.Message", wantFound: true}, - {inName: "fizz.buzz.Message.Message.X", wantFound: false}, - {inName: "fizz.buzz.Message.Enum", wantFound: true}, - {inName: "fizz.buzz.Message.Enum.X", wantFound: false}, - {inName: "fizz.buzz.Message.EnumValue", wantFound: true}, - {inName: "fizz.buzz.Message.EnumValue.X", wantFound: false}, - {inName: "fizz.buzz.Message.Extension", wantFound: true}, - {inName: "fizz.buzz.Message.Extension.X", wantFound: false}, - {inName: "fizz.buzz.enum", wantFound: false}, - {inName: "fizz.buzz.Enum", wantFound: true}, - {inName: "fizz.buzz.Enum.X", wantFound: false}, - {inName: "fizz.buzz.EnumValue", wantFound: true}, - {inName: "fizz.buzz.EnumValue.X", wantFound: false}, - {inName: "fizz.buzz.Enum.EnumValue", wantFound: false}, - {inName: "fizz.buzz.Extension", wantFound: true}, - {inName: "fizz.buzz.Extension.X", wantFound: false}, - {inName: "fizz.buzz.service", wantFound: false}, - {inName: "fizz.buzz.Service", wantFound: true}, - {inName: "fizz.buzz.Service.X", wantFound: false}, - {inName: "fizz.buzz.Method", wantFound: false}, - {inName: "fizz.buzz.Service.Method", wantFound: true}, - {inName: "fizz.buzz.Service.Method.X", wantFound: false}, - - {inName: "fizz.buzz.gazz", wantFound: false}, - {inName: "fizz.buzz.gazz.Enum", wantFound: true}, - {inName: "fizz.buzz.gazz.EnumValue", wantFound: true}, - {inName: "fizz.buzz.gazz.Enum.EnumValue", wantFound: false}, - - {inName: "fizz.buzz", wantFound: false}, - {inName: "fizz.buzz.Enum1", wantFound: true}, - {inName: "fizz.buzz.EnumValue1", wantFound: true}, - {inName: "fizz.buzz.Enum1.EnumValue1", wantFound: false}, - {inName: "fizz.buzz.Enum2", wantFound: true}, - {inName: "fizz.buzz.EnumValue2", wantFound: true}, - {inName: "fizz.buzz.Enum2.EnumValue2", wantFound: false}, - {inName: "fizz.buzz.Enum3", wantFound: false}, - - {inName: "", wantFound: false}, - {inName: "Message", wantFound: true}, - {inName: "Message.Message", wantFound: true}, - {inName: "Message.Message.Message", wantFound: true}, - {inName: "Message.Message.Message.Message", wantFound: false}, - }, - }} - - sortFiles := cmpopts.SortSlices(func(x, y file) bool { - return x.Path < y.Path || (x.Path == y.Path && x.Pkg < y.Pkg) - }) - for _, tt := range tests { - t.Run("", func(t *testing.T) { - var files protoregistry.Files - for i, tc := range tt.files { - gotErr := files.RegisterFile(tc.inFile) - if ((gotErr == nil) != (tc.wantErr == "")) || !strings.Contains(fmt.Sprint(gotErr), tc.wantErr) { - t.Errorf("file %d, Register() = %v, want %v", i, gotErr, tc.wantErr) - } - } - - for _, tc := range tt.findDescs { - d, _ := files.FindDescriptorByName(tc.inName) - gotFound := d != nil - if gotFound != tc.wantFound { - t.Errorf("FindDescriptorByName(%v) find mismatch: got %v, want %v", tc.inName, gotFound, tc.wantFound) - } - } - - for _, tc := range tt.rangePkgs { - var gotFiles []file - var gotCnt int - wantCnt := files.NumFilesByPackage(tc.inPkg) - files.RangeFilesByPackage(tc.inPkg, func(fd protoreflect.FileDescriptor) bool { - gotFiles = append(gotFiles, file{fd.Path(), fd.Package()}) - gotCnt++ - return true - }) - if gotCnt != wantCnt { - t.Errorf("NumFilesByPackage(%v) = %v, want %v", tc.inPkg, gotCnt, wantCnt) - } - if diff := cmp.Diff(tc.wantFiles, gotFiles, sortFiles); diff != "" { - t.Errorf("RangeFilesByPackage(%v) mismatch (-want +got):\n%v", tc.inPkg, diff) - } - } - - for _, tc := range tt.findPaths { - var gotFiles []file - fd, gotErr := files.FindFileByPath(tc.inPath) - if gotErr == nil { - gotFiles = append(gotFiles, file{fd.Path(), fd.Package()}) - } - if ((gotErr == nil) != (tc.wantErr == "")) || !strings.Contains(fmt.Sprint(gotErr), tc.wantErr) { - t.Errorf("FindFileByPath(%v) = %v, want %v", tc.inPath, gotErr, tc.wantErr) - } - if diff := cmp.Diff(tc.wantFiles, gotFiles, sortFiles); diff != "" { - t.Errorf("FindFileByPath(%v) mismatch (-want +got):\n%v", tc.inPath, diff) - } - } - }) - } -} - -func TestTypes(t *testing.T) { - mt1 := pimpl.Export{}.MessageTypeOf(&testpb.Message1{}) - et1 := pimpl.Export{}.EnumTypeOf(testpb.Enum1_ONE) - xt1 := testpb.E_StringField - xt2 := testpb.E_Message4_MessageField - registry := new(protoregistry.Types) - if err := registry.RegisterMessage(mt1); err != nil { - t.Fatalf("registry.RegisterMessage(%v) returns unexpected error: %v", mt1.Descriptor().FullName(), err) - } - if err := registry.RegisterEnum(et1); err != nil { - t.Fatalf("registry.RegisterEnum(%v) returns unexpected error: %v", et1.Descriptor().FullName(), err) - } - if err := registry.RegisterExtension(xt1); err != nil { - t.Fatalf("registry.RegisterExtension(%v) returns unexpected error: %v", xt1.TypeDescriptor().FullName(), err) - } - if err := registry.RegisterExtension(xt2); err != nil { - t.Fatalf("registry.RegisterExtension(%v) returns unexpected error: %v", xt2.TypeDescriptor().FullName(), err) - } - - t.Run("FindMessageByName", func(t *testing.T) { - tests := []struct { - name string - messageType protoreflect.MessageType - wantErr bool - wantNotFound bool - }{{ - name: "testprotos.Message1", - messageType: mt1, - }, { - name: "testprotos.NoSuchMessage", - wantErr: true, - wantNotFound: true, - }, { - name: "testprotos.Enum1", - wantErr: true, - }, { - name: "testprotos.Enum2", - wantErr: true, - }, { - name: "testprotos.Enum3", - wantErr: true, - }} - for _, tc := range tests { - got, err := registry.FindMessageByName(protoreflect.FullName(tc.name)) - gotErr := err != nil - if gotErr != tc.wantErr { - t.Errorf("FindMessageByName(%v) = (_, %v), want error? %t", tc.name, err, tc.wantErr) - continue - } - if tc.wantNotFound && err != protoregistry.NotFound { - t.Errorf("FindMessageByName(%v) got error: %v, want NotFound error", tc.name, err) - continue - } - if got != tc.messageType { - t.Errorf("FindMessageByName(%v) got wrong value: %v", tc.name, got) - } - } - }) - - t.Run("FindMessageByURL", func(t *testing.T) { - tests := []struct { - name string - messageType protoreflect.MessageType - wantErr bool - wantNotFound bool - }{{ - name: "testprotos.Message1", - messageType: mt1, - }, { - name: "type.googleapis.com/testprotos.Nada", - wantErr: true, - wantNotFound: true, - }, { - name: "testprotos.Enum1", - wantErr: true, - }} - for _, tc := range tests { - got, err := registry.FindMessageByURL(tc.name) - gotErr := err != nil - if gotErr != tc.wantErr { - t.Errorf("FindMessageByURL(%v) = (_, %v), want error? %t", tc.name, err, tc.wantErr) - continue - } - if tc.wantNotFound && err != protoregistry.NotFound { - t.Errorf("FindMessageByURL(%v) got error: %v, want NotFound error", tc.name, err) - continue - } - if got != tc.messageType { - t.Errorf("FindMessageByURL(%v) got wrong value: %v", tc.name, got) - } - } - }) - - t.Run("FindEnumByName", func(t *testing.T) { - tests := []struct { - name string - enumType protoreflect.EnumType - wantErr bool - wantNotFound bool - }{{ - name: "testprotos.Enum1", - enumType: et1, - }, { - name: "testprotos.None", - wantErr: true, - wantNotFound: true, - }, { - name: "testprotos.Message1", - wantErr: true, - }} - for _, tc := range tests { - got, err := registry.FindEnumByName(protoreflect.FullName(tc.name)) - gotErr := err != nil - if gotErr != tc.wantErr { - t.Errorf("FindEnumByName(%v) = (_, %v), want error? %t", tc.name, err, tc.wantErr) - continue - } - if tc.wantNotFound && err != protoregistry.NotFound { - t.Errorf("FindEnumByName(%v) got error: %v, want NotFound error", tc.name, err) - continue - } - if got != tc.enumType { - t.Errorf("FindEnumByName(%v) got wrong value: %v", tc.name, got) - } - } - }) - - t.Run("FindExtensionByName", func(t *testing.T) { - tests := []struct { - name string - extensionType protoreflect.ExtensionType - wantErr bool - wantNotFound bool - }{{ - name: "testprotos.string_field", - extensionType: xt1, - }, { - name: "testprotos.Message4.message_field", - extensionType: xt2, - }, { - name: "testprotos.None", - wantErr: true, - wantNotFound: true, - }, { - name: "testprotos.Message1", - wantErr: true, - }} - for _, tc := range tests { - got, err := registry.FindExtensionByName(protoreflect.FullName(tc.name)) - gotErr := err != nil - if gotErr != tc.wantErr { - t.Errorf("FindExtensionByName(%v) = (_, %v), want error? %t", tc.name, err, tc.wantErr) - continue - } - if tc.wantNotFound && err != protoregistry.NotFound { - t.Errorf("FindExtensionByName(%v) got error: %v, want NotFound error", tc.name, err) - continue - } - if got != tc.extensionType { - t.Errorf("FindExtensionByName(%v) got wrong value: %v", tc.name, got) - } - } - }) - - t.Run("FindExtensionByNumber", func(t *testing.T) { - tests := []struct { - parent string - number int32 - extensionType protoreflect.ExtensionType - wantErr bool - wantNotFound bool - }{{ - parent: "testprotos.Message1", - number: 11, - extensionType: xt1, - }, { - parent: "testprotos.Message1", - number: 13, - wantErr: true, - wantNotFound: true, - }, { - parent: "testprotos.Message1", - number: 21, - extensionType: xt2, - }, { - parent: "testprotos.Message1", - number: 23, - wantErr: true, - wantNotFound: true, - }, { - parent: "testprotos.NoSuchMessage", - number: 11, - wantErr: true, - wantNotFound: true, - }, { - parent: "testprotos.Message1", - number: 30, - wantErr: true, - wantNotFound: true, - }, { - parent: "testprotos.Message1", - number: 99, - wantErr: true, - wantNotFound: true, - }} - for _, tc := range tests { - got, err := registry.FindExtensionByNumber(protoreflect.FullName(tc.parent), protoreflect.FieldNumber(tc.number)) - gotErr := err != nil - if gotErr != tc.wantErr { - t.Errorf("FindExtensionByNumber(%v, %d) = (_, %v), want error? %t", tc.parent, tc.number, err, tc.wantErr) - continue - } - if tc.wantNotFound && err != protoregistry.NotFound { - t.Errorf("FindExtensionByNumber(%v, %d) got error %v, want NotFound error", tc.parent, tc.number, err) - continue - } - if got != tc.extensionType { - t.Errorf("FindExtensionByNumber(%v, %d) got wrong value: %v", tc.parent, tc.number, got) - } - } - }) - - sortTypes := cmp.Options{ - cmpopts.SortSlices(func(x, y protoreflect.EnumType) bool { - return x.Descriptor().FullName() < y.Descriptor().FullName() - }), - cmpopts.SortSlices(func(x, y protoreflect.MessageType) bool { - return x.Descriptor().FullName() < y.Descriptor().FullName() - }), - cmpopts.SortSlices(func(x, y protoreflect.ExtensionType) bool { - return x.TypeDescriptor().FullName() < y.TypeDescriptor().FullName() - }), - } - compare := cmp.Options{ - cmp.Comparer(func(x, y protoreflect.EnumType) bool { - return x == y - }), - cmp.Comparer(func(x, y protoreflect.ExtensionType) bool { - return x == y - }), - cmp.Comparer(func(x, y protoreflect.MessageType) bool { - return x == y - }), - } - - t.Run("RangeEnums", func(t *testing.T) { - want := []protoreflect.EnumType{et1} - var got []protoreflect.EnumType - var gotCnt int - wantCnt := registry.NumEnums() - registry.RangeEnums(func(et protoreflect.EnumType) bool { - got = append(got, et) - gotCnt++ - return true - }) - - if gotCnt != wantCnt { - t.Errorf("NumEnums() = %v, want %v", gotCnt, wantCnt) - } - if diff := cmp.Diff(want, got, sortTypes, compare); diff != "" { - t.Errorf("RangeEnums() mismatch (-want +got):\n%v", diff) - } - }) - - t.Run("RangeMessages", func(t *testing.T) { - want := []protoreflect.MessageType{mt1} - var got []protoreflect.MessageType - var gotCnt int - wantCnt := registry.NumMessages() - registry.RangeMessages(func(mt protoreflect.MessageType) bool { - got = append(got, mt) - gotCnt++ - return true - }) - - if gotCnt != wantCnt { - t.Errorf("NumMessages() = %v, want %v", gotCnt, wantCnt) - } - if diff := cmp.Diff(want, got, sortTypes, compare); diff != "" { - t.Errorf("RangeMessages() mismatch (-want +got):\n%v", diff) - } - }) - - t.Run("RangeExtensions", func(t *testing.T) { - want := []protoreflect.ExtensionType{xt1, xt2} - var got []protoreflect.ExtensionType - var gotCnt int - wantCnt := registry.NumExtensions() - registry.RangeExtensions(func(xt protoreflect.ExtensionType) bool { - got = append(got, xt) - gotCnt++ - return true - }) - - if gotCnt != wantCnt { - t.Errorf("NumExtensions() = %v, want %v", gotCnt, wantCnt) - } - if diff := cmp.Diff(want, got, sortTypes, compare); diff != "" { - t.Errorf("RangeExtensions() mismatch (-want +got):\n%v", diff) - } - }) - - t.Run("RangeExtensionsByMessage", func(t *testing.T) { - want := []protoreflect.ExtensionType{xt1, xt2} - var got []protoreflect.ExtensionType - var gotCnt int - wantCnt := registry.NumExtensionsByMessage("testprotos.Message1") - registry.RangeExtensionsByMessage("testprotos.Message1", func(xt protoreflect.ExtensionType) bool { - got = append(got, xt) - gotCnt++ - return true - }) - - if gotCnt != wantCnt { - t.Errorf("NumExtensionsByMessage() = %v, want %v", gotCnt, wantCnt) - } - if diff := cmp.Diff(want, got, sortTypes, compare); diff != "" { - t.Errorf("RangeExtensionsByMessage() mismatch (-want +got):\n%v", diff) - } - }) -} diff --git a/vendor/google.golang.org/protobuf/reflect/protoregistry/ya.make b/vendor/google.golang.org/protobuf/reflect/protoregistry/ya.make index 85b2be5127..a6fda0d69d 100644 --- a/vendor/google.golang.org/protobuf/reflect/protoregistry/ya.make +++ b/vendor/google.golang.org/protobuf/reflect/protoregistry/ya.make @@ -2,10 +2,8 @@ GO_LIBRARY() LICENSE(BSD-3-Clause) -SRCS(registry.go) - -GO_XTEST_SRCS(registry_test.go) +SRCS( + registry.go +) END() - -RECURSE(gotest) |