Refactor leafValueFromValue

This function will be useful in other libyang enabled contexts.

Change-Id: Iae808d892be27749571f5086fac7af17290953e8
diff --git a/src/libyang_utils.cpp b/src/libyang_utils.cpp
new file mode 100644
index 0000000..0885c64
--- /dev/null
+++ b/src/libyang_utils.cpp
@@ -0,0 +1,32 @@
+#include "libyang_utils.hpp"
+
+leaf_data_ leafValueFromValue(const libyang::S_Value& value, LY_DATA_TYPE type)
+{
+    using namespace std::string_literals;
+    switch (type) {
+    case LY_TYPE_INT8:
+        return value->int8();
+    case LY_TYPE_INT16:
+        return value->int16();
+    case LY_TYPE_INT32:
+        return value->int32();
+    case LY_TYPE_INT64:
+        return value->int64();
+    case LY_TYPE_UINT8:
+        return value->uint8();
+    case LY_TYPE_UINT16:
+        return value->uint16();
+    case LY_TYPE_UINT32:
+        return value->uintu32();
+    case LY_TYPE_UINT64:
+        return value->uint64();
+    case LY_TYPE_BOOL:
+        return bool(value->bln());
+    case LY_TYPE_STRING:
+        return std::string(value->string());
+    case LY_TYPE_ENUM:
+        return enum_{std::string(value->enm()->name())};
+    default: // TODO: implement all types
+        return "(can't print)"s;
+    }
+}