| 169 | } |
| 170 | |
| 171 | absl::StatusOr<bool> FieldBackedMapImpl::LookupMapValue( |
| 172 | const CelValue& key, MapValueConstRef* value_ref) const { |
| 173 | if (!MatchesMapKeyType(key_desc_, key)) { |
| 174 | return InvalidMapKeyType(key_desc_->cpp_type_name()); |
| 175 | } |
| 176 | |
| 177 | std::string map_key_string; |
| 178 | google::protobuf::MapKey proto_key; |
| 179 | switch (key_desc_->cpp_type()) { |
| 180 | case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: { |
| 181 | bool key_value; |
| 182 | key.GetValue(&key_value); |
| 183 | proto_key.SetBoolValue(key_value); |
| 184 | } break; |
| 185 | case google::protobuf::FieldDescriptor::CPPTYPE_INT32: { |
| 186 | int64_t key_value; |
| 187 | key.GetValue(&key_value); |
| 188 | if (key_value > std::numeric_limits<int32_t>::max() || |
| 189 | key_value < std::numeric_limits<int32_t>::lowest()) { |
| 190 | return absl::OutOfRangeError("integer overflow"); |
| 191 | } |
| 192 | proto_key.SetInt32Value(key_value); |
| 193 | } break; |
| 194 | case google::protobuf::FieldDescriptor::CPPTYPE_INT64: { |
| 195 | int64_t key_value; |
| 196 | key.GetValue(&key_value); |
| 197 | proto_key.SetInt64Value(key_value); |
| 198 | } break; |
| 199 | case google::protobuf::FieldDescriptor::CPPTYPE_STRING: { |
| 200 | CelValue::StringHolder key_value; |
| 201 | key.GetValue(&key_value); |
| 202 | map_key_string.assign(key_value.value().data(), key_value.value().size()); |
| 203 | proto_key.SetStringValue(map_key_string); |
| 204 | } break; |
| 205 | case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: { |
| 206 | uint64_t key_value; |
| 207 | key.GetValue(&key_value); |
| 208 | if (key_value > std::numeric_limits<uint32_t>::max()) { |
| 209 | return absl::OutOfRangeError("unsigned integer overlow"); |
| 210 | } |
| 211 | proto_key.SetUInt32Value(key_value); |
| 212 | } break; |
| 213 | case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: { |
| 214 | uint64_t key_value; |
| 215 | key.GetValue(&key_value); |
| 216 | proto_key.SetUInt64Value(key_value); |
| 217 | } break; |
| 218 | default: |
| 219 | return InvalidMapKeyType(key_desc_->cpp_type_name()); |
| 220 | } |
| 221 | // Look the value up |
| 222 | return cel::extensions::protobuf_internal::LookupMapValue( |
| 223 | *reflection_, *message_, *descriptor_, proto_key, value_ref); |
| 224 | } |
| 225 | |
| 226 | absl::StatusOr<bool> FieldBackedMapImpl::LegacyHasMapValue( |
| 227 | const CelValue& key) const { |
nothing calls this directly
no test coverage detected