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