diff --git a/README.md b/README.md index 8575ba13..ec9ae60d 100644 --- a/README.md +++ b/README.md @@ -281,8 +281,7 @@ Finally, it is very easy to extend full support to your own classes, refer to th reflect-cpp currently supports the following serialization formats: - **JSON**: Out-of-the-box support, no additional dependencies required. -- **XML**: Requires [libxml2](https://github.com/GNOME/libxml2) (TODO). -- **flexbuffers**: Requires [flatbuffers](https://github.com/google/flatbuffers) (TODO). +- **flexbuffers**: Requires [flatbuffers](https://github.com/google/flatbuffers). reflect-cpp is deliberately designed in a very modular format, using [concepts](https://en.cppreference.com/w/cpp/language/constraints), to make it as easy as possible to support additional serialization formats. Refer to the [documentation](https://github.com/getml/reflect-cpp/tree/main/docs) for details. PRs related to serialization formats are welcome. diff --git a/docs/README.md b/docs/README.md index e8548ab7..1c12ac6d 100644 --- a/docs/README.md +++ b/docs/README.md @@ -52,6 +52,8 @@ 5.1) [JSON](https://github.com/getml/reflect-cpp/blob/main/docs/json.md) +5.2) [flexbuffers](https://github.com/getml/reflect-cpp/blob/main/docs/flexbuffers.md) + ## 6) Advanced topics 6.1) [Supporting your own format](https://github.com/getml/reflect-cpp/blob/main/docs/supporting_your_own_format.md) - For supporting your own serialization and deserialization formats. diff --git a/docs/flexbuffers.md b/docs/flexbuffers.md index 3da4ec74..f1ec40fe 100644 --- a/docs/flexbuffers.md +++ b/docs/flexbuffers.md @@ -154,53 +154,53 @@ But what it more, unlike "normal" flatbuffers, flexbuffers also supports field n #include #include - using Color = rfl::Literal<"Red", "Green", "Blue">; +using Color = rfl::Literal<"Red", "Green", "Blue">; - struct Weapon { - rfl::Field<"name", std::string> name; - rfl::Field<"damage", short> damage; - }; +struct Weapon { + rfl::Field<"name", std::string> name; + rfl::Field<"damage", short> damage; +}; - using Equipment = rfl::Variant>; +using Equipment = rfl::Variant>; - struct Vec3 { - rfl::Field<"x", float> x; - rfl::Field<"y", float> y; - rfl::Field<"z", float> z; - }; +struct Vec3 { + rfl::Field<"x", float> x; + rfl::Field<"y", float> y; + rfl::Field<"z", float> z; +}; - struct Monster { - rfl::Field<"pos", Vec3> pos; - rfl::Field<"mana", short> mana = 150; - rfl::Field<"hp", short> hp = 100; - rfl::Field<"name", std::string> name; - rfl::Field<"friendly", bool> friendly = false; - rfl::Field<"inventory", std::vector> inventory; - rfl::Field<"color", Color> color = Color::make<"Blue">(); - rfl::Field<"weapons", std::vector> weapons; - rfl::Field<"equipped", Equipment> equipped; - rfl::Field<"path", std::vector> path; - }; +struct Monster { + rfl::Field<"pos", Vec3> pos; + rfl::Field<"mana", short> mana = 150; + rfl::Field<"hp", short> hp = 100; + rfl::Field<"name", std::string> name; + rfl::Field<"friendly", bool> friendly = false; + rfl::Field<"inventory", std::vector> inventory; + rfl::Field<"color", Color> color = Color::make<"Blue">(); + rfl::Field<"weapons", std::vector> weapons; + rfl::Field<"equipped", Equipment> equipped; + rfl::Field<"path", std::vector> path; +}; - const auto sword = Weapon{.name = "Sword", .damage = 3}; - const auto axe = Weapon{.name = "Axe", .damage = 5}; +const auto sword = Weapon{.name = "Sword", .damage = 3}; +const auto axe = Weapon{.name = "Axe", .damage = 5}; - const auto weapons = std::vector({sword, axe}); +const auto weapons = std::vector({sword, axe}); - const auto position = Vec3{1.0f, 2.0f, 3.0f}; +const auto position = Vec3{1.0f, 2.0f, 3.0f}; - const auto inventory = - std::vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); +const auto inventory = + std::vector({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); - const auto orc = Monster{.pos = position, - .mana = 150, - .hp = 80, - .name = "MyMonster", - .inventory = inventory, - .color = Color::make<"Red">(), - .weapons = weapons, - .equipped = rfl::make_field<"weapon">(axe), - .path = rfl::default_value}; +const auto orc = Monster{.pos = position, + .mana = 150, + .hp = 80, + .name = "MyMonster", + .inventory = inventory, + .color = Color::make<"Red">(), + .weapons = weapons, + .equipped = rfl::make_field<"weapon">(axe), + .path = rfl::default_value}; const auto bytes = rfl::flexbuf::write(orc); diff --git a/tests/flexbuffers/README.md b/tests/flexbuffers/README.md new file mode 100644 index 00000000..1c62f9f5 --- /dev/null +++ b/tests/flexbuffers/README.md @@ -0,0 +1,23 @@ +# Tests for flexbuffers + +This folder contains the tests for flexbuffers. A Docker-based build pipeline is provided for Linux users. + +Build the Docker container containing the build environment: + +``` +./build_docker.sh +``` + +Compile the tests: + +``` +./compile.sh +``` + +Run the tests: + +``` +./build/reflect-cpp-tests +``` + +To run the scripts, you may have to run `chmod +x build_docker.sh` and `chmod +x compile.sh` first.