cppserdes_icon
***CppSerdes*** is a serialization/deserialization library designed with embedded systems in mind
Features
- Bitpacking support - any bit alignment, any bit padding.
- Portability - uses bit shifting and masking, with no dynamic memory allocation (avoids most std containers).
- Serializes to/from 8-bit arrays, ***AND*** 16-bit, 32-bit, and 64-bit arrays. With no API changes to your code, to work with hardware drivers directly in their native bit widths.
- Common Embedded Systems types - floating point, unsigned, signed, classes, enums, arrays, custom types, etc. While avoiding pulling in atypically embedded std types such as std::string, std::vector, etc.
- Arrays - fixed sized arrays, dynamically sized arrays, and ***delimited*** arrays.
- Memory safety - Bound checking for both serial buffers and array fields.
- Choose from both high abstraction level (object-oriented & streams) and low level (memcpy-like) APIs.
- Custom formatter types, such as optional validation checks, attached right to a field.
- Virtual fields, and pure virtual fields, allowing you to easily change formats at runtime.
- Header only, and works with C++11 and greater.
- "constexpr" support for C++14 or greater using bitcpy function (depends on compiler support).
- Compiles with high warning levels (pedantic, Wall, etc.).
Documentation
darrenlevine.github.io/cppserdes
Quick Start
- Check out the examples:
- Compile and run "examples/01_simple_example.cpp".
- Read through the examples/ folder for various usage cases.
- Use the library in your project:
- Manual inclusion: Make sure "cppserdes/include/" is added to your project's path and use as desired.
- With CMake: Add the following lines to your CmakeLists.txt project file:
1 add_subdirectory(cppserdes/)
2 target_link_libraries(your_project_name cppserdes)
int8_t x = 6, y = 7, z = 8;
}
};
int main() {
uint16_t serial_data[] = {0x0102, 0x7B00};
my_packet obj1;
obj1.load(serial_data);
my_packet obj2;
obj2.store(serial_data);
}
int main() {
uint16_t serial_data[] = {0x0102, 0xFB00};
int8_t x, y, z;
}
int main() {
uint16_t serial_data[] = {0x0102, 0x0304, 0x0506};
int8_t x, y, z;
}
Known Limitations
- Little endian "serialization" is not yet supported (Note: little and big endian "platforms" ARE both supported)
- Constexpr bitcpy of enums and floating point types is not supported since the constexpr intepretation of their memory is undefined behaviour (i.e. non-constexpr memcpy must be used behind the scenes)
- Cannot bitcpy more than 0.25GB of data in a single function call (due to a memory-usage/speed design decision)
- The examples are written using C++17 syntax for succinctness and simplicity, so if you're using an older compiler, templated fields might need to have their templates explicitly specified, for example:
Planned Features
- Little endian serialization support (compile time only is planned)
- The ability to avoid serialization/deserialization by setting pointers to point to the appropriate spot within the serial buffer, instead of making a copy into a new buffer, thus saving time and memory if the serial buffer's lifetime persists longer than the reference, and the memory is aligned appropriately to allow this optimization. Similar to how capnproto and flatbuffers work.
Requirements