Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_protobuf / public / pw_protobuf / find.h
1 // Copyright 2020 The Pigweed Authors
2 //
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
5 // 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, 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
13 // the License.
14 #pragma once
15
16 #include "pw_protobuf/decoder.h"
17
18 namespace pw::protobuf {
19
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
23 // nested message.
24 class FindDecodeHandler final : public DecodeHandler {
25  public:
26   constexpr FindDecodeHandler(uint32_t field_number)
27       : FindDecodeHandler(field_number, nullptr) {}
28
29   constexpr FindDecodeHandler(uint32_t field_number, FindDecodeHandler* nested)
30       : field_number_(field_number), found_(false), nested_handler_(nested) {}
31
32   Status ProcessField(CallbackDecoder& decoder, uint32_t field_number) override;
33
34   bool found() const { return found_; }
35
36   void set_nested_handler(FindDecodeHandler* nested) {
37     nested_handler_ = nested;
38   }
39
40  private:
41   uint32_t field_number_;
42   bool found_;
43   FindDecodeHandler* nested_handler_;
44 };
45
46 }  // namespace pw::protobuf