MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ cobs_decode()

bool MayaFlux::Transitive::Protocol::detail::cobs_decode ( Message frame,
std::vector< uint8_t > & out )
inlinenodiscard

Decode one COBS frame, without its zero delimiter.

Returns
false when the frame is malformed. out may then hold a partial result.

Definition at line 489 of file Framing.hpp.

490 {
491 size_t index = 0;
492 while (index < frame.size()) {
493 const size_t code = frame[index++];
494 if (code == 0) {
495 return false;
496 }
497 const size_t run = code - 1;
498 if (index + run > frame.size()) {
499 return false;
500 }
501 for (size_t i = 0; i < run; ++i) {
502 if (frame[index + i] == 0) {
503 return false;
504 }
505 }
506 out.insert(out.end(), frame.begin() + static_cast<std::ptrdiff_t>(index),
507 frame.begin() + static_cast<std::ptrdiff_t>(index + run));
508 index += run;
509 if (code != 0xFF && index < frame.size()) {
510 out.push_back(0);
511 }
512 }
513 return true;
514 }
void run()
Definition main.cpp:21

References run().

Referenced by MayaFlux::Transitive::Protocol::CobsFramer::push().

Here is the call graph for this function:
Here is the caller graph for this function: