Skip to content

Commit 5886d61

Browse files
committed
ByteArray::find_sequence returns std::pair<bool, std::size_t> instead of just std::size_t, where first bool in pair signalize about search status
1 parent 5b10a33 commit 5886d61

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

vpr/src/server/bytearray.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ByteArray : public std::vector<uint8_t> {
4242
push_back(b);
4343
}
4444

45-
std::size_t find_sequence(const char* sequence, std::size_t sequence_size) {
45+
std::pair<bool, std::size_t> find_sequence(const char* sequence, std::size_t sequence_size) {
4646
const std::size_t ssize = size();
4747
if (ssize >= sequence_size) {
4848
for (std::size_t i = 0; i <= ssize - sequence_size; ++i) {
@@ -54,11 +54,11 @@ class ByteArray : public std::vector<uint8_t> {
5454
}
5555
}
5656
if (found) {
57-
return i;
57+
return std::make_pair(true, i);
5858
}
5959
}
6060
}
61-
return std::size_t(-1);
61+
return std::make_pair(false, 0);
6262
}
6363

6464
std::string to_string() const {

vpr/src/server/telegrambuffer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ void TelegramBuffer::append(const ByteArray& bytes) {
99
}
1010

1111
bool TelegramBuffer::check_telegram_header_presence() {
12-
std::size_t signature_start_index = m_raw_buffer.find_sequence(TelegramHeader::SIGNATURE, TelegramHeader::SIGNATURE_SIZE);
13-
if (signature_start_index != std::size_t(-1)) {
12+
auto [found, signature_start_index] = m_raw_buffer.find_sequence(TelegramHeader::SIGNATURE, TelegramHeader::SIGNATURE_SIZE);
13+
if (found) {
1414
if (signature_start_index != 0) {
1515
// discard bytes preceding the header start position.
1616
m_raw_buffer.erase(m_raw_buffer.begin(), m_raw_buffer.begin() + signature_start_index);

0 commit comments

Comments
 (0)