Part of our summer project plans are to get some older projects onto GitHub with free permissive licenses for both private and commercial works (Currently we are using MIT license).
Our first offering is something I've wanted to see become a common library for a long time.
Serialization of object models in C++
...that is an easier route to save game files for complex game states;
without having to understand the nitty gritty of object model serialization techniques.
https://github.com/edigames/object-model-serializer
First off, there are better known, more complete (at least as of this writing), and far more complex implementations out there.
But a key element for us was to adhere to a few guiding principles:
- It should be tiny (2 files)
- It should be non-intrusive, procedural style no base class inheritance requirements
- It should internally handle references and cycles ("saving pointers")
- It should be 'soft serialization' ability to add/remove and out-of-order members without 'version blocks'
- It should come with a complex use case example (see simple_rpg folder)
- It should use standard streams, for file and in-memory serialization.
- It should be a lightweight binary format (soft serialization is 'easy' in something like json/xml)
- It should not use external pre-processor, or code generation techniques (gross.)
Some future goals...- It should be endian/architechture agnostic (this should be relatively simple)
- Higher level interfaces should be optional to reduce syntax and mundane routines
It is still a work in progress, but I have overcome a sticking point which made me question feasibility (without excessive overhead), such that I now feel it is ready for folks to have a look and even begin using.
I ask everyone willing to have a look, comment, rant, contibute etc.
Problems, specifically in usage will be addressed as quickly as possible.
- It should be endian/architechture agnostic (this should be relatively simple)
I'd suggest using msgpack as a lightweight binary format back-end for your serialization code instead of rolling your own, benefits is it already handles endianness correctly, is basically the same as your approach (type marker followed by data) but also has size optimizations for e.g. small ints, small strings, and so on, supports arrays (both indexed and associative), and has efficient, lightweight and battle-tested implementations (I'm quite fond of https://github.com/camgunz/cmp). I'm sure there is a suitably C++ized implementation available as well..
I would imagine a streaming encoder/decoder is all you need for soft serialization, don't want to impose a strict object model on the user, rather let him define his own... perhaps more advanced features might want to dig into the serialized stream for e.g. lazy initialization, but I don't know how useful that really is.