Open DavidBuchanan314 opened 2 years ago
While I agree it would be handy, it is not quite a universal function. If the buffer is larger than the memory + the rom or whatever in RAM, you will crash. The Arduino one already suffers from memory pressure & the way it is implemented in tamatool has a whole different level of abstractions over the file system which aren't easily replicated. It sucks to replicate but there are not too many options given the constraints of the platforms.
It could be done with ~0 memory, using a streaming API, e.g.
void get_serialised_state(void (*callback_that_writes_one_byte)(uint8_t));
void set_serialised_state(uint8_t (*callback_that_reads_one_byte)(void));
(please excuse my possibly incorrect C function pointer syntax...)
This API should be sufficient to implement something like writing to an EEPROM on a resource-constrained Arduino, but also work nicely for implementations like tamatool.
For most concrete implementations (e.g. in tamatool https://github.com/jcrona/tamatool/blob/master/src/state.c ), there exists a need to serialise the state to an array of bytes, so that it may be saved in non-volatile storage etc.
IMHO this logic should be contained within tamalib itself, along with functions vaguely like