30#include "plugins_internal.h"
31#include "tree_schema_internal.h"
48lyplg_type_store_int(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value, uint32_t value_size_bits,
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);
66 LY_CHECK_GOTO(ret, cleanup);
70 memcpy(&num, value, value_size);
75 LY_CHECK_GOTO(ret, cleanup);
80 ret =
lyplg_type_parse_int(
"int8", base, INT64_C(-128), INT64_C(127), value, value_size, &num, err);
83 ret =
lyplg_type_parse_int(
"int16", base, INT64_C(-32768), INT64_C(32767), value, value_size, &num, err);
86 ret =
lyplg_type_parse_int(
"int32", base, INT64_C(-2147483648), INT64_C(2147483647), value, value_size, &num, err);
90 INT64_C(9223372036854775807), value, value_size, &num, err);
96 LY_CHECK_GOTO(ret, cleanup);
106 storage->int16 = num;
107 num = storage->int16;
110 storage->int32 = num;
111 num = storage->int32;
114 storage->int64 = num;
115 num = storage->int64;
126 LY_CHECK_GOTO(ret, cleanup);
129 LY_CHECK_GOTO(ret, cleanup);
135 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId8, storage->int8) == -1, ret =
LY_EMEM, cleanup);
138 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId16, storage->int16) == -1, ret =
LY_EMEM, cleanup);
141 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId32, storage->int32) == -1, ret =
LY_EMEM, cleanup);
144 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId64, storage->int64) == -1, ret =
LY_EMEM, cleanup);
152 LY_CHECK_GOTO(ret, cleanup);
157 ret = lyplg_type_validate_value_int(ctx, type, storage, err);
158 LY_CHECK_GOTO(ret, cleanup);
176lyplg_type_validate_value_int(
const struct ly_ctx *UNUSED(ctx),
const struct lysc_type *type,
struct lyd_value *storage,
183 LY_CHECK_ARG_RET(NULL, type, storage, err,
LY_EINVAL);
192 num = storage->int16;
195 num = storage->int32;
198 num = storage->int64;
205 if (type_num->
range) {
223 if (val1->int8 != val2->int8) {
228 if (val1->int16 != val2->int16) {
233 if (val1->int32 != val2->int32) {
238 if (val1->int64 != val2->int64) {
253 if (val1->int8 < val2->int8) {
255 }
else if (val1->int8 > val2->int8) {
262 if (val1->int16 < val2->int16) {
264 }
else if (val1->int16 > val2->int16) {
271 if (val1->int32 < val2->int32) {
273 }
else if (val1->int32 > val2->int32) {
280 if (val1->int64 < val2->int64) {
282 }
else if (val1->int64 > val2->int64) {
295lyplg_type_store_uint(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value, uint32_t value_size_bits,
296 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
297 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
307 memset(storage, 0,
sizeof *storage);
313 LY_CHECK_GOTO(ret, cleanup);
317 memcpy(&num, value, value_size);
322 LY_CHECK_GOTO(ret, cleanup);
336 ret =
lyplg_type_parse_uint(
"uint64", base, UINT64_C(18446744073709551615), value, value_size, &num, err);
342 LY_CHECK_GOTO(ret, cleanup);
348 storage->uint8 = num;
351 storage->uint16 = num;
354 storage->uint32 = num;
357 storage->uint64 = num;
368 LY_CHECK_GOTO(ret, cleanup);
371 LY_CHECK_GOTO(ret, cleanup);
375 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRIu64, num) == -1, ret =
LY_EMEM, cleanup);
379 LY_CHECK_GOTO(ret, cleanup);
384 ret = lyplg_type_validate_value_uint(ctx, type, storage, err);
385 LY_CHECK_GOTO(ret, cleanup);
403lyplg_type_validate_value_uint(
const struct ly_ctx *UNUSED(ctx),
const struct lysc_type *type,
struct lyd_value *storage,
410 LY_CHECK_ARG_RET(NULL, type, storage, err,
LY_EINVAL);
416 num = storage->uint8;
419 num = storage->uint16;
422 num = storage->uint32;
425 num = storage->uint64;
432 if (type_num->
range) {
442lyplg_type_compare_uint(
const struct ly_ctx *UNUSED(ctx),
const struct lyd_value *val1,
const struct lyd_value *val2)
446 if (val1->uint8 != val2->uint8) {
451 if (val1->uint16 != val2->uint16) {
456 if (val1->uint32 != val2->uint32) {
461 if (val1->uint64 != val2->uint64) {
476 if (val1->uint8 < val2->uint8) {
478 }
else if (val1->uint8 > val2->uint8) {
485 if (val1->uint16 < val2->uint16) {
487 }
else if (val1->uint16 > val2->uint16) {
494 if (val1->uint32 < val2->uint32) {
496 }
else if (val1->uint32 > val2->uint32) {
503 if (val1->uint64 < val2->uint64) {
505 }
else if (val1->uint64 > val2->uint64) {
519 void *UNUSED(prefix_data),
ly_bool *dynamic, uint32_t *value_size_bits)
548 if (htole64(num) == value->uint64) {
551 if (value_size_bits) {
555 return &value->uint64;
561 buf = calloc(1, bytes_used);
562 LY_CHECK_RET(!buf, NULL);
564 memcpy(buf, &num, bytes_used);
567 if (value_size_bits) {
568 *value_size_bits = bits_used;
578 if (value_size_bits) {
579 *value_size_bits = strlen(value->
_canonical) * 8;
595 .name = LY_TYPE_UINT8_STR,
597 .plugin.id =
"ly2 integers",
599 .plugin.store = lyplg_type_store_uint,
600 .plugin.validate_value = lyplg_type_validate_value_uint,
601 .plugin.validate_tree = NULL,
602 .plugin.compare = lyplg_type_compare_uint,
603 .plugin.sort = lyplg_type_sort_uint,
604 .plugin.print = lyplg_type_print_u_int,
610 .name = LY_TYPE_UINT16_STR,
612 .plugin.id =
"ly2 integers",
614 .plugin.store = lyplg_type_store_uint,
615 .plugin.validate_value = lyplg_type_validate_value_uint,
616 .plugin.validate_tree = NULL,
617 .plugin.compare = lyplg_type_compare_uint,
618 .plugin.sort = lyplg_type_sort_uint,
619 .plugin.print = lyplg_type_print_u_int,
625 .name = LY_TYPE_UINT32_STR,
627 .plugin.id =
"ly2 integers",
629 .plugin.store = lyplg_type_store_uint,
630 .plugin.validate_value = lyplg_type_validate_value_uint,
631 .plugin.validate_tree = NULL,
632 .plugin.compare = lyplg_type_compare_uint,
633 .plugin.sort = lyplg_type_sort_uint,
634 .plugin.print = lyplg_type_print_u_int,
640 .name = LY_TYPE_UINT64_STR,
642 .plugin.id =
"ly2 integers",
644 .plugin.store = lyplg_type_store_uint,
645 .plugin.validate_value = lyplg_type_validate_value_uint,
646 .plugin.validate_tree = NULL,
647 .plugin.compare = lyplg_type_compare_uint,
648 .plugin.sort = lyplg_type_sort_uint,
649 .plugin.print = lyplg_type_print_u_int,
655 .name = LY_TYPE_INT8_STR,
657 .plugin.id =
"ly2 integers",
659 .plugin.store = lyplg_type_store_int,
660 .plugin.validate_value = lyplg_type_validate_value_int,
661 .plugin.validate_tree = NULL,
662 .plugin.compare = lyplg_type_compare_int,
663 .plugin.sort = lyplg_type_sort_int,
664 .plugin.print = lyplg_type_print_u_int,
670 .name = LY_TYPE_INT16_STR,
672 .plugin.id =
"ly2 integers",
674 .plugin.store = lyplg_type_store_int,
675 .plugin.validate_value = lyplg_type_validate_value_int,
676 .plugin.validate_tree = NULL,
677 .plugin.compare = lyplg_type_compare_int,
678 .plugin.sort = lyplg_type_sort_int,
679 .plugin.print = lyplg_type_print_u_int,
685 .name = LY_TYPE_INT32_STR,
687 .plugin.id =
"ly2 integers",
689 .plugin.store = lyplg_type_store_int,
690 .plugin.validate_value = lyplg_type_validate_value_int,
691 .plugin.validate_tree = NULL,
692 .plugin.compare = lyplg_type_compare_int,
693 .plugin.sort = lyplg_type_sort_int,
694 .plugin.print = lyplg_type_print_u_int,
700 .name = LY_TYPE_INT64_STR,
702 .plugin.id =
"ly2 integers",
704 .plugin.store = lyplg_type_store_int,
705 .plugin.validate_value = lyplg_type_validate_value_int,
706 .plugin.validate_tree = NULL,
707 .plugin.compare = lyplg_type_compare_int,
708 .plugin.sort = lyplg_type_sort_int,
709 .plugin.print = lyplg_type_print_u_int,
LIBYANG_API_DECL LY_ERR lydict_insert(const struct ly_ctx *ctx, const char *value, size_t len, const char **str_p)
Insert string into dictionary. If the string is already present, only a reference counter is incremen...
LIBYANG_API_DECL LY_ERR lydict_insert_zc(const struct ly_ctx *ctx, char *value, const char **str_p)
Insert string into dictionary - zerocopy version. If the string is already present,...
LY_ERR
libyang's error codes returned by the libyang functions.
Libyang full error structure.
LIBYANG_API_DECL LY_ERR lyplg_type_check_hints(uint32_t hints, const char *value, uint32_t value_len, LY_DATA_TYPE type, int *base, struct ly_err_item **err)
Check that the type is suitable for the parser's hints (if any) in the specified format.
LIBYANG_API_DECL LY_ERR lyplg_type_parse_uint(const char *datatype, int base, uint64_t max, const char *value, uint32_t value_len, uint64_t *ret, struct ly_err_item **err)
Unsigned integer value parser and validator.
LIBYANG_API_DECL LY_ERR lyplg_type_parse_int(const char *datatype, int base, int64_t min, int64_t max, const char *value, uint32_t value_len, int64_t *ret, struct ly_err_item **err)
Unsigned integer value parser and validator.
LIBYANG_API_DECL uint64_t lyplg_type_get_highest_set_bit_pos(uint64_t num)
Learn the position of the highest set bit in a number. Represents also the least amount of bits requi...
LIBYANG_API_DECL LY_ERR lyplg_type_check_value_size(const char *type_name, LY_VALUE_FORMAT format, uint32_t value_size_bits, enum lyplg_lyb_size_type lyb_size_type, uint32_t lyb_fixed_size_bits, uint32_t *value_size, struct ly_err_item **err)
Check a value type in bits is correct and as expected.
LIBYANG_API_DECL LY_ERR lyplg_type_validate_range(LY_DATA_TYPE basetype, struct lysc_range *range, int64_t value, const char *strval, uint32_t strval_len, struct ly_err_item **err)
Data type validator for a range/length-restricted values.
#define LYPLG_BITS2BYTES(bits)
Convert bits to bytes.
@ LYPLG_LYB_SIZE_VARIABLE_BITS
LIBYANG_API_DECL void lyplg_type_lyb_size_variable_bits(const struct lysc_type *type, enum lyplg_lyb_size_type *size_type, uint32_t *fixed_size_bits)
Implementation of lyplg_type_lyb_size_clb for a type with variable length in bits.
LIBYANG_API_DECL LY_ERR lyplg_type_dup_simple(const struct ly_ctx *ctx, const struct lyd_value *original, struct lyd_value *dup)
Implementation of lyplg_type_dup_clb for a generic simple type.
LIBYANG_API_DECL void lyplg_type_free_simple(const struct ly_ctx *ctx, struct lyd_value *value)
Implementation of lyplg_type_free_clb for a generic simple type.
#define LYPLG_TYPE_STORE_DYNAMIC
#define LYPLG_TYPE_STORE_ONLY
struct lysc_range * range
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
const struct lyplg_type_record plugins_integer[]
Plugin information for integer types implementation.
The main libyang public header.
uint8_t ly_bool
Type to indicate boolean value.
API for (user) types plugins.
const struct lysc_type * realtype
YANG data representation.