blob: 9051e1616267692425c345bb67d37c92573c1994 [file] [log] [blame]
Václav Kubernát02a71152020-01-21 14:52:51 +01001#include "libyang_utils.hpp"
Jan Kundrátbd3169c2020-02-03 19:31:34 +01002#include <cmath>
Václav Kubernát02a71152020-01-21 14:52:51 +01003
4leaf_data_ leafValueFromValue(const libyang::S_Value& value, LY_DATA_TYPE type)
5{
6 using namespace std::string_literals;
7 switch (type) {
8 case LY_TYPE_INT8:
9 return value->int8();
10 case LY_TYPE_INT16:
11 return value->int16();
12 case LY_TYPE_INT32:
13 return value->int32();
14 case LY_TYPE_INT64:
15 return value->int64();
16 case LY_TYPE_UINT8:
17 return value->uint8();
18 case LY_TYPE_UINT16:
19 return value->uint16();
20 case LY_TYPE_UINT32:
Jan Kundrátcc2538f2020-02-03 11:33:42 +010021 return value->uint32();
Václav Kubernát02a71152020-01-21 14:52:51 +010022 case LY_TYPE_UINT64:
23 return value->uint64();
24 case LY_TYPE_BOOL:
25 return bool(value->bln());
26 case LY_TYPE_STRING:
27 return std::string(value->string());
28 case LY_TYPE_ENUM:
29 return enum_{std::string(value->enm()->name())};
Jan Kundrát4225b3f2020-01-24 12:58:38 +010030 case LY_TYPE_BINARY:
31 return std::string{value->binary()};
Jan Kundrátbd3169c2020-02-03 19:31:34 +010032 case LY_TYPE_DEC64:
33 {
34 auto v = value->dec64();
35 return v.value * std::pow(10, -v.digits);
36 }
Václav Kubernát02a71152020-01-21 14:52:51 +010037 default: // TODO: implement all types
38 return "(can't print)"s;
39 }
40}