Open phckopper opened 1 year ago
unsigned char serialize_struct(participant data) { // Alocate memory for all fields in the struct unsigned char buffer = (unsigned char )malloc(sizeof(char) 256 + sizeof(char) 16 + sizeof(char) 18 + sizeof(int)); memcpy(buffer, &data->hostname, sizeof(char) 256); memcpy(buffer + sizeof(char) 256, data->ip_address, sizeof(char) 16); memcpy(buffer + sizeof(char) 256 + sizeof(char) 16, &data->mac_address, sizeof(char) 18); memcpy(buffer + sizeof(char) 256 + sizeof(char) 16 + sizeof(char) 18, &data->status, sizeof(int)); return buffer; }
participant deserialize_struct(unsigned char buffer) { participant data = (participant )malloc(sizeof(participant)); memcpy(&data->hostname, buffer, sizeof(char) 256); memcpy(data->ip_address, buffer + sizeof(char) 256, sizeof(char) 16); memcpy(&data->mac_address, buffer + sizeof(char) 256 + sizeof(char) 16, sizeof(char) 18); memcpy(&data->status, buffer + sizeof(char) 256 + sizeof(char) 16 + sizeof(char) * 18, sizeof(int)); return data; }
Currently, we use bare fields in our network packages
https://github.com/pedrorigon/wakeUP_Computer/blob/345abc11e370af95beb42653369bba164dd60115/structs.h#L12-L20
We should start serializing our payloads into the
payload
field and stop using extra parameters in that struct.