C/C++ API Reference
Loading...
Searching...
No Matches
pw::hdlc::Decoder Class Reference

Overview

Facilitates decoding of data frames using the HDLC protocol by returning packets as they are decoded and storing incomplete data frames in a buffer.

Decoder does not own the buffer it writes to. It can be used to write bytes to any buffer. The DecoderBuffer template class allocates a buffer.

Inheritance diagram for pw::hdlc::Decoder:
pw::hdlc::DecoderBuffer< kSizeBytes >

Public Member Functions

constexpr Decoder (ByteSpan buffer)
 
 Decoder (const Decoder &)=delete
 
Decoderoperator= (const Decoder &)=delete
 
 Decoder (Decoder &&)=default
 
Decoderoperator= (Decoder &&)=default
 
Result< FrameProcess (std::byte new_byte)
 Parses a single byte of an HDLC stream.
 
template<typename F , typename... Args>
void Process (ConstByteSpan data, F &&callback, Args &&... args)
 Processes a span of data and calls the provided callback with each frame or error.
 
size_t max_size () const
 
void Clear ()
 Clears and resets the decoder.
 

Static Public Member Functions

static constexpr size_t RequiredBufferSizeForFrameSize (size_t max_frame_size)
 

Member Function Documentation

◆ max_size()

size_t pw::hdlc::Decoder::max_size ( ) const
inline
Returns
The maximum size of the Decoder's frame buffer.

◆ Process()

Result< Frame > pw::hdlc::Decoder::Process ( std::byte  new_byte)

Parses a single byte of an HDLC stream.

Note
A subsequent call to Process() will invalidate the frame.
Returns
A Result containing the decoded frame on success or one of the following error codes on failure:
  • UNAVAILABLE - No frame is available.
  • RESOURCE_EXHAUSTED - A frame completed, but it was too large to fit in the decoder's buffer.
  • DATA_LOSS - A frame completed, but it was invalid. The frame was incomplete or the frame check sequence verification failed.

◆ RequiredBufferSizeForFrameSize()

static constexpr size_t pw::hdlc::Decoder::RequiredBufferSizeForFrameSize ( size_t  max_frame_size)
inlinestaticconstexpr
Returns
The buffer space required for a Decoder to successfully decode a frame whose on-the-wire HDLC encoded size does not exceed max_frame_size.

The documentation for this class was generated from the following file: