| 1 | // Copyright 2018 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | // Package pb reflects over protocol buffer descriptors to generate objects |
| 16 | // that simplify type, enum, and field lookup. |
| 17 | package pbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/ |
| 18 | |
| 19 | import ( |
| 20 | "fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/" |
| 21 | |
| 22 | "google.golang.org/protobuf/protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/" |
| 23 | "google.golang.org/protobuf/reflect/protoreflectscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/" |
| 24 | "google.golang.org/protobuf/reflect/protoregistryscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoregistry`/" |
| 25 | |
| 26 | anypbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/anypb`/ "google.golang.org/protobuf/types/known/anypbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/anypb`/" |
| 27 | durpbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/durationpb`/ "google.golang.org/protobuf/types/known/durationpbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/durationpb`/" |
| 28 | emptypbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/emptypb`/ "google.golang.org/protobuf/types/known/emptypbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/emptypb`/" |
| 29 | structpbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/structpb`/ "google.golang.org/protobuf/types/known/structpbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/structpb`/" |
| 30 | tspbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/timestamppb`/ "google.golang.org/protobuf/types/known/timestamppbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/timestamppb`/" |
| 31 | wrapperspbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/wrapperspb`/ "google.golang.org/protobuf/types/known/wrapperspbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/wrapperspb`/" |
| 32 | ) |
| 33 | |
| 34 | // Db maps from file / message / enum name to file description. |
| 35 | // |
| 36 | // Each Db is isolated from each other, and while information about protobuf descriptors may be |
| 37 | // fetched from the global protobuf registry, no descriptors are added to this registry, else |
| 38 | // the isolation guarantees of the Db object would be violated. |
| 39 | type Dbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db# struct { |
| 40 | revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap. map[string]*FileDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription# |
| 41 | // files contains the deduped set of FileDescriptions whose types are contained in the pb.Db. |
| 42 | filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files. []*FileDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription# |
| 43 | // extensions contains the mapping between a given type name, extension name and its FieldDescription |
| 44 | extensionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#extensions. map[string]map[string]*FieldDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FieldDescription# |
| 45 | } |
| 46 | |
| 47 | // extensionsMap is a type alias to a map[typeName]map[extensionName]*FieldDescription |
| 48 | type extensionMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/extensionMap# = map[string]map[string]*FieldDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FieldDescription# |
| 49 | |
| 50 | var ( |
| 51 | // DefaultDb used at evaluation time or unless overridden at check time. |
| 52 | DefaultDbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/DefaultDb. = &Dbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#{ |
| 53 | revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.: make(map[string]*FileDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#), |
| 54 | filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files.: []*FileDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#{}, |
| 55 | extensionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#extensions.: make(extensionMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/extensionMap#), |
| 56 | } |
| 57 | ) |
| 58 | |
| 59 | // Merge will copy the source proto message into the destination, or error if the merge cannot be completed. |
| 60 | // |
| 61 | // Unlike the proto.Merge, this method will fallback to proto.Marshal/Unmarshal of the two proto messages do not |
| 62 | // share the same instance of their type descriptor. |
| 63 | func Mergescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Merge().(dstPB, srcPB protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.Messagescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/Message#) error { |
| 64 | src, dst := srcPB.ProtoReflectscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/ProtoMessage#ProtoReflect().(), dstPB.ProtoReflectscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/ProtoMessage#ProtoReflect().() |
| 65 | if src.Descriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Message#Descriptor().() == dst.Descriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Message#Descriptor().() { |
| 66 | protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.Mergescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/Merge().(dstPB, srcPB) |
| 67 | return nil |
| 68 | } |
| 69 | if src.Descriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Message#Descriptor().().FullNamescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Descriptor#FullName().() != dst.Descriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Message#Descriptor().().FullNamescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Descriptor#FullName().() { |
| 70 | return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("pb.Merge() arguments must be the same type. got: %v, %v", |
| 71 | dst.Descriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Message#Descriptor().().FullNamescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Descriptor#FullName().(), src.Descriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Message#Descriptor().().FullNamescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Descriptor#FullName().()) |
| 72 | } |
| 73 | bytes, err := protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.Marshalscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/Marshal().(srcPB) |
| 74 | if err != nil { |
| 75 | return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("pb.Merge(dstPB, srcPB) failed to marshal source proto: %v", err) |
| 76 | } |
| 77 | err = protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.Unmarshalscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/Unmarshal().(bytes, dstPB) |
| 78 | if err != nil { |
| 79 | return fmtscip-go gomod github.com/golang/go/src go1.23.0 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.23.0 fmt/Errorf().("pb.Merge(dstPB, srcPB) failed to unmarshal to dest proto: %v", err) |
| 80 | } |
| 81 | return nil |
| 82 | } |
| 83 | |
| 84 | // NewDb creates a new `pb.Db` with an empty type name to file description map. |
| 85 | func NewDbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/NewDb().() *Dbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db# { |
| 86 | pbdb := &Dbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#{ |
| 87 | revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.: make(map[string]*FileDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#), |
| 88 | filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files.: []*FileDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#{}, |
| 89 | extensionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#extensions.: make(extensionMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/extensionMap#), |
| 90 | } |
| 91 | // The FileDescription objects in the default db contain lazily initialized TypeDescription |
| 92 | // values which may point to the state contained in the DefaultDb irrespective of this shallow |
| 93 | // copy; however, the type graph for a field is idempotently computed, and is guaranteed to |
| 94 | // only be initialized once thanks to atomic values within the TypeDescription objects, so it |
| 95 | // is safe to share these values across instances. |
| 96 | for k, v := range DefaultDbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/DefaultDb..revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap. { |
| 97 | pbdb.revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.[k] = v |
| 98 | } |
| 99 | pbdb.filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files. = append(pbdb.filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files., DefaultDbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/DefaultDb..filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files....) |
| 100 | return pbdb |
| 101 | } |
| 102 | |
| 103 | // Copy creates a copy of the current database with its own internal descriptor mapping. |
| 104 | func (pbdb *Dbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#) Copyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#Copy().() *Dbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db# { |
| 105 | copy := NewDbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/NewDb().() |
| 106 | for _, fd := range pbdb.filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files. { |
| 107 | hasFile := false |
| 108 | for _, fd2 := range copy.filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files. { |
| 109 | if fd2 == fd { |
| 110 | hasFile = true |
| 111 | } |
| 112 | } |
| 113 | if !hasFile { |
| 114 | fd = fd.Copyscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#Copy().(copy) |
| 115 | copy.filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files. = append(copy.filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files., fd) |
| 116 | } |
| 117 | for _, enumValName := range fd.GetEnumNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#GetEnumNames().() { |
| 118 | copy.revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.[enumValName] = fd |
| 119 | } |
| 120 | for _, msgTypeName := range fd.GetTypeNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#GetTypeNames().() { |
| 121 | copy.revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.[msgTypeName] = fd |
| 122 | } |
| 123 | copy.revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.[fd.GetNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#GetName().()] = fd |
| 124 | } |
| 125 | for typeName, extFieldMap := range pbdb.extensionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#extensions. { |
| 126 | copyExtFieldMap, found := copy.extensionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#extensions.[typeName] |
| 127 | if !found { |
| 128 | copyExtFieldMap = make(map[string]*FieldDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FieldDescription#, len(extFieldMap)) |
| 129 | } |
| 130 | for extFieldName, fd := range extFieldMap { |
| 131 | copyExtFieldMap[extFieldName] = fd |
| 132 | } |
| 133 | copy.extensionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#extensions.[typeName] = copyExtFieldMap |
| 134 | } |
| 135 | return copy |
| 136 | } |
| 137 | |
| 138 | // FileDescriptions returns the set of file descriptions associated with this db. |
| 139 | func (pbdb *Dbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#) FileDescriptionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#FileDescriptions().() []*FileDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription# { |
| 140 | return pbdb.filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files. |
| 141 | } |
| 142 | |
| 143 | // RegisterDescriptor produces a `FileDescription` from a `FileDescriptor` and registers the |
| 144 | // message and enum types into the `pb.Db`. |
| 145 | func (pbdb *Dbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#) RegisterDescriptorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#RegisterDescriptor().(fileDesc protoreflectscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/.FileDescriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor#) (*FileDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#, error) { |
| 146 | fd, found := pbdb.revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.[fileDesc.Pathscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor#Path().()] |
| 147 | if found { |
| 148 | return fd, nil |
| 149 | } |
| 150 | // Make sure to search the global registry to see if a protoreflect.FileDescriptor for |
| 151 | // the file specified has been linked into the binary. If so, use the copy of the descriptor |
| 152 | // from the global cache. |
| 153 | // |
| 154 | // Note: Proto reflection relies on descriptor values being object equal rather than object |
| 155 | // equivalence. This choice means that a FieldDescriptor generated from a FileDescriptorProto |
| 156 | // will be incompatible with the FieldDescriptor in the global registry and any message created |
| 157 | // from that global registry. |
| 158 | globalFD, err := protoregistryscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoregistry`/.GlobalFilesscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoregistry`/GlobalFiles..FindFileByPathscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoregistry`/Files#FindFileByPath().(fileDesc.Pathscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor#Path().()) |
| 159 | if err == nil { |
| 160 | fileDesc = globalFD |
| 161 | } |
| 162 | var fileExtMap extensionMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/extensionMap# |
| 163 | fd, fileExtMap = newFileDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/newFileDescription().(fileDesc, pbdb) |
| 164 | for _, enumValName := range fd.GetEnumNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#GetEnumNames().() { |
| 165 | pbdb.revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.[enumValName] = fd |
| 166 | } |
| 167 | for _, msgTypeName := range fd.GetTypeNamesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#GetTypeNames().() { |
| 168 | pbdb.revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.[msgTypeName] = fd |
| 169 | } |
| 170 | pbdb.revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.[fd.GetNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#GetName().()] = fd |
| 171 | |
| 172 | // Return the specific file descriptor registered. |
| 173 | pbdb.filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files. = append(pbdb.filesscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#files., fd) |
| 174 | |
| 175 | // Index the protobuf message extensions from the file into the pbdb |
| 176 | for typeName, extMap := range fileExtMap { |
| 177 | typeExtMap, found := pbdb.extensionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#extensions.[typeName] |
| 178 | if !found { |
| 179 | pbdb.extensionsscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#extensions.[typeName] = extMap |
| 180 | continue |
| 181 | } |
| 182 | for extName, field := range extMap { |
| 183 | typeExtMap[extName] = field |
| 184 | } |
| 185 | } |
| 186 | return fd, nil |
| 187 | } |
| 188 | |
| 189 | // RegisterMessage produces a `FileDescription` from a `message` and registers the message and all |
| 190 | // other definitions within the message file into the `pb.Db`. |
| 191 | func (pbdb *Dbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#) RegisterMessagescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#RegisterMessage().(message protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.Messagescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/Message#) (*FileDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#, error) { |
| 192 | msgDesc := message.ProtoReflectscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/ProtoMessage#ProtoReflect().().Descriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Message#Descriptor().() |
| 193 | msgName := msgDesc.FullNamescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Descriptor#FullName().() |
| 194 | typeName := sanitizeProtoNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/sanitizeProtoName().(string(msgName)) |
| 195 | if fd, found := pbdb.revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.[typeName]; found { |
| 196 | return fd, nil |
| 197 | } |
| 198 | return pbdb.RegisterDescriptorscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#RegisterDescriptor().(msgDesc.ParentFilescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Descriptor#ParentFile().()) |
| 199 | } |
| 200 | |
| 201 | // DescribeEnum takes a qualified enum name and returns an `EnumDescription` if it exists in the |
| 202 | // `pb.Db`. |
| 203 | func (pbdb *Dbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#) DescribeEnumscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#DescribeEnum().(enumName string) (*EnumValueDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/EnumValueDescription#, bool) { |
| 204 | enumName = sanitizeProtoNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/sanitizeProtoName().(enumName) |
| 205 | if fd, found := pbdb.revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.[enumName]; found { |
| 206 | return fd.GetEnumDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#GetEnumDescription().(enumName) |
| 207 | } |
| 208 | return nil, false |
| 209 | } |
| 210 | |
| 211 | // DescribeType returns a `TypeDescription` for the `typeName` if it exists in the `pb.Db`. |
| 212 | func (pbdb *Dbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#) DescribeTypescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#DescribeType().(typeName string) (*TypeDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/TypeDescription#, bool) { |
| 213 | typeName = sanitizeProtoNamescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/sanitizeProtoName().(typeName) |
| 214 | if fd, found := pbdb.revFileDescriptorMapscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#revFileDescriptorMap.[typeName]; found { |
| 215 | return fd.GetTypeDescriptionscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/FileDescription#GetTypeDescription().(typeName) |
| 216 | } |
| 217 | return nil, false |
| 218 | } |
| 219 | |
| 220 | // CollectFileDescriptorSet builds a file descriptor set associated with the file where the input |
| 221 | // message is declared. |
| 222 | func CollectFileDescriptorSetscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/CollectFileDescriptorSet().(message protoscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/.Messagescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/proto`/Message#) map[string]protoreflectscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/.FileDescriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor# { |
| 223 | fdMap := map[string]protoreflectscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/.FileDescriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor#{} |
| 224 | parentFile := message.ProtoReflectscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/ProtoMessage#ProtoReflect().().Descriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Message#Descriptor().().ParentFilescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/Descriptor#ParentFile().() |
| 225 | fdMap[parentFile.Pathscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor#Path().()] = parentFile |
| 226 | // Initialize list of dependencies |
| 227 | deps := make([]protoreflectscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/.FileImportscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileImport#, parentFile.Importsscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor#Imports().().Lenscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileImports#Len().()) |
| 228 | for i := 0; i < parentFile.Importsscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor#Imports().().Lenscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileImports#Len().(); i++ { |
| 229 | deps[i] = parentFile.Importsscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor#Imports().().Getscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileImports#Get().(i) |
| 230 | } |
| 231 | // Expand list for new dependencies |
| 232 | for i := 0; i < len(deps); i++ { |
| 233 | dep := deps[i] |
| 234 | if _, found := fdMap[dep.Pathscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor#Path().()]; found { |
| 235 | continue |
| 236 | } |
| 237 | fdMap[dep.Pathscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor#Path().()] = dep.FileDescriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileImport#FileDescriptor. |
| 238 | for j := 0; j < dep.FileDescriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileImport#FileDescriptor..Importsscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor#Imports().().Lenscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileImports#Len().(); j++ { |
| 239 | deps = append(deps, dep.FileDescriptorscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileImport#FileDescriptor..Importsscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileDescriptor#Imports().().Getscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/reflect/protoreflect`/FileImports#Get().(j)) |
| 240 | } |
| 241 | } |
| 242 | return fdMap |
| 243 | } |
| 244 | |
| 245 | func initscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/init().() { |
| 246 | // Describe well-known types to ensure they can always be resolved by the check and interpret |
| 247 | // execution phases. |
| 248 | // |
| 249 | // The following subset of message types is enough to ensure that all well-known types can |
| 250 | // resolved in the runtime, since describing the value results in describing the whole file |
| 251 | // where the message is declared. |
| 252 | DefaultDbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/DefaultDb..RegisterMessagescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#RegisterMessage().(&anypbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/anypb`/.Anyscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/anypb`/Any#{}) |
| 253 | DefaultDbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/DefaultDb..RegisterMessagescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#RegisterMessage().(&durpbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/durationpb`/.Durationscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/durationpb`/Duration#{}) |
| 254 | DefaultDbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/DefaultDb..RegisterMessagescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#RegisterMessage().(&emptypbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/emptypb`/.Emptyscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/emptypb`/Empty#{}) |
| 255 | DefaultDbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/DefaultDb..RegisterMessagescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#RegisterMessage().(&tspbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/timestamppb`/.Timestampscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/timestamppb`/Timestamp#{}) |
| 256 | DefaultDbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/DefaultDb..RegisterMessagescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#RegisterMessage().(&structpbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/structpb`/.Valuescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/structpb`/Value#{}) |
| 257 | DefaultDbscip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/DefaultDb..RegisterMessagescip-go gomod github.com/google/cel-go . `github.com/google/cel-go/common/types/pb`/Db#RegisterMessage().(&wrapperspbscip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/wrapperspb`/.BoolValuescip-go gomod google.golang.org/protobuf v1.36.10 `google.golang.org/protobuf/types/known/wrapperspb`/BoolValue#{}) |
| 258 | } |