|
22 | 22 | #include <utility> |
23 | 23 |
|
24 | 24 | #include "absl/base/nullability.h" |
25 | | -#include "absl/base/optimization.h" |
26 | 25 | #include "absl/log/absl_check.h" |
27 | 26 | #include "absl/status/status.h" |
28 | 27 | #include "absl/strings/str_cat.h" |
@@ -218,21 +217,33 @@ class LegacyParsedMapFieldMapValue final |
218 | 217 | if (arena == nullptr) { |
219 | 218 | arena = arena_; |
220 | 219 | } |
221 | | - if (auto status = |
222 | | - google::api::expr::runtime::CelValue::CheckMapKeyType(key); |
223 | | - !status.ok()) { |
224 | | - status.IgnoreError(); |
225 | | - return std::nullopt; |
226 | | - } |
227 | 220 | Value modern_key; |
228 | | - if (ABSL_PREDICT_FALSE(!ModernValue(arena, key, modern_key).ok())) { |
| 221 | + if (!ModernValue(arena, key, modern_key).ok()) { |
| 222 | + // Legacy to modern should succeed for a valid CelValue. |
229 | 223 | return std::nullopt; |
230 | 224 | } |
231 | 225 | Value modern_val; |
232 | | - auto status_or_found = |
233 | | - Find(modern_key, google::protobuf::DescriptorPool::generated_pool(), |
234 | | - google::protobuf::MessageFactory::generated_factory(), arena, &modern_val); |
235 | | - if (!status_or_found.ok() || !*status_or_found) { |
| 226 | + // Call custom map Find directly. MapValue normally handles wrapping |
| 227 | + // non-ok result to error value types, so emulate that here. |
| 228 | + // |
| 229 | + // Use the descriptor pool and message factory from the value. This is not |
| 230 | + // totally consistent with modern APIs, but this should behave the same as |
| 231 | + // the legacy map did. |
| 232 | + const google::protobuf::Message* msg = value_.message_; |
| 233 | + ABSL_DCHECK(msg->GetDescriptor() != nullptr); |
| 234 | + ABSL_DCHECK(msg->GetReflection() != nullptr); |
| 235 | + |
| 236 | + const google::protobuf::DescriptorPool* descriptor_pool = |
| 237 | + msg->GetDescriptor()->file()->pool(); |
| 238 | + google::protobuf::MessageFactory* message_factory = |
| 239 | + msg->GetReflection()->GetMessageFactory(); |
| 240 | + auto found = |
| 241 | + Find(modern_key, descriptor_pool, message_factory, arena, &modern_val); |
| 242 | + if (!found.ok()) { |
| 243 | + return google::api::expr::runtime::CreateErrorValue(arena, |
| 244 | + found.status()); |
| 245 | + } |
| 246 | + if (!(*found) && !modern_val.IsError()) { |
236 | 247 | return std::nullopt; |
237 | 248 | } |
238 | 249 | return UnsafeLegacyValue(modern_val, /*stable=*/false, arena); |
@@ -401,21 +412,25 @@ class LegacyParsedJsonMapValue final |
401 | 412 | if (arena == nullptr) { |
402 | 413 | arena = arena_; |
403 | 414 | } |
404 | | - if (auto status = |
405 | | - google::api::expr::runtime::CelValue::CheckMapKeyType(key); |
406 | | - !status.ok()) { |
407 | | - status.IgnoreError(); |
408 | | - return std::nullopt; |
409 | | - } |
410 | 415 | Value modern_key; |
411 | | - if (ABSL_PREDICT_FALSE(!ModernValue(arena, key, modern_key).ok())) { |
| 416 | + if (!ModernValue(arena, key, modern_key).ok()) { |
| 417 | + // Legacy to modern should succeed for a valid CelValue. |
412 | 418 | return std::nullopt; |
413 | 419 | } |
414 | 420 | Value modern_val; |
415 | | - auto status_or_found = value_.Find( |
416 | | - modern_key, google::protobuf::DescriptorPool::generated_pool(), |
417 | | - google::protobuf::MessageFactory::generated_factory(), arena, &modern_val); |
418 | | - if (!status_or_found.ok() || !*status_or_found) { |
| 421 | + // Call custom map Find directly. MapValue normally handles wrapping |
| 422 | + // non-ok result to error value types, so emulate that here. |
| 423 | + // |
| 424 | + // We know that the descriptor pool and message factory aren't needed here, |
| 425 | + // so fine to use generated. |
| 426 | + auto found = |
| 427 | + Find(modern_key, google::protobuf::DescriptorPool::generated_pool(), |
| 428 | + google::protobuf::MessageFactory::generated_factory(), arena, &modern_val); |
| 429 | + if (!found.ok()) { |
| 430 | + return google::api::expr::runtime::CreateErrorValue(arena, |
| 431 | + found.status()); |
| 432 | + } |
| 433 | + if (!(*found) && !modern_val.IsError()) { |
419 | 434 | return std::nullopt; |
420 | 435 | } |
421 | 436 | return UnsafeLegacyValue(modern_val, /*stable=*/false, arena); |
|
0 commit comments