These examples demonstrate using the serdes::packet class with stream operators as well as method operators, along with several format customization techniques such as modifying padding, alignment, and and bit size (bitpacking)
#include "../include/serdes.h"
#include "../include/bitprint.h"
int main()
{
constexpr size_t buffer_size = sizeof(int) * 3 / sizeof(uint32_t);
{
uint32_t buffer[buffer_size] = {};
buffer_stream << 1 << 5 << 9;
printf("stored data: ");
int x, y, z;
buffer_stream >> x >> y >> z;
printf("recovered data: {x = %i, y = %i, z = %i}\n\n", x, y, z);
}
{
uint32_t buffer[buffer_size] = {};
buffer_stream.
store(-2, 3);
buffer_stream.
store(-123);
printf("stored data: ");
int x, y, z;
buffer_stream.
load(y, 3);
printf("recovered data: {x = %i, y = %i, z = %i}\n\n", x, y, z);
}
{
uint32_t buffer[buffer_size] = {};
uint64_t flags[8] = {1, 0, 1, 0, 1, 0, 1, 1};
printf("stored data: ");
int x, y, z;
printf("recovered data: {x = %i, y = %i, z = %i}\n\n", x, y, z);
}
}