Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / pigweed / repo / pw_hdlc / public / pw_hdlc / internal / encoder.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_checksum/crc32.h"
17 #include "pw_stream/stream.h"
18
19 namespace pw::hdlc::internal {
20
21 // Encodes and writes HDLC frames.
22 class Encoder {
23  public:
24   constexpr Encoder(stream::Writer& output) : writer_(output) {}
25
26   // Writes the header for an I-frame. After successfully calling
27   // StartInformationFrame, WriteData may be called any number of times.
28   [[maybe_unused]] Status StartInformationFrame(uint8_t address);
29
30   // Writes the header for an U-frame. After successfully calling
31   // StartUnnumberedFrame, WriteData may be called any number of times.
32   Status StartUnnumberedFrame(uint8_t address);
33
34   // Writes data for an ongoing frame. Must only be called after a successful
35   // StartInformationFrame call, and prior to a FinishFrame() call.
36   Status WriteData(ConstByteSpan data);
37
38   // Finishes a frame. Writes the frame check sequence and a terminating flag.
39   Status FinishFrame();
40
41   // Runs a pass through a payload, returning the worst-case encoded size for a
42   // frame containing it. Does not calculate CRC to improve efficiency.
43   static size_t MaxEncodedSize(uint8_t address, ConstByteSpan payload);
44
45  private:
46   stream::Writer& writer_;
47   checksum::Crc32 fcs_;
48 };
49
50 }  // namespace pw::hdlc::internal