/proc/self/cwd/extensions/protobuf/internal/map_reflection.cc
Line | Count | Source |
1 | | // Copyright 2022 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 "extensions/protobuf/internal/map_reflection.h" |
16 | | |
17 | | #include "absl/base/nullability.h" |
18 | | #include "google/protobuf/descriptor.h" |
19 | | #include "google/protobuf/map_field.h" |
20 | | #include "google/protobuf/message.h" |
21 | | |
22 | | namespace google::protobuf::expr { |
23 | | |
24 | | class CelMapReflectionFriend final { |
25 | | public: |
26 | | static bool LookupMapValue(const Reflection& reflection, |
27 | | const Message& message, |
28 | | const FieldDescriptor& field, const MapKey& key, |
29 | 0 | MapValueConstRef* value) { |
30 | 0 | return reflection.LookupMapValue(message, &field, key, value); |
31 | 0 | } |
32 | | |
33 | | static bool ContainsMapKey(const Reflection& reflection, |
34 | | const Message& message, |
35 | 0 | const FieldDescriptor& field, const MapKey& key) { |
36 | 0 | return reflection.ContainsMapKey(message, &field, key); |
37 | 0 | } |
38 | | |
39 | | static int MapSize(const google::protobuf::Reflection& reflection, |
40 | | const google::protobuf::Message& message, |
41 | 0 | const google::protobuf::FieldDescriptor& field) { |
42 | 0 | return reflection.MapSize(message, &field); |
43 | 0 | } |
44 | | |
45 | | static google::protobuf::ConstMapIterator ConstMapBegin( |
46 | | const google::protobuf::Reflection& reflection, const google::protobuf::Message& message, |
47 | 0 | const google::protobuf::FieldDescriptor& field) { |
48 | 0 | return reflection.ConstMapBegin(&message, &field); |
49 | 0 | } |
50 | | |
51 | | static google::protobuf::ConstMapIterator ConstMapEnd( |
52 | | const google::protobuf::Reflection& reflection, const google::protobuf::Message& message, |
53 | 0 | const google::protobuf::FieldDescriptor& field) { |
54 | 0 | return reflection.ConstMapEnd(&message, &field); |
55 | 0 | } |
56 | | |
57 | | static bool InsertOrLookupMapValue(const google::protobuf::Reflection& reflection, |
58 | | google::protobuf::Message* message, |
59 | | const google::protobuf::FieldDescriptor& field, |
60 | | const google::protobuf::MapKey& key, |
61 | 0 | google::protobuf::MapValueRef* value) { |
62 | 0 | return reflection.InsertOrLookupMapValue(message, &field, key, value); |
63 | 0 | } |
64 | | |
65 | | static bool DeleteMapValue(const google::protobuf::Reflection* absl_nonnull reflection, |
66 | | google::protobuf::Message* absl_nonnull message, |
67 | | const google::protobuf::FieldDescriptor* absl_nonnull field, |
68 | 0 | const google::protobuf::MapKey& key) { |
69 | 0 | return reflection->DeleteMapValue(message, field, key); |
70 | 0 | } |
71 | | }; |
72 | | |
73 | | } // namespace google::protobuf::expr |
74 | | |
75 | | namespace cel::extensions::protobuf_internal { |
76 | | |
77 | | bool LookupMapValue(const google::protobuf::Reflection& reflection, |
78 | | const google::protobuf::Message& message, |
79 | | const google::protobuf::FieldDescriptor& field, |
80 | | const google::protobuf::MapKey& key, |
81 | 0 | google::protobuf::MapValueConstRef* value) { |
82 | 0 | return google::protobuf::expr::CelMapReflectionFriend::LookupMapValue( |
83 | 0 | reflection, message, field, key, value); |
84 | 0 | } |
85 | | |
86 | | bool ContainsMapKey(const google::protobuf::Reflection& reflection, |
87 | | const google::protobuf::Message& message, |
88 | | const google::protobuf::FieldDescriptor& field, |
89 | 0 | const google::protobuf::MapKey& key) { |
90 | 0 | return google::protobuf::expr::CelMapReflectionFriend::ContainsMapKey( |
91 | 0 | reflection, message, field, key); |
92 | 0 | } |
93 | | |
94 | | int MapSize(const google::protobuf::Reflection& reflection, |
95 | | const google::protobuf::Message& message, |
96 | 0 | const google::protobuf::FieldDescriptor& field) { |
97 | 0 | return google::protobuf::expr::CelMapReflectionFriend::MapSize(reflection, message, |
98 | 0 | field); |
99 | 0 | } |
100 | | |
101 | | google::protobuf::ConstMapIterator ConstMapBegin(const google::protobuf::Reflection& reflection, |
102 | | const google::protobuf::Message& message, |
103 | 0 | const google::protobuf::FieldDescriptor& field) { |
104 | 0 | return google::protobuf::expr::CelMapReflectionFriend::ConstMapBegin(reflection, |
105 | 0 | message, field); |
106 | 0 | } |
107 | | |
108 | | google::protobuf::ConstMapIterator ConstMapEnd(const google::protobuf::Reflection& reflection, |
109 | | const google::protobuf::Message& message, |
110 | 0 | const google::protobuf::FieldDescriptor& field) { |
111 | 0 | return google::protobuf::expr::CelMapReflectionFriend::ConstMapEnd(reflection, message, |
112 | 0 | field); |
113 | 0 | } |
114 | | |
115 | | bool InsertOrLookupMapValue(const google::protobuf::Reflection& reflection, |
116 | | google::protobuf::Message* message, |
117 | | const google::protobuf::FieldDescriptor& field, |
118 | | const google::protobuf::MapKey& key, |
119 | 0 | google::protobuf::MapValueRef* value) { |
120 | 0 | return google::protobuf::expr::CelMapReflectionFriend::InsertOrLookupMapValue( |
121 | 0 | reflection, message, field, key, value); |
122 | 0 | } |
123 | | |
124 | | bool DeleteMapValue(const google::protobuf::Reflection* absl_nonnull reflection, |
125 | | google::protobuf::Message* absl_nonnull message, |
126 | | const google::protobuf::FieldDescriptor* absl_nonnull field, |
127 | 0 | const google::protobuf::MapKey& key) { |
128 | 0 | return google::protobuf::expr::CelMapReflectionFriend::DeleteMapValue( |
129 | 0 | reflection, message, field, key); |
130 | 0 | } |
131 | | |
132 | | } // namespace cel::extensions::protobuf_internal |