I'm trying to make portable library that can be used in esp32. Right now I have function that converts a struct to a char*. I populate the struct Message and then do:
memcpy(array,&message,sizeof(Message));
Later I would like to send this char* to a socket, receive it in the other side and reconstruct the struct. Is that possible ? Also, another question I have is:
struct Header{
uint32_t source_id;
uint32_t destinatary_id;
uint32_t message_type;
};
struct Data {
uint32_t dataSize;
uint8_t* data;
};
struct Message{
Header header;
Data data;
uint32_t timestamp;
};
char* array = new char[sizeof(Message)];
char array2[sizeof(Message)];
What is the difference between those two? array is a pointer and array2 is an array but I can't use array2 in this function because once I get out of the scope of the function the pointer to it is deleted.