|
ESPHome 2026.12.0-dev
|
Collects binary frames that give their own length, of up to N bytes, in one or more FrameFormats; the first byte picks the format, so each format needs a different first header byte. More...
#include <frame_reader.h>
Public Member Functions | |
| template<class F > | |
| void | __attribute__ ((always_inline)) feed(uint8_t c |
| Feed one byte; calls handle(frame, length) for each frame it completes, header included. | |
| if (pos+1u< this->end_) | |
| else | if (const size_t len=this->feed_edge_(c)) |
| template<class F > | |
| void | flush (F &&handle) |
| For a partial frame idle too long: hands over the frames a corrupt length holds back inside it, else keeps it for a slow UART. | |
| size_t | length () const |
| Number of bytes of the partial frame; 0 after a frame is returned and while looking for a header. | |
| bool | receiving () const |
| Whether a frame is coming in: a partial frame that an idle flush has not searched and kept. | |
| void | drop_kept () |
| Forget a partial frame an idle flush kept, before a request starts a new exchange; safe inside a frame handler. | |
| void | reset () |
| Forget the partial frame, for a request/response protocol starting a new exchange. | |
Data Fields | |
| void F && | handle |
Protected Member Functions | |
| template<class F > | |
| bool ESPHOME_FRAME_READER_COLD | drain_ (size_t len, F &handle) |
| template<class F > | |
| void ESPHOME_FRAME_READER_COLD | flush_ (F &handle) |
| size_t ESPHOME_FRAME_READER_COLD | feed_edge_ (uint8_t c) |
| template<class F > | |
| size_t | feed_as_ (pos_t pos, uint8_t c) |
| size_t ESPHOME_FRAME_READER_COLD | replay_ (size_t from, size_t to) |
Protected Attributes | |
| pos_t | pos_ {0} |
| pos_t | end_ {0} |
| pos_t | held_end_ {0} |
| uint8_t | buf_ [N] |
Collects binary frames that give their own length, of up to N bytes, in one or more FrameFormats; the first byte picks the format, so each format needs a different first header byte.
Bytes before a header are skipped. A length that ends the frame before its length field, or is longer than N, is not a frame, and the reader looks for a header after its first byte. Checksums and footers are left to the caller, which passes a handler that returns false for a frame it rejects:
this->reader_.feed(c, [this](const uint8_t *frame, size_t len) { return this->handle_frame_(frame, len); });
For frames of one fixed size, FrameReader is smaller.
Definition at line 221 of file frame_reader.h.
| void esphome::LengthFrameReader< N, FORMATS >::__attribute__ | ( | (always_inline) | ) |
Feed one byte; calls handle(frame, length) for each frame it completes, header included.
A rejected frame (handle returns false) is searched for frames inside it and after it, which go to handle the same way. handle must not feed this reader again: the frame and the bytes held behind it live in its buffer.
|
inlineprotected |
Definition at line 290 of file frame_reader.h.
|
inline |
Forget a partial frame an idle flush kept, before a request starts a new exchange; safe inside a frame handler.
Definition at line 275 of file frame_reader.h.
|
inlineprotected |
Definition at line 341 of file frame_reader.h.
|
inlineprotected |
Definition at line 319 of file frame_reader.h.
|
inline |
For a partial frame idle too long: hands over the frames a corrupt length holds back inside it, else keeps it for a slow UART.
UARTDevice::read_frames() calls this.
Definition at line 262 of file frame_reader.h.
|
inlineprotected |
Definition at line 302 of file frame_reader.h.
|
inline |
Definition at line 255 of file frame_reader.h.
|
inline |
Definition at line 252 of file frame_reader.h.
|
inline |
Number of bytes of the partial frame; 0 after a frame is returned and while looking for a header.
Definition at line 269 of file frame_reader.h.
|
inline |
Whether a frame is coming in: a partial frame that an idle flush has not searched and kept.
Definition at line 272 of file frame_reader.h.
|
inlineprotected |
Definition at line 366 of file frame_reader.h.
|
inline |
Forget the partial frame, for a request/response protocol starting a new exchange.
Definition at line 281 of file frame_reader.h.
|
protected |
Definition at line 390 of file frame_reader.h.
|
protected |
Definition at line 386 of file frame_reader.h.
| void F&& esphome::LengthFrameReader< N, FORMATS >::handle |
Definition at line 249 of file frame_reader.h.
|
protected |
Definition at line 389 of file frame_reader.h.
|
protected |
Definition at line 384 of file frame_reader.h.