From b68858e6ad77243fc2c2fb348140cd78ed190aac Mon Sep 17 00:00:00 2001 From: Thomas Pedersen Date: Fri, 17 Jan 2020 09:09:08 -0800 Subject: [PATCH] Fixed parsing of u8 (unsigned char) --- include/yaml-cpp/node/convert.h | 17 ++++++++++++++++- include/yaml-cpp/node/impl.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/yaml-cpp/node/convert.h b/include/yaml-cpp/node/convert.h index 51f7d4c..8fbcc4a 100644 --- a/include/yaml-cpp/node/convert.h +++ b/include/yaml-cpp/node/convert.h @@ -68,6 +68,21 @@ struct convert { } }; +template <> +struct convert { + static Node encode(const unsigned char& rhs) { Node n; n = rhs; return n; } + + static bool decode(const Node& node, unsigned char& rhs) { + if (node.Type() != NodeType::Scalar) { + return false; + } + int t = stoi(node.Scalar()); + if(t < 0 || t > 255) return false; + rhs = (unsigned char)t; + return true; + } +}; + // C-strings can only be encoded template <> struct convert { @@ -146,7 +161,7 @@ YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned long long); YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(char); YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(signed char); -YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned char); +//YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned char); YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(float); YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(double); diff --git a/include/yaml-cpp/node/impl.h b/include/yaml-cpp/node/impl.h index 06a4884..9ffc84d 100644 --- a/include/yaml-cpp/node/impl.h +++ b/include/yaml-cpp/node/impl.h @@ -116,6 +116,7 @@ struct as_if { } }; + template struct as_if { explicit as_if(const Node& node_) : node(node_) {}