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

◆ encode_delimited()

bool MayaFlux::Transitive::Protocol::encode_delimited ( Message payload,
Message terminator,
std::vector< uint8_t > & out )
inlinenodiscard

Append a payload and a terminator to out, in the form DelimiterFramer reads back.

Refused, with out unchanged, when the terminator is empty or when the terminator would end the message before the payload does.

Definition at line 466 of file Framing.hpp.

467{
468 if (terminator.empty()) {
469 return false;
470 }
471
472 std::vector<uint8_t> joined(payload.begin(), payload.end());
473 joined.insert(joined.end(), terminator.begin(), terminator.end());
474 const auto hit = std::ranges::search(joined, terminator);
475 if (static_cast<size_t>(hit.begin() - joined.begin()) != payload.size()) {
476 return false;
477 }
478
479 out.insert(out.end(), joined.begin(), joined.end());
480 return true;
481}