Omni reflector - C++ reflection/serialization library, that uses c++ metaprogramming to manage fields of class and structs at compile time. Depends only on c++ standard library, not event boost funsion or hana required.
Note serialization api depeneds on nlohmann/json library
omni reflector is not a new javascript framework btw !
#define OMNI_REFLECTOR_ENABLE_SERIALIZER
#include "omni_reflector.h"
using namespace omni::reflector;
using namespace omni::reflector::serialization;
struct MyChildStruct : Reflected<MyChildStruct> {
float someRandomFloatField;
const constexpr static auto meta = std::make_tuple(
field(someRandomFloatField)
);
};
struct MyStruct : Reflected<MyStruct> {
std::string stringField;
int poggers;
MyChildStruct childStruct;
const constexpr static auto meta = std::make_tuple(
field(stringField),
field(poggers),
field(childStruct)
);
};
int main() {
MyStruct someRandomStruct;
/* Filling struct with some values*/
nlohmann::json object = JsonSerializer::json_serialize(someRandomStruct);
const auto representation = object.dump(4);
std::cout << representation << "\n";
return 0;
};
After serializing someRandomStruct
, eventually we get json structure, that will have following layout (Note fields filled with garbage, since I haven't filled the someRandomStruct
:) ):
{
"childStruct": {
"someRandomFloatField": 4.590373509435236e-41
},
"poggers": -981426683,
"stringField": ""
}
cmake -B build -G Ninja
make.bat
test.bat
Todo