@@ -27,11 +27,14 @@ echo_binary_text_client_demo.cpp -lpthread -o echo_client
2727#include < iostream>
2828#include < cstdlib> // EXIT_SUCCESS
2929#include < cstddef> // std::size_t
30+ #include < cstdint> // std::uint16_t, etc
3031#include < string>
3132#include < thread>
3233#include < chrono>
3334#include < cassert>
3435
36+ #include " utility/cast_ptr_to.hpp"
37+
3538#include " net_ip/net_ip.hpp"
3639#include " net_ip/net_entity.hpp"
3740#include " net_ip_component/worker.hpp"
@@ -83,9 +86,9 @@ bool process_args(int argc, char* argv[], bool& print_errors, std::string& ip_ad
8386 return EXIT_SUCCESS;
8487}
8588
89+ constexpr std::size_t HDR_SIZE{2 }; // 1st 2 bytes of data is message size
8690
8791int main (int argc, char * argv[]) {
88- const std::size_t HDR_SIZE = 2 ; // 1st 2 bytes of data is message size
8992 const std::string PORT = " 5002" ;
9093 const std::string LOCAL_LOOP = " 127.0.0.1" ;
9194
@@ -106,7 +109,7 @@ int main(int argc, char* argv[]) {
106109 // receive text, display to console
107110 auto msg_hndlr = [] (const_buf buf, io_output io_out, endpoint ep) {
108111 // create string from buf, omit 1st 2 bytes (header)
109- std::string s (static_cast < const char *> (buf.data ()) + 2 , buf.size () - 2 );
112+ std::string s (chops::cast_ptr_to< char > (buf.data ()) + 2 , buf.size () - 2 );
110113 std::cout << s << std::endl;
111114
112115 return true ;
@@ -124,8 +127,8 @@ int main(int argc, char* argv[]) {
124127 hdr_processed = true ;
125128 // 1st 2 bytes is message size
126129 // endian correct data marshalling
127- uint16_t size = chops::extract_val<uint16_t >
128- (static_cast <std::byte*> (buf.data ()));
130+ std:: uint16_t size = chops::extract_val<std:: uint16_t >
131+ (chops::cast_ptr_to <std::byte> (buf.data ()));
129132
130133 return size;
131134 }
@@ -194,11 +197,11 @@ int main(int argc, char* argv[]) {
194197 chops::mutable_shared_buffer buf_out;
195198
196199 // 1st 2 bytes size of message (header) are the string length
197- uint16_t size_val = s.size ();
200+ std:: uint16_t size_val = static_cast <std:: uint16_t >( s.size ()); // narrowing, hence the static cast
198201 // endian correct data marshalling
199202 std::byte tbuf[HDR_SIZE]; // temp buffer to hold the header
200203 // write those 2 bytes to the temp buffer
201- std::size_t result = chops::append_val<uint16_t >(tbuf, size_val);
204+ std::size_t result = chops::append_val<std:: uint16_t >(tbuf, size_val);
202205 assert (result == HDR_SIZE);
203206 // now append our header and string data to the output buffer
204207 buf_out.append (tbuf, sizeof (tbuf)); // write the header
0 commit comments