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_struct_value.h
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
// IWYU pragma: private, include "common/value.h"
16
// IWYU pragma: friend "common/value.h"
17
18
#ifndef THIRD_PARTY_CEL_CPP_COMMON_VALUES_LEGACY_STRUCT_VALUE_H_
19
#define THIRD_PARTY_CEL_CPP_COMMON_VALUES_LEGACY_STRUCT_VALUE_H_
20
21
#include <cstdint>
22
#include <ostream>
23
#include <string>
24
#include <utility>
25
26
#include "absl/base/nullability.h"
27
#include "absl/status/status.h"
28
#include "absl/status/statusor.h"
29
#include "absl/strings/cord.h"
30
#include "absl/strings/string_view.h"
31
#include "absl/types/optional.h"
32
#include "absl/types/span.h"
33
#include "base/attribute.h"
34
#include "common/type.h"
35
#include "common/value_kind.h"
36
#include "common/values/custom_struct_value.h"
37
#include "common/values/values.h"
38
#include "runtime/runtime_options.h"
39
#include "google/protobuf/arena.h"
40
#include "google/protobuf/descriptor.h"
41
#include "google/protobuf/io/zero_copy_stream.h"
42
#include "google/protobuf/message.h"
43
44
namespace google::api::expr::runtime {
45
class LegacyTypeInfoApis;
46
}
47
48
namespace cel {
49
50
class Value;
51
52
namespace common_internal {
53
54
class LegacyStructValue;
55
56
// `LegacyStructValue` is a wrapper around the old representation of protocol
57
// buffer messages in `google::api::expr::runtime::CelValue`. It only supports
58
// arena allocation.
59
class LegacyStructValue final
60
    : private common_internal::StructValueMixin<LegacyStructValue> {
61
 public:
62
  static constexpr ValueKind kKind = ValueKind::kStruct;
63
64
  LegacyStructValue() = default;
65
66
  LegacyStructValue(
67
      const google::protobuf::Message* absl_nullability_unknown message_ptr,
68
      const google::api::expr::runtime::
69
          LegacyTypeInfoApis* absl_nullability_unknown legacy_type_info)
70
289
      : message_ptr_(message_ptr), legacy_type_info_(legacy_type_info) {}
71
72
  LegacyStructValue(const LegacyStructValue&) = default;
73
  LegacyStructValue& operator=(const LegacyStructValue&) = default;
74
75
0
  constexpr ValueKind kind() const { return kKind; }
76
77
  StructType GetRuntimeType() const;
78
79
  absl::string_view GetTypeName() const;
80
81
  std::string DebugString() const;
82
83
  // See Value::SerializeTo().
84
  absl::Status SerializeTo(
85
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
86
      google::protobuf::MessageFactory* absl_nonnull message_factory,
87
      google::protobuf::io::ZeroCopyOutputStream* absl_nonnull output) const;
88
89
  // See Value::ConvertToJson().
90
  absl::Status ConvertToJson(
91
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
92
      google::protobuf::MessageFactory* absl_nonnull message_factory,
93
      google::protobuf::Message* absl_nonnull json) const;
94
95
  // See Value::ConvertToJsonObject().
96
  absl::Status ConvertToJsonObject(
97
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
98
      google::protobuf::MessageFactory* absl_nonnull message_factory,
99
      google::protobuf::Message* absl_nonnull json) const;
100
101
  absl::Status Equal(const Value& other,
102
                     const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
103
                     google::protobuf::MessageFactory* absl_nonnull message_factory,
104
                     google::protobuf::Arena* absl_nonnull arena,
105
                     Value* absl_nonnull result) const;
106
  using StructValueMixin::Equal;
107
108
  bool IsZeroValue() const;
109
110
  absl::Status GetFieldByName(
111
      absl::string_view name, ProtoWrapperTypeOptions unboxing_options,
112
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
113
      google::protobuf::MessageFactory* absl_nonnull message_factory,
114
      google::protobuf::Arena* absl_nonnull arena, Value* absl_nonnull result) const;
115
  using StructValueMixin::GetFieldByName;
116
117
  absl::Status GetFieldByNumber(
118
      int64_t number, ProtoWrapperTypeOptions unboxing_options,
119
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
120
      google::protobuf::MessageFactory* absl_nonnull message_factory,
121
      google::protobuf::Arena* absl_nonnull arena, Value* absl_nonnull result) const;
122
  using StructValueMixin::GetFieldByNumber;
123
124
  absl::StatusOr<bool> HasFieldByName(absl::string_view name) const;
125
126
  absl::StatusOr<bool> HasFieldByNumber(int64_t number) const;
127
128
  using ForEachFieldCallback = CustomStructValueInterface::ForEachFieldCallback;
129
130
  absl::Status ForEachField(
131
      ForEachFieldCallback callback,
132
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
133
      google::protobuf::MessageFactory* absl_nonnull message_factory,
134
      google::protobuf::Arena* absl_nonnull arena) const;
135
136
  absl::Status Qualify(
137
      absl::Span<const SelectQualifier> qualifiers, bool presence_test,
138
      const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,
139
      google::protobuf::MessageFactory* absl_nonnull message_factory,
140
      google::protobuf::Arena* absl_nonnull arena, Value* absl_nonnull result,
141
      int* absl_nonnull count) const;
142
  using StructValueMixin::Qualify;
143
144
1
  const google::protobuf::Message* absl_nullability_unknown message_ptr() const {
145
1
    return message_ptr_;
146
1
  }
147
148
  const google::api::expr::runtime::LegacyTypeInfoApis* absl_nullability_unknown
149
1
  legacy_type_info() const {
150
1
    return legacy_type_info_;
151
1
  }
152
153
0
  friend void swap(LegacyStructValue& lhs, LegacyStructValue& rhs) noexcept {
154
0
    using std::swap;
155
0
    swap(lhs.message_ptr_, rhs.message_ptr_);
156
0
    swap(lhs.legacy_type_info_, rhs.legacy_type_info_);
157
0
  }
158
159
 private:
160
  friend class common_internal::ValueMixin<LegacyStructValue>;
161
  friend class common_internal::StructValueMixin<LegacyStructValue>;
162
163
  const google::protobuf::Message* absl_nullability_unknown message_ptr_ = nullptr;
164
  const google::api::expr::runtime::LegacyTypeInfoApis* absl_nullability_unknown
165
  legacy_type_info_ = nullptr;
166
};
167
168
inline std::ostream& operator<<(std::ostream& out,
169
0
                                const LegacyStructValue& value) {
170
0
  return out << value.DebugString();
171
0
}
172
173
bool IsLegacyStructValue(const Value& value);
174
175
LegacyStructValue GetLegacyStructValue(const Value& value);
176
177
absl::optional<LegacyStructValue> AsLegacyStructValue(const Value& value);
178
179
}  // namespace common_internal
180
181
}  // namespace cel
182
183
#endif  // THIRD_PARTY_CEL_CPP_COMMON_VALUES_LEGACY_STRUCT_VALUE_H_