pupene
0.2.0
|
A non-invasive, multi-format serialization library for C++17.
This library was primarily conceived as a foundation for assisting with building tooling for gamedev projects. The approach and naming conventions are borrowed from Daniel Randle's Pupping - a method for serializing data.
pupene
relies on direct field access to read/write.pup()
- one serializer-agnostic read/write function per type.Pupper
- serializer, binary and optional JSON support included.Add this conan remote:
In your project's conanfile.txt/py:
At the core, pupene
is built around serializers called puppers, and pup
functions - a combined read/write function per serializable type.
Include <pupene/binary.h>
and/or <pupene/json.h>
(requires -DPUPENE_BUILD_JSON=true
) to access the appropriate puppers.
Refer to the API docs for more detailed documentation. The tests may be of some interest too.
Namespace pupene
is omitted from example code, in the interest of brevity.
Pupper
is on the receiving end of pup
; they only deal directly with values once pup
has flattened the object into a sequence of integer, decimal and string types.
Included Puppers, and related convenience functions:
from_json()
to_json()
from_binary()
to_binary()
to_debug()
A pup
function must exist for each serializable type.
An object is serializable when there's a matching pup
function; these describe the structure of the type by enumerating its fields. All pup
functions must be defined in the pupene::fns
namespace.
A limited number of fundamental types are built-in:
std::string
std::vector
and std::map
pup()
for a type FooBar
has the following signature:
N.B. For function resolution to work, pup
functions must be declared in a file which does not #include
any puppers, implicitly or explicitly.
You have some models:
To make the types eligible, each requires its own pup function in the namespace pupene:fns
.
Once the necessary pup:s are implemented, serialization between different format becomes possible e.g.:
Color
and FontReference
can now also be combined with some STL containers:
Unless already added, The conan-community
remote has to be added for the Boost
test dependency to work:
First-time setup:
Build project:
Once conan has built the project for the first time, CMake should work as expected.
Build project:
Tests are run with:
... or run the tests with valgrind/memcheck:
To play nice with CLion, manually specify the compiler using CMake Options under Settings > Build, Execution, Deployment > CMake
, e.g.:
pup
.