Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/common/values/legacy_map_value.cc
Line
Count
Source
1
// Copyright 2023 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
//     https://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
#include "common/values/legacy_map_value.h"
16
17
#include "absl/base/nullability.h"
18
#include "absl/log/absl_check.h"
19
#include "absl/status/status.h"
20
#include "absl/types/optional.h"
21
#include "common/native_type.h"
22
#include "common/value.h"
23
#include "common/values/map_value_builder.h"
24
#include "common/values/values.h"
25
#include "eval/public/cel_value.h"
26
#include "internal/casts.h"
27
#include "google/protobuf/arena.h"
28
#include "google/protobuf/descriptor.h"
29
#include "google/protobuf/message.h"
30
31
namespace cel::common_internal {
32
33
absl::Status LegacyMapValue::Equal(
34
    const Value& other,
35
    const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
36
    google::protobuf::MessageFactory* absl_nonnull message_factory,
37
0
    google::protobuf::Arena* absl_nonnull arena, Value* absl_nonnull result) const {
38
0
  if (auto map_value = other.AsMap(); map_value.has_value()) {
39
0
    return MapValueEqual(*this, *map_value, descriptor_pool, message_factory,
40
0
                         arena, result);
41
0
  }
42
0
  *result = FalseValue();
43
0
  return absl::OkStatus();
44
0
}
45
46
44
bool IsLegacyMapValue(const Value& value) {
47
44
  return value.variant_.Is<LegacyMapValue>();
48
44
}
49
50
1
LegacyMapValue GetLegacyMapValue(const Value& value) {
51
1
  ABSL_DCHECK(IsLegacyMapValue(value));
52
1
  return value.variant_.Get<LegacyMapValue>();
53
1
}
54
55
44
absl::optional<LegacyMapValue> AsLegacyMapValue(const Value& value) {
56
44
  if (IsLegacyMapValue(value)) {
57
1
    return GetLegacyMapValue(value);
58
1
  }
59
43
  if (auto custom_map_value = value.AsCustomMap(); custom_map_value) {
60
43
    NativeTypeId native_type_id = NativeTypeId::Of(*custom_map_value);
61
43
    if (native_type_id == NativeTypeId::For<CompatMapValue>()) {
62
43
      return LegacyMapValue(
63
43
          static_cast<const google::api::expr::runtime::CelMap*>(
64
43
              cel::internal::down_cast<const CompatMapValue*>(
65
43
                  custom_map_value->interface())));
66
43
    } else if (native_type_id == NativeTypeId::For<MutableCompatMapValue>()) {
67
0
      return LegacyMapValue(
68
0
          static_cast<const google::api::expr::runtime::CelMap*>(
69
0
              cel::internal::down_cast<const MutableCompatMapValue*>(
70
0
                  custom_map_value->interface())));
71
0
    }
72
43
  }
73
0
  return absl::nullopt;
74
43
}
75
76
}  // namespace cel::common_internal