Made sure uint8_t is properly handled by YAML; #270 (#311)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2024-12-22 19:14:16 +01:00
committed by GitHub
parent 23ce24f001
commit 896c4a4132
3 changed files with 16 additions and 4 deletions
+3 -2
View File
@@ -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.");
}
+12 -1
View File
@@ -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{};
}
@@ -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"};