libyang: support working with the decimal64 type
Change-Id: I3a36658fe810089970a99d71003124b3041ee6a0
diff --git a/src/libyang_utils.cpp b/src/libyang_utils.cpp
index df90db4..9051e16 100644
--- a/src/libyang_utils.cpp
+++ b/src/libyang_utils.cpp
@@ -1,4 +1,5 @@
#include "libyang_utils.hpp"
+#include <cmath>
leaf_data_ leafValueFromValue(const libyang::S_Value& value, LY_DATA_TYPE type)
{
@@ -28,6 +29,11 @@
return enum_{std::string(value->enm()->name())};
case LY_TYPE_BINARY:
return std::string{value->binary()};
+ case LY_TYPE_DEC64:
+ {
+ auto v = value->dec64();
+ return v.value * std::pow(10, -v.digits);
+ }
default: // TODO: implement all types
return "(can't print)"s;
}
diff --git a/tests/datastore_access.cpp b/tests/datastore_access.cpp
index 88b05c3..093f348 100644
--- a/tests/datastore_access.cpp
+++ b/tests/datastore_access.cpp
@@ -288,6 +288,17 @@
}
+ SECTION("floats")
+ {
+ datastore.setLeaf("/example-schema:leafDecimal", 123.4);
+ REQUIRE_CALL(mock, write("/example-schema:leafDecimal", std::nullopt, "123.4"s));
+ datastore.commitChanges();
+ DatastoreAccess::Tree expected {
+ {"/example-schema:leafDecimal", 123.4},
+ };
+ REQUIRE(datastore.getItems("/example-schema:leafDecimal") == expected);
+ }
+
waitForCompletionAndBitMore(seq1);
}