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, uint64_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 if (value_size >
sizeof num) {
72 lys_datatype2str(type->
basetype), value_size,
sizeof num);
73 LY_CHECK_GOTO(ret, cleanup);
75 memcpy(&num, value, value_size);
80 LY_CHECK_GOTO(ret, cleanup);
85 ret =
lyplg_type_parse_int(
"int8", base, INT64_C(-128), INT64_C(127), value, value_size, &num, err);
88 ret =
lyplg_type_parse_int(
"int16", base, INT64_C(-32768), INT64_C(32767), value, value_size, &num, err);
91 ret =
lyplg_type_parse_int(
"int32", base, INT64_C(-2147483648), INT64_C(2147483647), value, value_size, &num, err);
95 INT64_C(9223372036854775807), value, value_size, &num, err);
101 LY_CHECK_GOTO(ret, cleanup);
111 storage->int16 = num;
112 num = storage->int16;
115 storage->int32 = num;
116 num = storage->int32;
119 storage->int64 = num;
120 num = storage->int64;
131 LY_CHECK_GOTO(ret, cleanup);
134 LY_CHECK_GOTO(ret, cleanup);
140 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId8, storage->int8) == -1, ret =
LY_EMEM, cleanup);
143 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId16, storage->int16) == -1, ret =
LY_EMEM, cleanup);
146 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId32, storage->int32) == -1, ret =
LY_EMEM, cleanup);
149 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId64, storage->int64) == -1, ret =
LY_EMEM, cleanup);
157 LY_CHECK_GOTO(ret, cleanup);
162 ret = lyplg_type_validate_value_int(ctx, type, storage, err);
163 LY_CHECK_GOTO(ret, cleanup);
181lyplg_type_validate_value_int(
const struct ly_ctx *UNUSED(ctx),
const struct lysc_type *type,
struct lyd_value *storage,
188 LY_CHECK_ARG_RET(NULL, type, storage, err,
LY_EINVAL);
197 num = storage->int16;
200 num = storage->int32;
203 num = storage->int64;
210 if (type_num->
range) {
228 if (val1->int8 != val2->int8) {
233 if (val1->int16 != val2->int16) {
238 if (val1->int32 != val2->int32) {
243 if (val1->int64 != val2->int64) {
258 if (val1->int8 < val2->int8) {
260 }
else if (val1->int8 > val2->int8) {
267 if (val1->int16 < val2->int16) {
269 }
else if (val1->int16 > val2->int16) {
276 if (val1->int32 < val2->int32) {
278 }
else if (val1->int32 > val2->int32) {
285 if (val1->int64 < val2->int64) {
287 }
else if (val1->int64 > val2->int64) {
300lyplg_type_store_uint(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value, uint64_t value_size_bits,
301 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
302 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
312 memset(storage, 0,
sizeof *storage);
318 LY_CHECK_GOTO(ret, cleanup);
322 if (value_size >
sizeof num) {
324 lys_datatype2str(type->
basetype), value_size,
sizeof num);
325 LY_CHECK_GOTO(ret, cleanup);
327 memcpy(&num, value, value_size);
332 LY_CHECK_GOTO(ret, cleanup);
346 ret =
lyplg_type_parse_uint(
"uint64", base, UINT64_C(18446744073709551615), value, value_size, &num, err);
352 LY_CHECK_GOTO(ret, cleanup);
358 storage->uint8 = num;
361 storage->uint16 = num;
364 storage->uint32 = num;
367 storage->uint64 = num;
378 LY_CHECK_GOTO(ret, cleanup);
381 LY_CHECK_GOTO(ret, cleanup);
385 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRIu64, num) == -1, ret =
LY_EMEM, cleanup);
389 LY_CHECK_GOTO(ret, cleanup);
394 ret = lyplg_type_validate_value_uint(ctx, type, storage, err);
395 LY_CHECK_GOTO(ret, cleanup);
413lyplg_type_validate_value_uint(
const struct ly_ctx *UNUSED(ctx),
const struct lysc_type *type,
struct lyd_value *storage,
420 LY_CHECK_ARG_RET(NULL, type, storage, err,
LY_EINVAL);
426 num = storage->uint8;
429 num = storage->uint16;
432 num = storage->uint32;
435 num = storage->uint64;
442 if (type_num->
range) {
452lyplg_type_compare_uint(
const struct ly_ctx *UNUSED(ctx),
const struct lyd_value *val1,
const struct lyd_value *val2)
456 if (val1->uint8 != val2->uint8) {
461 if (val1->uint16 != val2->uint16) {
466 if (val1->uint32 != val2->uint32) {
471 if (val1->uint64 != val2->uint64) {
486 if (val1->uint8 < val2->uint8) {
488 }
else if (val1->uint8 > val2->uint8) {
495 if (val1->uint16 < val2->uint16) {
497 }
else if (val1->uint16 > val2->uint16) {
504 if (val1->uint32 < val2->uint32) {
506 }
else if (val1->uint32 > val2->uint32) {
513 if (val1->uint64 < val2->uint64) {
515 }
else if (val1->uint64 > val2->uint64) {
529 void *UNUSED(prefix_data),
ly_bool *dynamic, uint64_t *value_size_bits)
558 if (htole64(num) == value->uint64) {
561 if (value_size_bits) {
565 return &value->uint64;
571 buf = calloc(1, bytes_used);
572 LY_CHECK_RET(!buf, NULL);
574 memcpy(buf, &num, bytes_used);
577 if (value_size_bits) {
578 *value_size_bits = bits_used;
588 if (value_size_bits) {
589 *value_size_bits = strlen(value->
_canonical) * 8;
605 .name = LY_TYPE_UINT8_STR,
607 .plugin.id =
"ly2 integers",
609 .plugin.store = lyplg_type_store_uint,
610 .plugin.validate_value = lyplg_type_validate_value_uint,
611 .plugin.validate_tree = NULL,
612 .plugin.compare = lyplg_type_compare_uint,
613 .plugin.sort = lyplg_type_sort_uint,
614 .plugin.print = lyplg_type_print_u_int,
620 .name = LY_TYPE_UINT16_STR,
622 .plugin.id =
"ly2 integers",
624 .plugin.store = lyplg_type_store_uint,
625 .plugin.validate_value = lyplg_type_validate_value_uint,
626 .plugin.validate_tree = NULL,
627 .plugin.compare = lyplg_type_compare_uint,
628 .plugin.sort = lyplg_type_sort_uint,
629 .plugin.print = lyplg_type_print_u_int,
635 .name = LY_TYPE_UINT32_STR,
637 .plugin.id =
"ly2 integers",
639 .plugin.store = lyplg_type_store_uint,
640 .plugin.validate_value = lyplg_type_validate_value_uint,
641 .plugin.validate_tree = NULL,
642 .plugin.compare = lyplg_type_compare_uint,
643 .plugin.sort = lyplg_type_sort_uint,
644 .plugin.print = lyplg_type_print_u_int,
650 .name = LY_TYPE_UINT64_STR,
652 .plugin.id =
"ly2 integers",
654 .plugin.store = lyplg_type_store_uint,
655 .plugin.validate_value = lyplg_type_validate_value_uint,
656 .plugin.validate_tree = NULL,
657 .plugin.compare = lyplg_type_compare_uint,
658 .plugin.sort = lyplg_type_sort_uint,
659 .plugin.print = lyplg_type_print_u_int,
665 .name = LY_TYPE_INT8_STR,
667 .plugin.id =
"ly2 integers",
669 .plugin.store = lyplg_type_store_int,
670 .plugin.validate_value = lyplg_type_validate_value_int,
671 .plugin.validate_tree = NULL,
672 .plugin.compare = lyplg_type_compare_int,
673 .plugin.sort = lyplg_type_sort_int,
674 .plugin.print = lyplg_type_print_u_int,
680 .name = LY_TYPE_INT16_STR,
682 .plugin.id =
"ly2 integers",
684 .plugin.store = lyplg_type_store_int,
685 .plugin.validate_value = lyplg_type_validate_value_int,
686 .plugin.validate_tree = NULL,
687 .plugin.compare = lyplg_type_compare_int,
688 .plugin.sort = lyplg_type_sort_int,
689 .plugin.print = lyplg_type_print_u_int,
695 .name = LY_TYPE_INT32_STR,
697 .plugin.id =
"ly2 integers",
699 .plugin.store = lyplg_type_store_int,
700 .plugin.validate_value = lyplg_type_validate_value_int,
701 .plugin.validate_tree = NULL,
702 .plugin.compare = lyplg_type_compare_int,
703 .plugin.sort = lyplg_type_sort_int,
704 .plugin.print = lyplg_type_print_u_int,
710 .name = LY_TYPE_INT64_STR,
712 .plugin.id =
"ly2 integers",
714 .plugin.store = lyplg_type_store_int,
715 .plugin.validate_value = lyplg_type_validate_value_int,
716 .plugin.validate_tree = NULL,
717 .plugin.compare = lyplg_type_compare_int,
718 .plugin.sort = lyplg_type_sort_int,
719 .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_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.
LIBYANG_API_DECL LY_ERR lyplg_type_check_value_size(const char *type_name, LY_VALUE_FORMAT format, uint64_t value_size_bits, enum lyplg_lyb_size_type lyb_size_type, uint64_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 ly_err_new(struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *data_path, char *apptag, const char *err_format,...) _FORMAT_PRINTF(6
Create and fill error structure.
#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, uint64_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.