I'm currently writing an abstraction layer for RF24Mesh microcontroller layer to implement message signing.
As I want to make it as universal as possible I'd love to make it possible to pass any struct/payload for ex: (This is only an example of one struct that one should be able to pass to the function)
struct payload_sensor {
uint8_t some_other_sensor_data[32];
int sensor_id;
int sensor_data;
};
To the signing function and then let it deal with storing the payload/struct until everything else is done for it to be sent.
But here's the thing, I can't predict the exact size of the struct passed to the function (it should deal with any struct passed to it), the same struct might be reused (filled with other data) and passed to the function again. I'm totally unable to think of a good solution.
Now how do I implement a proper buffer to store these unknown payloads/structs until they are ready to be sent? I'd also have to keep in mind that the code is running on AVR, so AVR memory (fragmentation) might become an issue.
I'm kind of new to structs and more advanced stuff, so don't mind me missing something obvious please.
char*orvoid*and a size.Tdefines, you don't even need length.memcpyed into it. Have the first struct byte/short/int by convention hold a tag that tells the other end what type is coming along.