blob: 3b924adc0adb8f0aa89d84587ec27adb06a71c18 [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át0d8abd12020-05-07 02:00:14 +020030 case LY_TYPE_IDENT:
31 return identityRef_{value->ident()->module()->name(), value->ident()->name()};
Jan Kundrát4225b3f2020-01-24 12:58:38 +010032 case LY_TYPE_BINARY:
33 return std::string{value->binary()};
Jan Kundrátbd3169c2020-02-03 19:31:34 +010034 case LY_TYPE_DEC64:
35 {
36 auto v = value->dec64();
37 return v.value * std::pow(10, -v.digits);
38 }
Václav Kubernát02a71152020-01-21 14:52:51 +010039 default: // TODO: implement all types
40 return "(can't print)"s;
41 }
42}