It parses C++ sourcecode for special attributes. In the simplest situation you only need mark an object by ER_REFLECT()
macro. All other work will be done by code generation tool and reflection library.
The main idea is use kinda dynamic typing and Run Time Type Checking for some type agnostic operations, like copying or taking name of a type.
It makes possible determine a variable type and do right job - print, serialize/deserialize or whatever.
- Linux, MacOS and Windows support
- translate enums to string and vise versa
- support of stl containers like
std::vector
,std::list
,std::map
, etc. - smart pointers support
- native serialization directly to an object and without third parties for:
- JSON
- YAML 1.2 even with anchors, but keep in mind that variables behind anchors have to have the same type.
- binary with Variable Length Quantity to reduce number of bytes
- debug printing
- understandable errors
Take a look at Installation guide and install the solution.
Then define your object and use ER_REFLECT()
attribute:
ER_REFLECT()
class Object {
public:
std::string field_str;
int field_int;
std::vector<int> field_vector;
}
And serialize/deserialize it in one shot:
#include "generated/reflection.h"
#include "er/serialization/json.h"
using namespace serialization;
...
auto str = json::to_string<Object>(obj).unwrap();
obj = json::from_string<Object>(str).unwrap();
...
For more details see How To Use.
The repository includes benchmarks
folder, feel free to check it on your own hardware.
JSON on average Core i5 laptop is faster then nlohmann json.
Serialization is the same fast as rapid json, deserialization is little faster with simdjson
parser and more then twice slower without.
YAML is blazingly faster then yaml-cpp, if I did the benchmark right.
Note: Deserialization comparisson is not absolutely fair.
Other libraries not always convert string represented values toint
,float
orbool
and don't create instances ofstd::string
until you call something like.get<int>()
.
Easy Reflection, on the other hand, provides ready-made object with all values within. And it's still fast despite it takes some time.
The length in bytes of serialized in different ways objects has the following relation:
- Specialize
constexpr TypeId
for analyzed types - Construct fields map in compile time
- Cleanup all
TODO
s in the code - Default value in case of
null
in parsers - Prettify
reflection::print()
- Add default constructable SFINAE guard
- Add support of move semantic
- Optimize size of
Expected<>
in parsers - Test YAML parser extensively
- Test wide strings
- Add parent class fields to serialized fields
- Add support of user's template classes with different number of template arguments
- Add custom allocators in supported containers