Coverage Report

Created: 2026-05-27 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/common/legacy_value.h
Line
Count
Source
1
// Copyright 2024 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
#ifndef THIRD_PARTY_CEL_CPP_COMMON_LEGACY_VALUE_H_
16
#define THIRD_PARTY_CEL_CPP_COMMON_LEGACY_VALUE_H_
17
18
#include <cstdint>
19
#include <vector>
20
21
#include "absl/base/nullability.h"
22
#include "absl/status/status.h"
23
#include "absl/status/statusor.h"
24
#include "absl/strings/string_view.h"
25
#include "absl/time/time.h"
26
#include "absl/types/span.h"
27
#include "common/value.h"
28
#include "eval/public/cel_value.h"
29
#include "internal/status_macros.h"
30
#include "google/protobuf/arena.h"
31
32
namespace cel {
33
34
absl::Status ModernValue(google::protobuf::Arena* arena,
35
                         google::api::expr::runtime::CelValue legacy_value,
36
                         Value& result);
37
inline absl::StatusOr<Value> ModernValue(
38
1.65k
    google::protobuf::Arena* arena, google::api::expr::runtime::CelValue legacy_value) {
39
1.65k
  Value result;
40
1.65k
  CEL_RETURN_IF_ERROR(ModernValue(arena, legacy_value, result));
41
1.65k
  return result;
42
1.65k
}
43
44
absl::StatusOr<google::api::expr::runtime::CelValue> LegacyValue(
45
    google::protobuf::Arena* arena, const Value& modern_value);
46
47
namespace common_internal {
48
49
// Convert a `cel::Value` to `google::api::expr::runtime::CelValue`, using
50
// `arena` to make memory allocations if necessary. `stable` indicates whether
51
// `cel::Value` is in a location where it will not be moved, so that inline
52
// string/bytes storage can be referenced.
53
google::api::expr::runtime::CelValue UnsafeLegacyValue(
54
    const Value& value, bool stable, google::protobuf::Arena* absl_nonnull arena);
55
56
}  // namespace common_internal
57
58
}  // namespace cel
59
60
namespace cel::interop_internal {
61
62
absl::StatusOr<Value> FromLegacyValue(
63
    google::protobuf::Arena* arena,
64
    const google::api::expr::runtime::CelValue& legacy_value,
65
    bool unchecked = false);
66
67
absl::StatusOr<google::api::expr::runtime::CelValue> ToLegacyValue(
68
    google::protobuf::Arena* arena, const Value& value, bool unchecked = false);
69
70
0
inline NullValue CreateNullValue() { return NullValue{}; }
71
72
0
inline BoolValue CreateBoolValue(bool value) { return BoolValue{value}; }
73
74
0
inline IntValue CreateIntValue(int64_t value) { return IntValue{value}; }
75
76
0
inline UintValue CreateUintValue(uint64_t value) { return UintValue{value}; }
77
78
0
inline DoubleValue CreateDoubleValue(double value) {
79
0
  return DoubleValue{value};
80
0
}
81
82
inline ListValue CreateLegacyListValue(
83
0
    const google::api::expr::runtime::CelList* value) {
84
0
  return common_internal::LegacyListValue(value);
85
0
}
86
87
inline MapValue CreateLegacyMapValue(
88
0
    const google::api::expr::runtime::CelMap* value) {
89
0
  return common_internal::LegacyMapValue(value);
90
0
}
91
92
0
inline Value CreateDurationValue(absl::Duration value, bool unchecked = false) {
93
0
  return DurationValue{value};
94
0
}
95
96
0
inline TimestampValue CreateTimestampValue(absl::Time value) {
97
0
  return TimestampValue{value};
98
0
}
99
100
Value LegacyValueToModernValueOrDie(
101
    google::protobuf::Arena* arena, const google::api::expr::runtime::CelValue& value,
102
    bool unchecked = false);
103
std::vector<Value> LegacyValueToModernValueOrDie(
104
    google::protobuf::Arena* arena,
105
    absl::Span<const google::api::expr::runtime::CelValue> values,
106
    bool unchecked = false);
107
108
google::api::expr::runtime::CelValue ModernValueToLegacyValueOrDie(
109
    google::protobuf::Arena* arena, const Value& value, bool unchecked = false);
110
111
TypeValue CreateTypeValueFromView(google::protobuf::Arena* arena,
112
                                  absl::string_view input);
113
114
}  // namespace cel::interop_internal
115
116
#endif  // THIRD_PARTY_CEL_CPP_COMMON_LEGACY_VALUE_H_