File tree 5 files changed +14
-13
lines changed
5 files changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -58,8 +58,8 @@ class ByteArray : public std::vector<char> {
58
58
return std::make_pair (false , 0 );
59
59
}
60
60
61
- std::string to_string () const {
62
- return std::string ( reinterpret_cast < const char *>( this ->data () ), this ->size ());
61
+ operator std::string_view () const {
62
+ return std::string_view ( this ->data (), this ->size ());
63
63
}
64
64
65
65
uint32_t calc_check_sum () {
Original file line number Diff line number Diff line change @@ -134,7 +134,7 @@ GateIO::ActivityStatus GateIO::handle_telegrams(std::vector<comm::TelegramFrameP
134
134
telegram_buff.take_telegram_frames (telegram_frames);
135
135
for (const comm::TelegramFramePtr& telegram_frame: telegram_frames) {
136
136
// process received data
137
- std::string message{telegram_frame->data . to_string () };
137
+ std::string message{telegram_frame->data };
138
138
bool is_echo_telegram = false ;
139
139
if ((message.size () == comm::ECHO_DATA.size ()) && (message == comm::ECHO_DATA)) {
140
140
m_logger.queue (LogLevel::Detail, " received" , comm::ECHO_DATA);
@@ -168,7 +168,7 @@ GateIO::ActivityStatus GateIO::handle_client_alive_tracker(sockpp::tcp6_socket&
168
168
// / handle sending echo to client
169
169
if (client_alive_tracker_ptr->is_time_to_sent_echo ()) {
170
170
comm::TelegramHeader echo_header = comm::TelegramHeader::construct_from_data (comm::ECHO_DATA);
171
- std::string message = echo_header.buffer (). to_string () ;
171
+ std::string message{ echo_header.buffer ()} ;
172
172
message.append (comm::ECHO_DATA);
173
173
try {
174
174
std::size_t bytes_sent = client.write (message);
Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ std::string TelegramHeader::info() const {
73
73
return ss.str ();
74
74
}
75
75
76
+ comm::TelegramHeader TelegramHeader::construct_from_data (const std::string_view& body, uint8_t compressor_id) {
77
+ uint32_t body_check_sum = ByteArray::calc_check_sum (body);
78
+ return comm::TelegramHeader{static_cast <uint32_t >(body.size ()), body_check_sum, compressor_id};
79
+ }
80
+
76
81
} // namespace comm
77
82
78
83
#endif /* NO_SERVER */
Original file line number Diff line number Diff line change @@ -42,11 +42,7 @@ class TelegramHeader {
42
42
explicit TelegramHeader (const ByteArray& body);
43
43
~TelegramHeader ()=default ;
44
44
45
- template <typename T>
46
- static comm::TelegramHeader construct_from_data (const T& body, uint8_t compressor_id = 0 ) {
47
- uint32_t body_check_sum = ByteArray::calc_check_sum (body);
48
- return comm::TelegramHeader{static_cast <uint32_t >(body.size ()), body_check_sum, compressor_id};
49
- }
45
+ static comm::TelegramHeader construct_from_data (const std::string_view& body, uint8_t compressor_id = 0 );
50
46
51
47
static constexpr size_t size () {
52
48
return SIGNATURE_SIZE + LENGTH_SIZE + CHECKSUM_SIZE + COMPRESSORID_SIZE;
Original file line number Diff line number Diff line change @@ -18,21 +18,21 @@ TEST_CASE("test_server_bytearray", "[vpr]") {
18
18
REQUIRE (array.at (4 ) == ' 2' );
19
19
REQUIRE (array.at (5 ) == ' 2' );
20
20
21
- REQUIRE (array. to_string () == " 111222" );
21
+ REQUIRE (std::string_view{ array} == " 111222" );
22
22
23
23
REQUIRE (array.size () == 6 );
24
24
25
25
array.append (' 3' );
26
26
27
27
REQUIRE (array.size () == 7 );
28
- REQUIRE (array. to_string () == " 1112223" );
28
+ REQUIRE (std::string_view{ array} == " 1112223" );
29
29
30
30
REQUIRE (array.at (6 ) == ' 3' );
31
31
32
32
array.clear ();
33
33
34
34
REQUIRE (array.size () == 0 );
35
- REQUIRE (array. to_string () == " " );
35
+ REQUIRE (std::string_view{ array} == " " );
36
36
}
37
37
38
38
TEST_CASE (" test_server_telegrambuffer_oneOpened" , " [vpr]" ) {
@@ -43,7 +43,7 @@ TEST_CASE("test_server_telegrambuffer_oneOpened", "[vpr]") {
43
43
auto frames = buff.take_telegram_frames ();
44
44
REQUIRE (frames.size () == 0 );
45
45
46
- REQUIRE (buff.data (). to_string () == " 111222" );
46
+ REQUIRE (std::string_view{ buff.data ()} == " 111222" );
47
47
}
48
48
49
49
TEST_CASE (" test_server_telegrambuffer_notFilledTelegramButWithPrependedRubish" , " [vpr]" )
You can’t perform that action at this time.
0 commit comments