As an example have the below struct, and I am sending this over a tcp socket. When I receive the data on the tcp socket, how do I reconstruct the struct information? ( how do I convert the tcp data to be printed on the console)
//data struct
typedef struct {
int enable;
string name;
int numbers[5];
float counter;
}Student;
//convert data to uint8 and send over tcp socket
uint32_t size = sizeof(student);
std:vector<std::uint8_t> data(size);
std::memcpy(data.data(), reinterpret_cast<void*>(&student),size)
sendDataOverTCPSocket(data);
Appreciate an example on how to do this. Thank you
std::string name, and cannot be trivially copied with memcpy (and sizeof will not work as you expect either). You need to serialize it.