File tree 2 files changed +5
-5
lines changed
2 files changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ class ByteArray : public std::vector<uint8_t> {
42
42
push_back (b);
43
43
}
44
44
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) {
46
46
const std::size_t ssize = size ();
47
47
if (ssize >= sequence_size) {
48
48
for (std::size_t i = 0 ; i <= ssize - sequence_size; ++i) {
@@ -54,11 +54,11 @@ class ByteArray : public std::vector<uint8_t> {
54
54
}
55
55
}
56
56
if (found) {
57
- return i ;
57
+ return std::make_pair ( true , i) ;
58
58
}
59
59
}
60
60
}
61
- return std::size_t (- 1 );
61
+ return std::make_pair ( false , 0 );
62
62
}
63
63
64
64
std::string to_string () const {
Original file line number Diff line number Diff line change @@ -9,8 +9,8 @@ void TelegramBuffer::append(const ByteArray& bytes) {
9
9
}
10
10
11
11
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 ) {
14
14
if (signature_start_index != 0 ) {
15
15
// discard bytes preceding the header start position.
16
16
m_raw_buffer.erase (m_raw_buffer.begin (), m_raw_buffer.begin () + signature_start_index);
You can’t perform that action at this time.
0 commit comments