/proc/self/cwd/extensions/protobuf/internal/qualify.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_EXTENSIONS_PROTOBUF_INTERNAL_QUALIFY_H_ |
16 | | #define THIRD_PARTY_CEL_CPP_EXTENSIONS_PROTOBUF_INTERNAL_QUALIFY_H_ |
17 | | |
18 | | #include "absl/base/nullability.h" |
19 | | #include "absl/status/status.h" |
20 | | #include "absl/status/statusor.h" |
21 | | #include "base/attribute.h" |
22 | | #include "common/memory.h" |
23 | | #include "runtime/runtime_options.h" |
24 | | #include "google/protobuf/descriptor.h" |
25 | | #include "google/protobuf/map_field.h" |
26 | | #include "google/protobuf/message.h" |
27 | | #include "google/protobuf/reflection.h" |
28 | | |
29 | | namespace cel::extensions::protobuf_internal { |
30 | | |
31 | | class ProtoQualifyState { |
32 | | public: |
33 | | ProtoQualifyState(const google::protobuf::Message* absl_nonnull message, |
34 | | const google::protobuf::Descriptor* absl_nonnull descriptor, |
35 | | const google::protobuf::Reflection* absl_nonnull reflection) |
36 | 0 | : message_(message), |
37 | 0 | descriptor_(descriptor), |
38 | 0 | reflection_(reflection), |
39 | 0 | repeated_field_desc_(nullptr) {} |
40 | | |
41 | 0 | virtual ~ProtoQualifyState() = default; |
42 | | |
43 | | ProtoQualifyState(const ProtoQualifyState&) = delete; |
44 | | ProtoQualifyState& operator=(const ProtoQualifyState&) = delete; |
45 | | |
46 | | absl::Status ApplySelectQualifier(const cel::SelectQualifier& qualifier, |
47 | | MemoryManagerRef memory_manager); |
48 | | |
49 | | absl::Status ApplyLastQualifierHas(const cel::SelectQualifier& qualifier, |
50 | | MemoryManagerRef memory_manager); |
51 | | |
52 | | absl::Status ApplyLastQualifierGet(const cel::SelectQualifier& qualifier, |
53 | | MemoryManagerRef memory_manager); |
54 | | |
55 | | private: |
56 | | virtual void SetResultFromError(absl::Status status, |
57 | | MemoryManagerRef memory_manager) = 0; |
58 | | |
59 | | virtual void SetResultFromBool(bool value) = 0; |
60 | | |
61 | | virtual absl::Status SetResultFromField( |
62 | | const google::protobuf::Message* message, const google::protobuf::FieldDescriptor* field, |
63 | | ProtoWrapperTypeOptions unboxing_option, |
64 | | MemoryManagerRef memory_manager) = 0; |
65 | | |
66 | | virtual absl::Status SetResultFromRepeatedField( |
67 | | const google::protobuf::Message* message, const google::protobuf::FieldDescriptor* field, |
68 | | int index, MemoryManagerRef memory_manager) = 0; |
69 | | |
70 | | virtual absl::Status SetResultFromMapField( |
71 | | const google::protobuf::Message* message, const google::protobuf::FieldDescriptor* field, |
72 | | const google::protobuf::MapValueConstRef& value, |
73 | | MemoryManagerRef memory_manager) = 0; |
74 | | |
75 | | absl::Status ApplyFieldSpecifier(const cel::FieldSpecifier& field_specifier, |
76 | | MemoryManagerRef memory_manager); |
77 | | |
78 | | absl::StatusOr<int> CheckListIndex( |
79 | | const cel::AttributeQualifier& qualifier) const; |
80 | | |
81 | | absl::Status ApplyAttributeQualifierList( |
82 | | const cel::AttributeQualifier& qualifier, |
83 | | MemoryManagerRef memory_manager); |
84 | | |
85 | | absl::StatusOr<google::protobuf::MapValueConstRef> CheckMapIndex( |
86 | | const cel::AttributeQualifier& qualifier) const; |
87 | | |
88 | | absl::Status ApplyAttributeQualifierMap( |
89 | | const cel::AttributeQualifier& qualifier, |
90 | | MemoryManagerRef memory_manager); |
91 | | |
92 | | absl::Status ApplyAttributeQualifer(const cel::AttributeQualifier& qualifier, |
93 | | MemoryManagerRef memory_manager); |
94 | | |
95 | | absl::Status MapHas(const cel::AttributeQualifier& key, |
96 | | MemoryManagerRef memory_manager); |
97 | | |
98 | | absl::Status ApplyLastQualifierMessageGet( |
99 | | const cel::FieldSpecifier& specifier, MemoryManagerRef memory_manager); |
100 | | |
101 | | absl::Status ApplyLastQualifierGetList( |
102 | | const cel::AttributeQualifier& qualifier, |
103 | | MemoryManagerRef memory_manager); |
104 | | |
105 | | absl::Status ApplyLastQualifierGetMap( |
106 | | const cel::AttributeQualifier& qualifier, |
107 | | MemoryManagerRef memory_manager); |
108 | | |
109 | | const google::protobuf::Message* absl_nonnull message_; |
110 | | const google::protobuf::Descriptor* absl_nonnull descriptor_; |
111 | | const google::protobuf::Reflection* absl_nonnull reflection_; |
112 | | const google::protobuf::FieldDescriptor* absl_nullable repeated_field_desc_; |
113 | | }; |
114 | | |
115 | | } // namespace cel::extensions::protobuf_internal |
116 | | |
117 | | #endif // THIRD_PARTY_CEL_CPP_EXTENSIONS_PROTOBUF_INTERNAL_QUALIFY_H_ |