blob: 0fcce7d680aca55e722f46e349ba81167d65fb32 [file] [log] [blame]
Václav Kubernátcbdc98a2021-01-28 13:24:37 +01001#include <libyang/Tree_Data.hpp>
2#include "utils/libyang.h"
3
4const char* getValueAsString(const libyang::S_Data_Node& node)
5{
6 if (!node || node->schema()->nodetype() != LYS_LEAF) {
7 throw std::logic_error("retrieveString: invalid node");
8 }
9
10 return libyang::Data_Node_Leaf_List(node).value_str();
11}
12
13libyang::S_Data_Node getSubtree(const libyang::S_Data_Node& start, const char* path)
14{
15 auto set = start->find_path(path);
16 if (set->number() != 1) {
17 throw std::runtime_error("getSubtree: didn't get exactly one match (got " + std::to_string(set->number()) + ")");
18 }
19
20 return set->data().front();
21}