Skip to content

Commit

Permalink
Made sure uint8_t is properly handled by YAML; #270
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 committed Dec 22, 2024
1 parent a1920a1 commit 37a0be8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions include/rfl/yaml/Reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ struct Reader {
try {
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>() ||
std::is_same<std::remove_cvref_t<T>, bool>() ||
std::is_floating_point<std::remove_cvref_t<T>>() ||
std::is_integral<std::remove_cvref_t<T>>()) {
std::is_floating_point<std::remove_cvref_t<T>>()) {
return _var.node_.as<std::remove_cvref_t<T>>();
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
return static_cast<T>(_var.node_.as<std::remove_cvref_t<int64_t>>());
} else {
static_assert(rfl::always_false_v<T>, "Unsupported type.");
}
Expand Down
13 changes: 12 additions & 1 deletion include/rfl/yaml/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,18 @@ class Writer {
template <class T>
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::remove_cvref_t<T>, std::string>() ||
std::is_same<std::remove_cvref_t<T>, bool>() ||
std::is_floating_point<std::remove_cvref_t<T>>() ||
std::is_same<std::remove_cvref_t<T>,
std::remove_cvref_t<decltype(YAML::Null)>>()) {
(*out_) << YAML::Key << _name.data() << YAML::Value << _var;
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
(*out_) << YAML::Key << _name.data() << YAML::Value
<< static_cast<int64_t>(_var);
} else {
static_assert(rfl::always_false_v<T>, "Unsupported type.");
}
return OutputVarType{};
}

Expand Down
2 changes: 1 addition & 1 deletion tests/yaml/test_snake_case_to_pascal_case.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct Person {
std::vector<Person> 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"};

Expand Down

0 comments on commit 37a0be8

Please sign in to comment.