28 #include "plugins_internal.h"
42 static size_t integer_lyb_size[] = {
49 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
50 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
60 memset(storage, 0,
sizeof *storage);
65 if (value_len != integer_lyb_size[type->
basetype]) {
67 value_len, integer_lyb_size[type->
basetype]);
72 memcpy(&num, value, value_len);
77 LY_CHECK_GOTO(ret, cleanup);
82 ret =
lyplg_type_parse_int(
"int8", base, INT64_C(-128), INT64_C(127), value, value_len, &num, err);
85 ret =
lyplg_type_parse_int(
"int16", base, INT64_C(-32768), INT64_C(32767), value, value_len, &num, err);
88 ret =
lyplg_type_parse_int(
"int32", base, INT64_C(-2147483648), INT64_C(2147483647), value, value_len, &num, err);
92 INT64_C(9223372036854775807), value, value_len, &num, err);
98 LY_CHECK_GOTO(ret, cleanup);
108 storage->int16 = num;
109 num = storage->int16;
112 storage->int32 = num;
113 num = storage->int32;
116 storage->int64 = num;
117 num = storage->int64;
128 LY_CHECK_GOTO(ret, cleanup);
131 LY_CHECK_GOTO(ret, cleanup);
137 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId8, storage->int8) == -1, ret =
LY_EMEM, cleanup);
140 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId16, storage->int16) == -1, ret =
LY_EMEM, cleanup);
143 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId32, storage->int32) == -1, ret =
LY_EMEM, cleanup);
146 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId64, storage->int64) == -1, ret =
LY_EMEM, cleanup);
154 LY_CHECK_GOTO(ret, cleanup);
158 if (type_num->
range) {
161 LY_CHECK_GOTO(ret, cleanup);
184 if (val1->int8 != val2->int8) {
189 if (val1->int16 != val2->int16) {
194 if (val1->int32 != val2->int32) {
199 if (val1->int64 != val2->int64) {
209 LIBYANG_API_DEF
const void *
211 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
213 int64_t prev_num = 0, num = 0;
219 prev_num = num = value->int8;
222 prev_num = num = value->int16;
225 prev_num = num = value->int32;
228 prev_num = num = value->int64;
234 if (num == prev_num) {
240 return &value->int64;
244 LY_CHECK_RET(!buf, NULL);
267 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
268 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
278 memset(storage, 0,
sizeof *storage);
283 if (value_len != integer_lyb_size[type->
basetype]) {
285 value_len, integer_lyb_size[type->
basetype]);
290 memcpy(&num, value, value_len);
295 LY_CHECK_GOTO(ret, cleanup);
309 ret =
lyplg_type_parse_uint(
"uint64", base, UINT64_C(18446744073709551615), value, value_len, &num, err);
315 LY_CHECK_GOTO(ret, cleanup);
321 storage->uint8 = num;
324 storage->uint16 = num;
327 storage->uint32 = num;
330 storage->uint64 = num;
341 LY_CHECK_GOTO(ret, cleanup);
344 LY_CHECK_GOTO(ret, cleanup);
348 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRIu64, num) == -1, ret =
LY_EMEM, cleanup);
352 LY_CHECK_GOTO(ret, cleanup);
356 if (type_num->
range) {
359 LY_CHECK_GOTO(ret, cleanup);
382 if (val1->uint8 != val2->uint8) {
387 if (val1->uint16 != val2->uint16) {
392 if (val1->uint32 != val2->uint32) {
397 if (val1->uint64 != val2->uint64) {
407 LIBYANG_API_DEF
const void *
409 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
432 if (num == value->uint64) {
438 return &value->uint64;
442 LY_CHECK_RET(!buf, NULL);
474 .name = LY_TYPE_UINT8_STR,
476 .plugin.id =
"libyang 2 - integers, version 1",
478 .plugin.validate = NULL,
484 .plugin.lyb_data_len = 1,
488 .name = LY_TYPE_UINT16_STR,
490 .plugin.id =
"libyang 2 - integers, version 1",
492 .plugin.validate = NULL,
498 .plugin.lyb_data_len = 2,
502 .name = LY_TYPE_UINT32_STR,
504 .plugin.id =
"libyang 2 - integers, version 1",
506 .plugin.validate = NULL,
512 .plugin.lyb_data_len = 4,
516 .name = LY_TYPE_UINT64_STR,
518 .plugin.id =
"libyang 2 - integers, version 1",
520 .plugin.validate = NULL,
526 .plugin.lyb_data_len = 8,
530 .name = LY_TYPE_INT8_STR,
532 .plugin.id =
"libyang 2 - integers, version 1",
534 .plugin.validate = NULL,
540 .plugin.lyb_data_len = 1,
544 .name = LY_TYPE_INT16_STR,
546 .plugin.id =
"libyang 2 - integers, version 1",
548 .plugin.validate = NULL,
554 .plugin.lyb_data_len = 2,
558 .name = LY_TYPE_INT32_STR,
560 .plugin.id =
"libyang 2 - integers, version 1",
562 .plugin.validate = NULL,
568 .plugin.lyb_data_len = 4,
572 .name = LY_TYPE_INT64_STR,
574 .plugin.id =
"libyang 2 - integers, version 1",
576 .plugin.validate = NULL,
582 .plugin.lyb_data_len = 8,