This example demonstrates defining a list of serdes::formatter object which can be used as an editable format. Fields and formats can be swapped out flexibly, enabling use cases such as easily customizable telemetry messages.
#include "../include/serdes.h"
#include <stdio.h>
#include "../test/notify_when_dynamic_allocation_used.h"
{
int32_t x = -9, y = 10, z = -11;
{
p + edittable_format;
}
};
int main()
{
uint16_t serial_data[6] = {0x0018, 0x0001, 0x0002, 0xFFFF, 0xFFFB, 0x0000};
coordinates obj;
auto load_result = obj.load(serial_data);
auto store_result = obj.store(serial_data);
printf("Loaded x = %i, y = %i, z = %i (%zu bits total) with %s\n",
printf("Stored x = %i, y = %i, z = %i (%zu bits total) with %s\n",
printf("Replaced portion of the format = 0x%04X%04X\n", serial_data[0], serial_data[1]);
}