12 using pos_t = std::conditional_t<(N <= 0xFF), uint8_t, uint16_t>;
13 static constexpr size_t HEADER_LEN =
sizeof...(HEADER);
14 static_assert(HEADER_LEN >= 1 && HEADER_LEN <= 8,
"FrameReader takes 1 to 8 header bytes");
15 static_assert(HEADER_LEN < N && N <= 0xFFFF,
"FrameReader size out of range");
19 const uint8_t *
feed(uint8_t c) {
27 this->
buf_[pos++] = c;
51 ((r = (j++ == i) ? HEADER : r), ...);
58 for (
size_t i = 1; i <= last; i++) {
Collects fixed length binary frames of N bytes that start with the header bytes HEADER....
static constexpr uint8_t header_byte(size_t i)
size_t length() const
Number of bytes of the partial frame; 0 after a frame is returned and while looking for a header.
void replay_(size_t last)
const uint8_t * feed(uint8_t c)
Feed one byte; returns the completed frame, header included, valid until the next call,...
void resync()
For a frame the caller rejected (bad checksum): drop its first byte and realign on a header in the re...
void reset()
Forget the partial frame and look for a header from the next byte.