- Author: Richard James Howe
- License: 0BSD / Public Domain
- Email: mailto:hower.r.j.89@gmail.com
- Repo: https://github.com/howerj/serdes
This is a header-only serialization / deserialization library for C (and C++) that allows you to perform SERDES operations on a struct to and from a buffer.
Consult the code, in serdes.h for documentation and how to use this library.
For a quick overview of what the library does and helps with, say you want to write a structure to disk, or send it over a network connection, in a portable way, take the following structure as an example:
struct example {
uint16_t a;
int32_t b;
uint64_t c;
uint8_t d;
};
It is often a hassle to write the code out; what endianess is used, you have to write at least two functions (and another to print the structure out for debugging), etcetera.
Instead you can use this library and write:
int serdes_example(struct example *data, int op, uint8_t *buffer, size_t length) {
serdes_t s;
serdes_start(&s, op, buffer, length, "example");
serdes_u16(&s, 0, &data->a);
serdes_i32(&s, 0, &data->b);
serdes_u64(&s, 0, &data->c);
serdes_u8(&s, 0, &data->d);
return serdes_end(s);
}
This function will allow you to serialize the example structure into a buffer, read from a buffer into the example structure, and print the structure out.
It is described in more detail in the header.