16 #include <sys/cdefs.h>
30 #include "plugins_internal.h"
44 static size_t integer_lyb_size[] = {
51 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
52 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
62 memset(storage, 0,
sizeof *storage);
67 if (value_len != integer_lyb_size[type->
basetype]) {
69 value_len, integer_lyb_size[type->
basetype]);
76 num = *(int8_t *)value;
79 num = *(int16_t *)value;
82 num = *(int32_t *)value;
85 num = *(int64_t *)value;
95 LY_CHECK_GOTO(ret, cleanup);
100 ret =
lyplg_type_parse_int(
"int8", base, INT64_C(-128), INT64_C(127), value, value_len, &num, err);
103 ret =
lyplg_type_parse_int(
"int16", base, INT64_C(-32768), INT64_C(32767), value, value_len, &num, err);
106 ret =
lyplg_type_parse_int(
"int32", base, INT64_C(-2147483648), INT64_C(2147483647), value, value_len, &num, err);
110 INT64_C(9223372036854775807), value, value_len, &num, err);
116 LY_CHECK_GOTO(ret, cleanup);
125 storage->int16 = num;
128 storage->int32 = num;
131 storage->int64 = num;
142 LY_CHECK_GOTO(ret, cleanup);
145 LY_CHECK_GOTO(ret, cleanup);
149 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRId64, num) == -1, ret =
LY_EMEM, cleanup);
153 LY_CHECK_GOTO(ret, cleanup);
157 if (type_num->
range) {
160 LY_CHECK_GOTO(ret, cleanup);
183 if (val1->int8 != val2->int8) {
188 if (val1->int16 != val2->int16) {
193 if (val1->int32 != val2->int32) {
198 if (val1->int64 != val2->int64) {
210 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
221 return &value->int16;
223 return &value->int32;
225 return &value->int64;
244 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
245 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
255 memset(storage, 0,
sizeof *storage);
260 if (value_len != integer_lyb_size[type->
basetype]) {
262 value_len, integer_lyb_size[type->
basetype]);
269 num = *(uint8_t *)value;
272 num = *(uint16_t *)value;
275 num = *(uint32_t *)value;
278 num = *(uint64_t *)value;
288 LY_CHECK_GOTO(ret, cleanup);
302 ret =
lyplg_type_parse_uint(
"uint64", base, UINT64_C(18446744073709551615), value, value_len, &num, err);
308 LY_CHECK_GOTO(ret, cleanup);
314 storage->uint8 = num;
317 storage->uint16 = num;
320 storage->uint32 = num;
323 storage->uint64 = num;
334 LY_CHECK_GOTO(ret, cleanup);
337 LY_CHECK_GOTO(ret, cleanup);
341 LY_CHECK_ERR_GOTO(asprintf(&canon,
"%" PRIu64, num) == -1, ret =
LY_EMEM, cleanup);
345 LY_CHECK_GOTO(ret, cleanup);
349 if (type_num->
range) {
352 LY_CHECK_GOTO(ret, cleanup);
375 if (val1->uint8 != val2->uint8) {
380 if (val1->uint16 != val2->uint16) {
385 if (val1->uint32 != val2->uint32) {
390 if (val1->uint64 != val2->uint64) {
402 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
411 return &value->uint8;
413 return &value->uint16;
415 return &value->uint32;
417 return &value->uint64;
445 .name = LY_TYPE_UINT8_STR,
447 .plugin.id =
"libyang 2 - integers, version 1",
449 .plugin.validate = NULL,
458 .name = LY_TYPE_UINT16_STR,
460 .plugin.id =
"libyang 2 - integers, version 1",
462 .plugin.validate = NULL,
471 .name = LY_TYPE_UINT32_STR,
473 .plugin.id =
"libyang 2 - integers, version 1",
475 .plugin.validate = NULL,
484 .name = LY_TYPE_UINT64_STR,
486 .plugin.id =
"libyang 2 - integers, version 1",
488 .plugin.validate = NULL,
497 .name = LY_TYPE_INT8_STR,
499 .plugin.id =
"libyang 2 - integers, version 1",
501 .plugin.validate = NULL,
510 .name = LY_TYPE_INT16_STR,
512 .plugin.id =
"libyang 2 - integers, version 1",
514 .plugin.validate = NULL,
523 .name = LY_TYPE_INT32_STR,
525 .plugin.id =
"libyang 2 - integers, version 1",
527 .plugin.validate = NULL,
536 .name = LY_TYPE_INT64_STR,
538 .plugin.id =
"libyang 2 - integers, version 1",
540 .plugin.validate = NULL,
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 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...
LY_ERR
libyang's error codes returned by the libyang functions.
Libyang full error structure.
LY_ERR lyplg_type_check_hints(uint32_t hints, const char *value, size_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.
LY_ERR lyplg_type_validate_range(LY_DATA_TYPE basetype, struct lysc_range *range, int64_t value, const char *strval, size_t strval_len, struct ly_err_item **err)
Data type validator for a range/length-restricted values.
LY_ERR ly_err_new(struct ly_err_item **err, LY_ERR ecode, LY_VECODE vecode, char *path, char *apptag, const char *err_msg,...)
Create and fill error structure.
LY_ERR lyplg_type_parse_int(const char *datatype, int base, int64_t min, int64_t max, const char *value, size_t value_len, int64_t *ret, struct ly_err_item **err)
Unsigned integer value parser and validator.
LY_ERR lyplg_type_parse_uint(const char *datatype, int base, uint64_t max, const char *value, size_t value_len, uint64_t *ret, struct ly_err_item **err)
Unsigned integer value parser and validator.
API LY_ERR lyplg_type_compare_int(const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for the built-in signed integer types.
API LY_ERR lyplg_type_compare_uint(const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for the built-in unsigned integer types.
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.
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
struct lysc_range * range
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
API const void * lyplg_type_print_uint(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *value, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), ly_bool *dynamic, size_t *value_len)
const struct lyplg_type_record plugins_integer[]
Plugin information for integer types implementation.
API const void * lyplg_type_print_int(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *value, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), ly_bool *dynamic, size_t *value_len)
API LY_ERR lyplg_type_store_int(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, size_t value_len, uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints, const struct lysc_node *UNUSED(ctx_node), struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
API LY_ERR lyplg_type_store_uint(const struct ly_ctx *ctx, const struct lysc_type *type, const void *value, size_t value_len, uint32_t options, LY_VALUE_FORMAT format, void *UNUSED(prefix_data), uint32_t hints, const struct lysc_node *UNUSED(ctx_node), struct lyd_value *storage, struct lys_glob_unres *UNUSED(unres), struct ly_err_item **err)
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.