[VOL-5486] Fix deprecated versions
Change-Id: I3e03ea246020547ae75fa92ce8cf5cbba7e8f3bb
Signed-off-by: Abhay Kumar <abhay.kumar@radisys.com>
diff --git a/vendor/github.com/bufbuild/protocompile/LICENSE b/vendor/github.com/bufbuild/protocompile/LICENSE
new file mode 100644
index 0000000..553cbbf
--- /dev/null
+++ b/vendor/github.com/bufbuild/protocompile/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright 2020-2024 Buf Technologies, Inc.
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
diff --git a/vendor/github.com/bufbuild/protocompile/internal/editions/editions.go b/vendor/github.com/bufbuild/protocompile/internal/editions/editions.go
new file mode 100644
index 0000000..ee054fa
--- /dev/null
+++ b/vendor/github.com/bufbuild/protocompile/internal/editions/editions.go
@@ -0,0 +1,420 @@
+// Copyright 2020-2024 Buf Technologies, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package editions contains helpers related to resolving features for
+// Protobuf editions. These are lower-level helpers. Higher-level helpers
+// (which use this package under the hood) can be found in the exported
+// protoutil package.
+package editions
+
+import (
+ "fmt"
+ "strings"
+ "sync"
+
+ "google.golang.org/protobuf/encoding/prototext"
+ "google.golang.org/protobuf/proto"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/reflect/protoregistry"
+ "google.golang.org/protobuf/types/descriptorpb"
+ "google.golang.org/protobuf/types/dynamicpb"
+)
+
+const (
+ // MinSupportedEdition is the earliest edition supported by this module.
+ // It should be 2023 (the first edition) for the indefinite future.
+ MinSupportedEdition = descriptorpb.Edition_EDITION_2023
+
+ // MaxSupportedEdition is the most recent edition supported by this module.
+ MaxSupportedEdition = descriptorpb.Edition_EDITION_2023
+)
+
+var (
+ // SupportedEditions is the exhaustive set of editions that protocompile
+ // can support. We don't allow it to compile future/unknown editions, to
+ // make sure we don't generate incorrect descriptors, in the event that
+ // a future edition introduces a change or new feature that requires
+ // new logic in the compiler.
+ SupportedEditions = computeSupportedEditions(MinSupportedEdition, MaxSupportedEdition)
+
+ // FeatureSetDescriptor is the message descriptor for the compiled-in
+ // version (in the descriptorpb package) of the google.protobuf.FeatureSet
+ // message type.
+ FeatureSetDescriptor = (*descriptorpb.FeatureSet)(nil).ProtoReflect().Descriptor()
+ // FeatureSetType is the message type for the compiled-in version (in
+ // the descriptorpb package) of google.protobuf.FeatureSet.
+ FeatureSetType = (*descriptorpb.FeatureSet)(nil).ProtoReflect().Type()
+
+ editionDefaults map[descriptorpb.Edition]*descriptorpb.FeatureSet
+ editionDefaultsInit sync.Once
+)
+
+// HasFeatures is implemented by all options messages and provides a
+// nil-receiver-safe way of accessing the features explicitly configured
+// in those options.
+type HasFeatures interface {
+ GetFeatures() *descriptorpb.FeatureSet
+}
+
+var _ HasFeatures = (*descriptorpb.FileOptions)(nil)
+var _ HasFeatures = (*descriptorpb.MessageOptions)(nil)
+var _ HasFeatures = (*descriptorpb.FieldOptions)(nil)
+var _ HasFeatures = (*descriptorpb.OneofOptions)(nil)
+var _ HasFeatures = (*descriptorpb.ExtensionRangeOptions)(nil)
+var _ HasFeatures = (*descriptorpb.EnumOptions)(nil)
+var _ HasFeatures = (*descriptorpb.EnumValueOptions)(nil)
+var _ HasFeatures = (*descriptorpb.ServiceOptions)(nil)
+var _ HasFeatures = (*descriptorpb.MethodOptions)(nil)
+
+// ResolveFeature resolves a feature for the given descriptor. This simple
+// helper examines the given element and its ancestors, searching for an
+// override. If there is no overridden value, it returns a zero value.
+func ResolveFeature(
+ element protoreflect.Descriptor,
+ fields ...protoreflect.FieldDescriptor,
+) (protoreflect.Value, error) {
+ for {
+ var features *descriptorpb.FeatureSet
+ if withFeatures, ok := element.Options().(HasFeatures); ok {
+ // It should not really be possible for 'ok' to ever be false...
+ features = withFeatures.GetFeatures()
+ }
+
+ // TODO: adaptFeatureSet is only looking at the first field. But if we needed to
+ // support an extension field inside a custom feature, we'd really need
+ // to check all fields. That gets particularly complicated if the traversal
+ // path of fields includes list and map values. Luckily, features are not
+ // supposed to be repeated and not supposed to themselves have extensions.
+ // So this should be fine, at least for now.
+ msgRef, err := adaptFeatureSet(features, fields[0])
+ if err != nil {
+ return protoreflect.Value{}, err
+ }
+ // Navigate the fields to find the value
+ var val protoreflect.Value
+ for i, field := range fields {
+ if i > 0 {
+ msgRef = val.Message()
+ }
+ if !msgRef.Has(field) {
+ val = protoreflect.Value{}
+ break
+ }
+ val = msgRef.Get(field)
+ }
+ if val.IsValid() {
+ // All fields were set!
+ return val, nil
+ }
+
+ parent := element.Parent()
+ if parent == nil {
+ // We've reached the end of the inheritance chain.
+ return protoreflect.Value{}, nil
+ }
+ element = parent
+ }
+}
+
+// HasEdition should be implemented by values that implement
+// [protoreflect.FileDescriptor], to provide access to the file's
+// edition when its syntax is [protoreflect.Editions].
+type HasEdition interface {
+ // Edition returns the numeric value of a google.protobuf.Edition enum
+ // value that corresponds to the edition of this file. If the file does
+ // not use editions, it should return the enum value that corresponds
+ // to the syntax level, EDITION_PROTO2 or EDITION_PROTO3.
+ Edition() int32
+}
+
+// GetEdition returns the edition for a given element. It returns
+// EDITION_PROTO2 or EDITION_PROTO3 if the element is in a file that
+// uses proto2 or proto3 syntax, respectively. It returns EDITION_UNKNOWN
+// if the syntax of the given element is not recognized or if the edition
+// cannot be ascertained from the element's [protoreflect.FileDescriptor].
+func GetEdition(d protoreflect.Descriptor) descriptorpb.Edition {
+ switch d.ParentFile().Syntax() {
+ case protoreflect.Proto2:
+ return descriptorpb.Edition_EDITION_PROTO2
+ case protoreflect.Proto3:
+ return descriptorpb.Edition_EDITION_PROTO3
+ case protoreflect.Editions:
+ withEdition, ok := d.ParentFile().(HasEdition)
+ if !ok {
+ // The parent file should always be a *result, so we should
+ // never be able to actually get in here. If we somehow did
+ // have another implementation of protoreflect.FileDescriptor,
+ // it doesn't provide a way to get the edition, other than the
+ // potentially expensive step of generating a FileDescriptorProto
+ // and then querying for the edition from that. :/
+ return descriptorpb.Edition_EDITION_UNKNOWN
+ }
+ return descriptorpb.Edition(withEdition.Edition())
+ default:
+ return descriptorpb.Edition_EDITION_UNKNOWN
+ }
+}
+
+// GetEditionDefaults returns the default feature values for the given edition.
+// It returns nil if the given edition is not known.
+//
+// This only populates known features, those that are fields of [*descriptorpb.FeatureSet].
+// It does not populate any extension fields.
+//
+// The returned value must not be mutated as it references shared package state.
+func GetEditionDefaults(edition descriptorpb.Edition) *descriptorpb.FeatureSet {
+ editionDefaultsInit.Do(func() {
+ editionDefaults = make(map[descriptorpb.Edition]*descriptorpb.FeatureSet, len(descriptorpb.Edition_name))
+ // Compute default for all known editions in descriptorpb.
+ for editionInt := range descriptorpb.Edition_name {
+ edition := descriptorpb.Edition(editionInt)
+ defaults := &descriptorpb.FeatureSet{}
+ defaultsRef := defaults.ProtoReflect()
+ fields := defaultsRef.Descriptor().Fields()
+ // Note: we are not computing defaults for extensions. Those are not needed
+ // by anything in the compiler, so we can get away with just computing
+ // defaults for these static, non-extension fields.
+ for i, length := 0, fields.Len(); i < length; i++ {
+ field := fields.Get(i)
+ val, err := GetFeatureDefault(edition, FeatureSetType, field)
+ if err != nil {
+ // should we fail somehow??
+ continue
+ }
+ defaultsRef.Set(field, val)
+ }
+ editionDefaults[edition] = defaults
+ }
+ })
+ return editionDefaults[edition]
+}
+
+// GetFeatureDefault computes the default value for a feature. The given container
+// is the message type that contains the field. This should usually be the descriptor
+// for google.protobuf.FeatureSet, but can be a different message for computing the
+// default value of custom features.
+//
+// Note that this always re-computes the default. For known fields of FeatureSet,
+// it is more efficient to query from the statically computed default messages,
+// like so:
+//
+// editions.GetEditionDefaults(edition).ProtoReflect().Get(feature)
+func GetFeatureDefault(edition descriptorpb.Edition, container protoreflect.MessageType, feature protoreflect.FieldDescriptor) (protoreflect.Value, error) {
+ opts, ok := feature.Options().(*descriptorpb.FieldOptions)
+ if !ok {
+ // this is most likely impossible except for contrived use cases...
+ return protoreflect.Value{}, fmt.Errorf("options is %T instead of *descriptorpb.FieldOptions", feature.Options())
+ }
+ maxEdition := descriptorpb.Edition(-1)
+ var maxVal string
+ for _, def := range opts.EditionDefaults {
+ if def.GetEdition() <= edition && def.GetEdition() > maxEdition {
+ maxEdition = def.GetEdition()
+ maxVal = def.GetValue()
+ }
+ }
+ if maxEdition == -1 {
+ // no matching default found
+ return protoreflect.Value{}, fmt.Errorf("no relevant default for edition %s", edition)
+ }
+ // We use a typed nil so that it won't fall back to the global registry. Features
+ // should not use extensions or google.protobuf.Any, so a nil *Types is fine.
+ unmarshaler := prototext.UnmarshalOptions{Resolver: (*protoregistry.Types)(nil)}
+ // The string value is in the text format: either a field value literal or a
+ // message literal. (Repeated and map features aren't supported, so there's no
+ // array or map literal syntax to worry about.)
+ if feature.Kind() == protoreflect.MessageKind || feature.Kind() == protoreflect.GroupKind {
+ fldVal := container.Zero().NewField(feature)
+ err := unmarshaler.Unmarshal([]byte(maxVal), fldVal.Message().Interface())
+ if err != nil {
+ return protoreflect.Value{}, err
+ }
+ return fldVal, nil
+ }
+ // The value is the textformat for the field. But prototext doesn't provide a way
+ // to unmarshal a single field value. To work around, we unmarshal into an enclosing
+ // message, which means we must prefix the value with the field name.
+ if feature.IsExtension() {
+ maxVal = fmt.Sprintf("[%s]: %s", feature.FullName(), maxVal)
+ } else {
+ maxVal = fmt.Sprintf("%s: %s", feature.Name(), maxVal)
+ }
+ empty := container.New()
+ err := unmarshaler.Unmarshal([]byte(maxVal), empty.Interface())
+ if err != nil {
+ return protoreflect.Value{}, err
+ }
+ return empty.Get(feature), nil
+}
+
+func adaptFeatureSet(msg *descriptorpb.FeatureSet, field protoreflect.FieldDescriptor) (protoreflect.Message, error) {
+ msgRef := msg.ProtoReflect()
+ var actualField protoreflect.FieldDescriptor
+ switch {
+ case field.IsExtension():
+ // Extensions can be used directly with the feature set, even if
+ // field.ContainingMessage() != FeatureSetDescriptor. But only if
+ // the value is either not a message or is a message with the
+ // right descriptor, i.e. val.Descriptor() == field.Message().
+ if actualField = actualDescriptor(msgRef, field); actualField == nil || actualField == field {
+ if msgRef.Has(field) || len(msgRef.GetUnknown()) == 0 {
+ return msgRef, nil
+ }
+ // The field is not present, but the message has unrecognized values. So
+ // let's try to parse the unrecognized bytes, just in case they contain
+ // this extension.
+ temp := &descriptorpb.FeatureSet{}
+ unmarshaler := proto.UnmarshalOptions{
+ AllowPartial: true,
+ Resolver: resolverForExtension{field},
+ }
+ if err := unmarshaler.Unmarshal(msgRef.GetUnknown(), temp); err != nil {
+ return nil, fmt.Errorf("failed to parse unrecognized fields of FeatureSet: %w", err)
+ }
+ return temp.ProtoReflect(), nil
+ }
+ case field.ContainingMessage() == FeatureSetDescriptor:
+ // Known field, not dynamically generated. Can directly use with the feature set.
+ return msgRef, nil
+ default:
+ actualField = FeatureSetDescriptor.Fields().ByNumber(field.Number())
+ }
+
+ // If we get here, we have a dynamic field descriptor or an extension
+ // descriptor whose message type does not match the descriptor of the
+ // stored value. We need to copy its value into a dynamic message,
+ // which requires marshalling/unmarshalling.
+ // We only need to copy over the unrecognized bytes (if any)
+ // and the same field (if present).
+ data := msgRef.GetUnknown()
+ if actualField != nil && msgRef.Has(actualField) {
+ subset := &descriptorpb.FeatureSet{}
+ subset.ProtoReflect().Set(actualField, msgRef.Get(actualField))
+ var err error
+ data, err = proto.MarshalOptions{AllowPartial: true}.MarshalAppend(data, subset)
+ if err != nil {
+ return nil, fmt.Errorf("failed to marshal FeatureSet field %s to bytes: %w", field.Name(), err)
+ }
+ }
+ if len(data) == 0 {
+ // No relevant data to copy over, so we can just return
+ // a zero value message
+ return dynamicpb.NewMessageType(field.ContainingMessage()).Zero(), nil
+ }
+
+ other := dynamicpb.NewMessage(field.ContainingMessage())
+ // We don't need to use a resolver for this step because we know that
+ // field is not an extension. And features are not allowed to themselves
+ // have extensions.
+ if err := (proto.UnmarshalOptions{AllowPartial: true}).Unmarshal(data, other); err != nil {
+ return nil, fmt.Errorf("failed to marshal FeatureSet field %s to bytes: %w", field.Name(), err)
+ }
+ return other, nil
+}
+
+type resolverForExtension struct {
+ ext protoreflect.ExtensionDescriptor
+}
+
+func (r resolverForExtension) FindMessageByName(_ protoreflect.FullName) (protoreflect.MessageType, error) {
+ return nil, protoregistry.NotFound
+}
+
+func (r resolverForExtension) FindMessageByURL(_ string) (protoreflect.MessageType, error) {
+ return nil, protoregistry.NotFound
+}
+
+func (r resolverForExtension) FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error) {
+ if field == r.ext.FullName() {
+ return asExtensionType(r.ext), nil
+ }
+ return nil, protoregistry.NotFound
+}
+
+func (r resolverForExtension) FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error) {
+ if message == r.ext.ContainingMessage().FullName() && field == r.ext.Number() {
+ return asExtensionType(r.ext), nil
+ }
+ return nil, protoregistry.NotFound
+}
+
+func asExtensionType(ext protoreflect.ExtensionDescriptor) protoreflect.ExtensionType {
+ if xtd, ok := ext.(protoreflect.ExtensionTypeDescriptor); ok {
+ return xtd.Type()
+ }
+ return dynamicpb.NewExtensionType(ext)
+}
+
+func computeSupportedEditions(minEdition, maxEdition descriptorpb.Edition) map[string]descriptorpb.Edition {
+ supportedEditions := map[string]descriptorpb.Edition{}
+ for editionNum := range descriptorpb.Edition_name {
+ edition := descriptorpb.Edition(editionNum)
+ if edition >= minEdition && edition <= maxEdition {
+ name := strings.TrimPrefix(edition.String(), "EDITION_")
+ supportedEditions[name] = edition
+ }
+ }
+ return supportedEditions
+}
+
+// actualDescriptor returns the actual field descriptor referenced by msg that
+// corresponds to the given ext (i.e. same number). It returns nil if msg has
+// no reference, if the actual descriptor is the same as ext, or if ext is
+// otherwise safe to use as is.
+func actualDescriptor(msg protoreflect.Message, ext protoreflect.ExtensionDescriptor) protoreflect.FieldDescriptor {
+ if !msg.Has(ext) || ext.Message() == nil {
+ // nothing to match; safe as is
+ return nil
+ }
+ val := msg.Get(ext)
+ switch {
+ case ext.IsMap(): // should not actually be possible
+ expectedDescriptor := ext.MapValue().Message()
+ if expectedDescriptor == nil {
+ return nil // nothing to match
+ }
+ // We know msg.Has(field) is true, from above, so there's at least one entry.
+ var matches bool
+ val.Map().Range(func(_ protoreflect.MapKey, val protoreflect.Value) bool {
+ matches = val.Message().Descriptor() == expectedDescriptor
+ return false
+ })
+ if matches {
+ return nil
+ }
+ case ext.IsList():
+ // We know msg.Has(field) is true, from above, so there's at least one entry.
+ if val.List().Get(0).Message().Descriptor() == ext.Message() {
+ return nil
+ }
+ case !ext.IsMap():
+ if val.Message().Descriptor() == ext.Message() {
+ return nil
+ }
+ }
+ // The underlying message descriptors do not match. So we need to return
+ // the actual field descriptor. Sadly, protoreflect.Message provides no way
+ // to query the field descriptor in a message by number. For non-extensions,
+ // one can query the associated message descriptor. But for extensions, we
+ // have to do the slow thing, and range through all fields looking for it.
+ var actualField protoreflect.FieldDescriptor
+ msg.Range(func(fd protoreflect.FieldDescriptor, _ protoreflect.Value) bool {
+ if fd.Number() == ext.Number() {
+ actualField = fd
+ return false
+ }
+ return true
+ })
+ return actualField
+}
diff --git a/vendor/github.com/bufbuild/protocompile/protoutil/editions.go b/vendor/github.com/bufbuild/protocompile/protoutil/editions.go
new file mode 100644
index 0000000..fb21dff
--- /dev/null
+++ b/vendor/github.com/bufbuild/protocompile/protoutil/editions.go
@@ -0,0 +1,140 @@
+// Copyright 2020-2024 Buf Technologies, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package protoutil
+
+import (
+ "fmt"
+
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/types/descriptorpb"
+ "google.golang.org/protobuf/types/dynamicpb"
+
+ "github.com/bufbuild/protocompile/internal/editions"
+)
+
+// GetFeatureDefault gets the default value for the given feature and the given
+// edition. The given feature must represent a field of the google.protobuf.FeatureSet
+// message and must not be an extension.
+//
+// If the given field is from a dynamically built descriptor (i.e. it's containing
+// message descriptor is different from the linked-in descriptor for
+// [*descriptorpb.FeatureSet]), the returned value may be a dynamic value. In such
+// cases, the value may not be directly usable using [protoreflect.Message.Set] with
+// an instance of [*descriptorpb.FeatureSet] and must instead be used with a
+// [*dynamicpb.Message].
+//
+// To get the default value of a custom feature, use [GetCustomFeatureDefault]
+// instead.
+func GetFeatureDefault(edition descriptorpb.Edition, feature protoreflect.FieldDescriptor) (protoreflect.Value, error) {
+ if feature.ContainingMessage().FullName() != editions.FeatureSetDescriptor.FullName() {
+ return protoreflect.Value{}, fmt.Errorf("feature %s is a field of %s but should be a field of %s",
+ feature.Name(), feature.ContainingMessage().FullName(), editions.FeatureSetDescriptor.FullName())
+ }
+ var msgType protoreflect.MessageType
+ if feature.ContainingMessage() == editions.FeatureSetDescriptor {
+ msgType = editions.FeatureSetType
+ } else {
+ msgType = dynamicpb.NewMessageType(feature.ContainingMessage())
+ }
+ return editions.GetFeatureDefault(edition, msgType, feature)
+}
+
+// GetCustomFeatureDefault gets the default value for the given custom feature
+// and given edition. A custom feature is a field whose containing message is the
+// type of an extension field of google.protobuf.FeatureSet. The given extension
+// describes that extension field and message type. The given feature must be a
+// field of that extension's message type.
+func GetCustomFeatureDefault(edition descriptorpb.Edition, extension protoreflect.ExtensionType, feature protoreflect.FieldDescriptor) (protoreflect.Value, error) {
+ extDesc := extension.TypeDescriptor()
+ if extDesc.ContainingMessage().FullName() != editions.FeatureSetDescriptor.FullName() {
+ return protoreflect.Value{}, fmt.Errorf("extension %s does not extend %s", extDesc.FullName(), editions.FeatureSetDescriptor.FullName())
+ }
+ if extDesc.Message() == nil {
+ return protoreflect.Value{}, fmt.Errorf("extensions of %s should be messages; %s is instead %s",
+ editions.FeatureSetDescriptor.FullName(), extDesc.FullName(), extDesc.Kind().String())
+ }
+ if feature.IsExtension() {
+ return protoreflect.Value{}, fmt.Errorf("feature %s is an extension, but feature extension %s may not itself have extensions",
+ feature.FullName(), extDesc.FullName())
+ }
+ if feature.ContainingMessage().FullName() != extDesc.Message().FullName() {
+ return protoreflect.Value{}, fmt.Errorf("feature %s is a field of %s but should be a field of %s",
+ feature.Name(), feature.ContainingMessage().FullName(), extDesc.Message().FullName())
+ }
+ if feature.ContainingMessage() != extDesc.Message() {
+ return protoreflect.Value{}, fmt.Errorf("feature %s has a different message descriptor from the given extension type for %s",
+ feature.Name(), extDesc.Message().FullName())
+ }
+ return editions.GetFeatureDefault(edition, extension.Zero().Message().Type(), feature)
+}
+
+// ResolveFeature resolves a feature for the given descriptor.
+//
+// If the given element is in a proto2 or proto3 syntax file, this skips
+// resolution and just returns the relevant default (since such files are not
+// allowed to override features). If neither the given element nor any of its
+// ancestors override the given feature, the relevant default is returned.
+//
+// This has the same caveat as GetFeatureDefault if the given feature is from a
+// dynamically built descriptor.
+func ResolveFeature(element protoreflect.Descriptor, feature protoreflect.FieldDescriptor) (protoreflect.Value, error) {
+ edition := editions.GetEdition(element)
+ defaultVal, err := GetFeatureDefault(edition, feature)
+ if err != nil {
+ return protoreflect.Value{}, err
+ }
+ return resolveFeature(edition, defaultVal, element, feature)
+}
+
+// ResolveCustomFeature resolves a custom feature for the given extension and
+// field descriptor.
+//
+// The given extension must be an extension of google.protobuf.FeatureSet that
+// represents a non-repeated message value. The given feature is a field in
+// that extension's message type.
+//
+// If the given element is in a proto2 or proto3 syntax file, this skips
+// resolution and just returns the relevant default (since such files are not
+// allowed to override features). If neither the given element nor any of its
+// ancestors override the given feature, the relevant default is returned.
+func ResolveCustomFeature(element protoreflect.Descriptor, extension protoreflect.ExtensionType, feature protoreflect.FieldDescriptor) (protoreflect.Value, error) {
+ edition := editions.GetEdition(element)
+ defaultVal, err := GetCustomFeatureDefault(edition, extension, feature)
+ if err != nil {
+ return protoreflect.Value{}, err
+ }
+ return resolveFeature(edition, defaultVal, element, extension.TypeDescriptor(), feature)
+}
+
+func resolveFeature(
+ edition descriptorpb.Edition,
+ defaultVal protoreflect.Value,
+ element protoreflect.Descriptor,
+ fields ...protoreflect.FieldDescriptor,
+) (protoreflect.Value, error) {
+ if edition == descriptorpb.Edition_EDITION_PROTO2 || edition == descriptorpb.Edition_EDITION_PROTO3 {
+ // these syntax levels can't specify features, so we can short-circuit the search
+ // through the descriptor hierarchy for feature overrides
+ return defaultVal, nil
+ }
+ val, err := editions.ResolveFeature(element, fields...)
+ if err != nil {
+ return protoreflect.Value{}, err
+ }
+ if val.IsValid() {
+ return val, nil
+ }
+ return defaultVal, nil
+}
diff --git a/vendor/github.com/bufbuild/protocompile/protoutil/protos.go b/vendor/github.com/bufbuild/protocompile/protoutil/protos.go
new file mode 100644
index 0000000..9c55999
--- /dev/null
+++ b/vendor/github.com/bufbuild/protocompile/protoutil/protos.go
@@ -0,0 +1,262 @@
+// Copyright 2020-2024 Buf Technologies, Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Package protoutil contains useful functions for interacting with descriptors.
+// For now these include only functions for efficiently converting descriptors
+// produced by the compiler to descriptor protos and functions for resolving
+// "features" (a core concept of Protobuf Editions).
+//
+// Despite the fact that descriptor protos are mutable, calling code should NOT
+// mutate any of the protos returned from this package. For efficiency, some
+// values returned from this package may reference internal state of a compiler
+// result, and mutating the proto could corrupt or invalidate parts of that
+// result.
+package protoutil
+
+import (
+ "google.golang.org/protobuf/proto"
+ "google.golang.org/protobuf/reflect/protodesc"
+ "google.golang.org/protobuf/reflect/protoreflect"
+ "google.golang.org/protobuf/types/descriptorpb"
+)
+
+// DescriptorProtoWrapper is a protoreflect.Descriptor that wraps an
+// underlying descriptor proto. It provides the same interface as
+// Descriptor but with one extra operation, to efficiently query for
+// the underlying descriptor proto.
+//
+// Descriptors that implement this will also implement another method
+// whose specified return type is the concrete type returned by the
+// AsProto method. The name of this method varies by the type of this
+// descriptor:
+//
+// Descriptor Type Other Method Name
+// ---------------------+------------------------------------
+// FileDescriptor | FileDescriptorProto()
+// MessageDescriptor | MessageDescriptorProto()
+// FieldDescriptor | FieldDescriptorProto()
+// OneofDescriptor | OneofDescriptorProto()
+// EnumDescriptor | EnumDescriptorProto()
+// EnumValueDescriptor | EnumValueDescriptorProto()
+// ServiceDescriptor | ServiceDescriptorProto()
+// MethodDescriptor | MethodDescriptorProto()
+//
+// For example, a DescriptorProtoWrapper that implements FileDescriptor
+// returns a *descriptorpb.FileDescriptorProto value from its AsProto
+// method and also provides a method with the following signature:
+//
+// FileDescriptorProto() *descriptorpb.FileDescriptorProto
+type DescriptorProtoWrapper interface {
+ protoreflect.Descriptor
+ // AsProto returns the underlying descriptor proto. The concrete
+ // type of the proto message depends on the type of this
+ // descriptor:
+ // Descriptor Type Proto Message Type
+ // ---------------------+------------------------------------
+ // FileDescriptor | *descriptorpb.FileDescriptorProto
+ // MessageDescriptor | *descriptorpb.DescriptorProto
+ // FieldDescriptor | *descriptorpb.FieldDescriptorProto
+ // OneofDescriptor | *descriptorpb.OneofDescriptorProto
+ // EnumDescriptor | *descriptorpb.EnumDescriptorProto
+ // EnumValueDescriptor | *descriptorpb.EnumValueDescriptorProto
+ // ServiceDescriptor | *descriptorpb.ServiceDescriptorProto
+ // MethodDescriptor | *descriptorpb.MethodDescriptorProto
+ AsProto() proto.Message
+}
+
+// ProtoFromDescriptor extracts a descriptor proto from the given "rich"
+// descriptor. For descriptors generated by the compiler, this is an
+// inexpensive and non-lossy operation. Descriptors from other sources
+// however may be expensive (to re-create a proto) and even lossy.
+func ProtoFromDescriptor(d protoreflect.Descriptor) proto.Message {
+ switch d := d.(type) {
+ case protoreflect.FileDescriptor:
+ return ProtoFromFileDescriptor(d)
+ case protoreflect.MessageDescriptor:
+ return ProtoFromMessageDescriptor(d)
+ case protoreflect.FieldDescriptor:
+ return ProtoFromFieldDescriptor(d)
+ case protoreflect.OneofDescriptor:
+ return ProtoFromOneofDescriptor(d)
+ case protoreflect.EnumDescriptor:
+ return ProtoFromEnumDescriptor(d)
+ case protoreflect.EnumValueDescriptor:
+ return ProtoFromEnumValueDescriptor(d)
+ case protoreflect.ServiceDescriptor:
+ return ProtoFromServiceDescriptor(d)
+ case protoreflect.MethodDescriptor:
+ return ProtoFromMethodDescriptor(d)
+ default:
+ // WTF??
+ if res, ok := d.(DescriptorProtoWrapper); ok {
+ return res.AsProto()
+ }
+ return nil
+ }
+}
+
+// ProtoFromFileDescriptor extracts a descriptor proto from the given "rich"
+// descriptor. For file descriptors generated by the compiler, this is an
+// inexpensive and non-lossy operation. File descriptors from other sources
+// however may be expensive (to re-create a proto) and even lossy.
+func ProtoFromFileDescriptor(d protoreflect.FileDescriptor) *descriptorpb.FileDescriptorProto {
+ if imp, ok := d.(protoreflect.FileImport); ok {
+ d = imp.FileDescriptor
+ }
+ type canProto interface {
+ FileDescriptorProto() *descriptorpb.FileDescriptorProto
+ }
+ if res, ok := d.(canProto); ok {
+ return res.FileDescriptorProto()
+ }
+ if res, ok := d.(DescriptorProtoWrapper); ok {
+ if fd, ok := res.AsProto().(*descriptorpb.FileDescriptorProto); ok {
+ return fd
+ }
+ }
+ return protodesc.ToFileDescriptorProto(d)
+}
+
+// ProtoFromMessageDescriptor extracts a descriptor proto from the given "rich"
+// descriptor. For message descriptors generated by the compiler, this is an
+// inexpensive and non-lossy operation. Message descriptors from other sources
+// however may be expensive (to re-create a proto) and even lossy.
+func ProtoFromMessageDescriptor(d protoreflect.MessageDescriptor) *descriptorpb.DescriptorProto {
+ type canProto interface {
+ MessageDescriptorProto() *descriptorpb.DescriptorProto
+ }
+ if res, ok := d.(canProto); ok {
+ return res.MessageDescriptorProto()
+ }
+ if res, ok := d.(DescriptorProtoWrapper); ok {
+ if md, ok := res.AsProto().(*descriptorpb.DescriptorProto); ok {
+ return md
+ }
+ }
+ return protodesc.ToDescriptorProto(d)
+}
+
+// ProtoFromFieldDescriptor extracts a descriptor proto from the given "rich"
+// descriptor. For field descriptors generated by the compiler, this is an
+// inexpensive and non-lossy operation. Field descriptors from other sources
+// however may be expensive (to re-create a proto) and even lossy.
+func ProtoFromFieldDescriptor(d protoreflect.FieldDescriptor) *descriptorpb.FieldDescriptorProto {
+ type canProto interface {
+ FieldDescriptorProto() *descriptorpb.FieldDescriptorProto
+ }
+ if res, ok := d.(canProto); ok {
+ return res.FieldDescriptorProto()
+ }
+ if res, ok := d.(DescriptorProtoWrapper); ok {
+ if fd, ok := res.AsProto().(*descriptorpb.FieldDescriptorProto); ok {
+ return fd
+ }
+ }
+ return protodesc.ToFieldDescriptorProto(d)
+}
+
+// ProtoFromOneofDescriptor extracts a descriptor proto from the given "rich"
+// descriptor. For oneof descriptors generated by the compiler, this is an
+// inexpensive and non-lossy operation. Oneof descriptors from other sources
+// however may be expensive (to re-create a proto) and even lossy.
+func ProtoFromOneofDescriptor(d protoreflect.OneofDescriptor) *descriptorpb.OneofDescriptorProto {
+ type canProto interface {
+ OneofDescriptorProto() *descriptorpb.OneofDescriptorProto
+ }
+ if res, ok := d.(canProto); ok {
+ return res.OneofDescriptorProto()
+ }
+ if res, ok := d.(DescriptorProtoWrapper); ok {
+ if ood, ok := res.AsProto().(*descriptorpb.OneofDescriptorProto); ok {
+ return ood
+ }
+ }
+ return protodesc.ToOneofDescriptorProto(d)
+}
+
+// ProtoFromEnumDescriptor extracts a descriptor proto from the given "rich"
+// descriptor. For enum descriptors generated by the compiler, this is an
+// inexpensive and non-lossy operation. Enum descriptors from other sources
+// however may be expensive (to re-create a proto) and even lossy.
+func ProtoFromEnumDescriptor(d protoreflect.EnumDescriptor) *descriptorpb.EnumDescriptorProto {
+ type canProto interface {
+ EnumDescriptorProto() *descriptorpb.EnumDescriptorProto
+ }
+ if res, ok := d.(canProto); ok {
+ return res.EnumDescriptorProto()
+ }
+ if res, ok := d.(DescriptorProtoWrapper); ok {
+ if ed, ok := res.AsProto().(*descriptorpb.EnumDescriptorProto); ok {
+ return ed
+ }
+ }
+ return protodesc.ToEnumDescriptorProto(d)
+}
+
+// ProtoFromEnumValueDescriptor extracts a descriptor proto from the given "rich"
+// descriptor. For enum value descriptors generated by the compiler, this is an
+// inexpensive and non-lossy operation. Enum value descriptors from other sources
+// however may be expensive (to re-create a proto) and even lossy.
+func ProtoFromEnumValueDescriptor(d protoreflect.EnumValueDescriptor) *descriptorpb.EnumValueDescriptorProto {
+ type canProto interface {
+ EnumValueDescriptorProto() *descriptorpb.EnumValueDescriptorProto
+ }
+ if res, ok := d.(canProto); ok {
+ return res.EnumValueDescriptorProto()
+ }
+ if res, ok := d.(DescriptorProtoWrapper); ok {
+ if ed, ok := res.AsProto().(*descriptorpb.EnumValueDescriptorProto); ok {
+ return ed
+ }
+ }
+ return protodesc.ToEnumValueDescriptorProto(d)
+}
+
+// ProtoFromServiceDescriptor extracts a descriptor proto from the given "rich"
+// descriptor. For service descriptors generated by the compiler, this is an
+// inexpensive and non-lossy operation. Service descriptors from other sources
+// however may be expensive (to re-create a proto) and even lossy.
+func ProtoFromServiceDescriptor(d protoreflect.ServiceDescriptor) *descriptorpb.ServiceDescriptorProto {
+ type canProto interface {
+ ServiceDescriptorProto() *descriptorpb.ServiceDescriptorProto
+ }
+ if res, ok := d.(canProto); ok {
+ return res.ServiceDescriptorProto()
+ }
+ if res, ok := d.(DescriptorProtoWrapper); ok {
+ if sd, ok := res.AsProto().(*descriptorpb.ServiceDescriptorProto); ok {
+ return sd
+ }
+ }
+ return protodesc.ToServiceDescriptorProto(d)
+}
+
+// ProtoFromMethodDescriptor extracts a descriptor proto from the given "rich"
+// descriptor. For method descriptors generated by the compiler, this is an
+// inexpensive and non-lossy operation. Method descriptors from other sources
+// however may be expensive (to re-create a proto) and even lossy.
+func ProtoFromMethodDescriptor(d protoreflect.MethodDescriptor) *descriptorpb.MethodDescriptorProto {
+ type canProto interface {
+ MethodDescriptorProto() *descriptorpb.MethodDescriptorProto
+ }
+ if res, ok := d.(canProto); ok {
+ return res.MethodDescriptorProto()
+ }
+ if res, ok := d.(DescriptorProtoWrapper); ok {
+ if md, ok := res.AsProto().(*descriptorpb.MethodDescriptorProto); ok {
+ return md
+ }
+ }
+ return protodesc.ToMethodDescriptorProto(d)
+}