Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_hdlc / public / pw_hdlc / wire_packet_parser.h
1 // Copyright 2021 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_assert/light.h"
17 #include "pw_router/packet_parser.h"
18
19 namespace pw::hdlc {
20
21 // HDLC frame parser for routers that operates on wire-encoded frames.
22 //
23 // Currently, this assumes 1-byte HDLC address fields. An optional address_bits
24 // value can be provided to the constructor to use a smaller address size.
25 class WirePacketParser final : public router::PacketParser {
26  public:
27   constexpr WirePacketParser(uint8_t address_bits = 8)
28       : address_(0), address_shift_(8 - address_bits) {
29     PW_ASSERT(address_bits <= 8);
30   }
31
32   // Verifies and parses an HDLC frame. Packet passed in is expected to be a
33   // single, complete, wire-encoded frame, starting and ending with a flag.
34   bool Parse(ConstByteSpan packet) final;
35
36   std::optional<uint32_t> GetDestinationAddress() const final {
37     return address_;
38   }
39
40  private:
41   uint8_t address_;
42   uint8_t address_shift_;
43 };
44
45 }  // namespace pw::hdlc