@@ -109,11 +109,53 @@ class CelListIterator final : public ValueIterator {
109109 " ValueIterator::Next() called when ValueIterator::HasNext() returns "
110110 " false" );
111111 }
112- auto cel_value = cel_list_->Get (arena, index_++ );
112+ auto cel_value = cel_list_->Get (arena, index_);
113113 CEL_RETURN_IF_ERROR (ModernValue (arena, cel_value, *result));
114+ ++index_;
114115 return absl::OkStatus ();
115116 }
116117
118+ absl::StatusOr<bool > Next1 (
119+ absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool,
120+ absl::Nonnull<google::protobuf::MessageFactory*> message_factory,
121+ absl::Nonnull<google::protobuf::Arena*> arena,
122+ absl::Nonnull<Value*> key_or_value) override {
123+ ABSL_DCHECK (descriptor_pool != nullptr );
124+ ABSL_DCHECK (message_factory != nullptr );
125+ ABSL_DCHECK (arena != nullptr );
126+ ABSL_DCHECK (key_or_value != nullptr );
127+
128+ if (index_ >= size_) {
129+ return false ;
130+ }
131+ auto cel_value = cel_list_->Get (arena, index_);
132+ CEL_RETURN_IF_ERROR (ModernValue (arena, cel_value, *key_or_value));
133+ ++index_;
134+ return true ;
135+ }
136+
137+ absl::StatusOr<bool > Next2 (
138+ absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool,
139+ absl::Nonnull<google::protobuf::MessageFactory*> message_factory,
140+ absl::Nonnull<google::protobuf::Arena*> arena, absl::Nonnull<Value*> key,
141+ absl::Nullable<Value*> value) override {
142+ ABSL_DCHECK (descriptor_pool != nullptr );
143+ ABSL_DCHECK (message_factory != nullptr );
144+ ABSL_DCHECK (arena != nullptr );
145+ ABSL_DCHECK (key != nullptr );
146+
147+ if (index_ >= size_) {
148+ return false ;
149+ }
150+ if (value != nullptr ) {
151+ auto cel_value = cel_list_->Get (arena, index_);
152+ CEL_RETURN_IF_ERROR (ModernValue (arena, cel_value, *value));
153+ }
154+ *key = IntValue (index_);
155+ ++index_;
156+ return true ;
157+ }
158+
117159 private:
118160 const CelList* const cel_list_;
119161 const int size_;
@@ -137,18 +179,67 @@ class CelMapIterator final : public ValueIterator {
137179 " ValueIterator::Next() called when ValueIterator::HasNext() returns "
138180 " false" );
139181 }
140- ProjectKeys (arena);
141- CEL_RETURN_IF_ERROR (cel_list_.status ());
142- auto cel_value = (*cel_list_)->Get (arena, index_++);
182+ CEL_RETURN_IF_ERROR (ProjectKeys (arena));
183+ auto cel_value = (*cel_list_)->Get (arena, index_);
143184 CEL_RETURN_IF_ERROR (ModernValue (arena, cel_value, *result));
185+ ++index_;
144186 return absl::OkStatus ();
145187 }
146188
189+ absl::StatusOr<bool > Next1 (
190+ absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool,
191+ absl::Nonnull<google::protobuf::MessageFactory*> message_factory,
192+ absl::Nonnull<google::protobuf::Arena*> arena,
193+ absl::Nonnull<Value*> key_or_value) override {
194+ ABSL_DCHECK (descriptor_pool != nullptr );
195+ ABSL_DCHECK (message_factory != nullptr );
196+ ABSL_DCHECK (arena != nullptr );
197+ ABSL_DCHECK (key_or_value != nullptr );
198+
199+ if (index_ >= size_) {
200+ return false ;
201+ }
202+ CEL_RETURN_IF_ERROR (ProjectKeys (arena));
203+ auto cel_value = (*cel_list_)->Get (arena, index_);
204+ CEL_RETURN_IF_ERROR (ModernValue (arena, cel_value, *key_or_value));
205+ ++index_;
206+ return true ;
207+ }
208+
209+ absl::StatusOr<bool > Next2 (
210+ absl::Nonnull<const google::protobuf::DescriptorPool*> descriptor_pool,
211+ absl::Nonnull<google::protobuf::MessageFactory*> message_factory,
212+ absl::Nonnull<google::protobuf::Arena*> arena, absl::Nonnull<Value*> key,
213+ absl::Nullable<Value*> value) override {
214+ ABSL_DCHECK (descriptor_pool != nullptr );
215+ ABSL_DCHECK (message_factory != nullptr );
216+ ABSL_DCHECK (arena != nullptr );
217+ ABSL_DCHECK (key != nullptr );
218+
219+ if (index_ >= size_) {
220+ return false ;
221+ }
222+ CEL_RETURN_IF_ERROR (ProjectKeys (arena));
223+ auto cel_key = (*cel_list_)->Get (arena, index_);
224+ if (value != nullptr ) {
225+ auto cel_value = cel_map_->Get (arena, cel_key);
226+ if (!cel_value) {
227+ return absl::DataLossError (
228+ " map iterator returned key that was not present in the map" );
229+ }
230+ CEL_RETURN_IF_ERROR (ModernValue (arena, *cel_value, *value));
231+ }
232+ CEL_RETURN_IF_ERROR (ModernValue (arena, cel_key, *key));
233+ ++index_;
234+ return true ;
235+ }
236+
147237 private:
148- void ProjectKeys (google::protobuf::Arena* arena) {
238+ absl::Status ProjectKeys (google::protobuf::Arena* arena) {
149239 if (cel_list_.ok () && *cel_list_ == nullptr ) {
150240 cel_list_ = cel_map_->ListKeys (arena);
151241 }
242+ return cel_list_.status ();
152243 }
153244
154245 const CelMap* const cel_map_;
0 commit comments