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_router/packet_parser.h" 17 18 namespace pw::hdlc { 19 20 // HDLC frame parser for routers that operates on wire-encoded frames. 21 // 22 // This allows routing HDLC frames through Pigweed routers without having to 23 // first decode them from their wire format. 24 class WirePacketParser : public router::PacketParser { 25 public: WirePacketParser()26 constexpr WirePacketParser() : address_(0) {} 27 28 // Verifies and parses an HDLC frame. Packet passed in is expected to be a 29 // single, complete, wire-encoded frame, starting and ending with a flag. 30 bool Parse(ConstByteSpan packet) final; 31 GetDestinationAddress()32 std::optional<uint32_t> GetDestinationAddress() const override { 33 return address_; 34 } 35 36 protected: address()37 constexpr uint64_t address() const { return address_; } 38 39 private: 40 uint64_t address_; 41 }; 42 43 } // namespace pw::hdlc 44