From 9e8a61b0a2350c6fe9daaa69a076cbe9cdf2c654 Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Mon, 13 Nov 2023 19:51:04 +0100 Subject: [PATCH 1/5] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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. From 82204df756628fe24f500ea087f648ef935f1d91 Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Mon, 13 Nov 2023 19:54:49 +0100 Subject: [PATCH 2/5] Added README.md for the flexbuffers tests --- tests/flexbuffers/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/flexbuffers/README.md diff --git a/tests/flexbuffers/README.md b/tests/flexbuffers/README.md new file mode 100644 index 00000000..d05cf270 --- /dev/null +++ b/tests/flexbuffers/README.md @@ -0,0 +1,21 @@ +# 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 +``` From 944155c90560337028e4f511fd337c7993f767b4 Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Mon, 13 Nov 2023 19:56:51 +0100 Subject: [PATCH 3/5] Update README.md --- tests/flexbuffers/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/flexbuffers/README.md b/tests/flexbuffers/README.md index d05cf270..1c62f9f5 100644 --- a/tests/flexbuffers/README.md +++ b/tests/flexbuffers/README.md @@ -19,3 +19,5 @@ 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. From d6fe4fd8546c6955e31391062928c50db06b34e4 Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Mon, 13 Nov 2023 20:02:43 +0100 Subject: [PATCH 4/5] Update README.md --- docs/README.md | 2 ++ 1 file changed, 2 insertions(+) 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. From 8decfce92f4306d2cedf2fc20f62d9a5470a3389 Mon Sep 17 00:00:00 2001 From: liuzicheng1987 Date: Mon, 13 Nov 2023 20:04:18 +0100 Subject: [PATCH 5/5] Fixed typo in flexbuffers.md --- docs/flexbuffers.md | 76 ++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 38 deletions(-) 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);