1 // Copyright 2020 The Pigweed Authors
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
7 // https://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
16 #include "pw_protobuf/decoder.h"
18 namespace pw::protobuf {
20 // DecodeHandler that searches for a specific field in a proto message. If the
21 // field is found, it cancels the decode operation. Supports searching for
22 // nested fields by passing in another instance of a FindDecodeHandler for the
24 class FindDecodeHandler final : public DecodeHandler {
26 constexpr FindDecodeHandler(uint32_t field_number)
27 : FindDecodeHandler(field_number, nullptr) {}
29 constexpr FindDecodeHandler(uint32_t field_number, FindDecodeHandler* nested)
30 : field_number_(field_number), found_(false), nested_handler_(nested) {}
32 Status ProcessField(CallbackDecoder& decoder, uint32_t field_number) override;
34 bool found() const { return found_; }
36 void set_nested_handler(FindDecodeHandler* nested) {
37 nested_handler_ = nested;
41 uint32_t field_number_;
43 FindDecodeHandler* nested_handler_;
46 } // namespace pw::protobuf