This commit is contained in:
Timur A. Fatkhullin
2024-09-24 21:51:05 +03:00
parent 02dee70db9
commit 2cf0b1f94c
3 changed files with 60 additions and 32 deletions

View File

@@ -65,22 +65,23 @@ struct AdcStopSeqSessionProto {
template <std::input_iterator IT>
std::pair<IT, bool> search(IT begin, IT end)
auto search(IT begin, IT end)
{
auto res = std::make_pair(begin, false);
std::tuple<IT, IT, bool> res{begin, end, false};
if (begin == end) {
return res;
}
res.first = std::search(begin, end, STOP_SEQ.begin(), STOP_SEQ.end());
if (res.first != end) {
std::advance(res.first, STOP_SEQ_SIZE); // move iterator to the one-past-the-end position
res.second = true;
auto it = std::search(begin, end, STOP_SEQ.begin(), STOP_SEQ.end());
if (it != end) {
// std::advance(it, STOP_SEQ_SIZE); // move iterator to the one-past-the-end position
std::get<1>(res) = it + STOP_SEQ_SIZE;
std::get<2>(res) = true;
} else {
// may be only a part of valid byte sequence was received,
// so start next matching from previous begin-iterator
res.first = begin;
std::get<1>(res) = begin;
}
return res;