From 37a0be8a91fc8186155088a1bcf80ea27c604625 Mon Sep 17 00:00:00 2001 From: "Dr. Patrick Urbanke" Date: Sun, 22 Dec 2024 14:50:11 +0100 Subject: [PATCH] Made sure uint8_t is properly handled by YAML; #270 --- include/rfl/yaml/Reader.hpp | 5 +++-- include/rfl/yaml/Writer.hpp | 13 ++++++++++++- tests/yaml/test_snake_case_to_pascal_case.cpp | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/include/rfl/yaml/Reader.hpp b/include/rfl/yaml/Reader.hpp index 231192ae..451a86ce 100644 --- a/include/rfl/yaml/Reader.hpp +++ b/include/rfl/yaml/Reader.hpp @@ -61,9 +61,10 @@ struct Reader { try { if constexpr (std::is_same, std::string>() || std::is_same, bool>() || - std::is_floating_point>() || - std::is_integral>()) { + std::is_floating_point>()) { return _var.node_.as>(); + } else if constexpr (std::is_integral>()) { + return static_cast(_var.node_.as>()); } else { static_assert(rfl::always_false_v, "Unsupported type."); } diff --git a/include/rfl/yaml/Writer.hpp b/include/rfl/yaml/Writer.hpp index 59b1d9d7..1a8db584 100644 --- a/include/rfl/yaml/Writer.hpp +++ b/include/rfl/yaml/Writer.hpp @@ -86,7 +86,18 @@ class Writer { template OutputVarType insert_value(const std::string_view& _name, const T& _var) const noexcept { - (*out_) << YAML::Key << _name.data() << YAML::Value << _var; + if constexpr (std::is_same, std::string>() || + std::is_same, bool>() || + std::is_floating_point>() || + std::is_same, + std::remove_cvref_t>()) { + (*out_) << YAML::Key << _name.data() << YAML::Value << _var; + } else if constexpr (std::is_integral>()) { + (*out_) << YAML::Key << _name.data() << YAML::Value + << static_cast(_var); + } else { + static_assert(rfl::always_false_v, "Unsupported type."); + } return OutputVarType{}; } diff --git a/tests/yaml/test_snake_case_to_pascal_case.cpp b/tests/yaml/test_snake_case_to_pascal_case.cpp index c709445c..46da1344 100644 --- a/tests/yaml/test_snake_case_to_pascal_case.cpp +++ b/tests/yaml/test_snake_case_to_pascal_case.cpp @@ -13,7 +13,7 @@ struct Person { std::vector children; }; -TEST(bson, test_snake_case_to_pascal_case) { +TEST(yaml, test_snake_case_to_pascal_case) { const auto bart = Person{ .first_name = "Bart", .last_name = "Simpson", .birthday = "1987-04-19"};