28 #include "plugins_internal.h"
48 decimal64_num2str(int64_t num,
struct lysc_type_dec *type,
char **str)
53 ret = calloc(1, LY_NUMBER_MAXLEN);
57 int count = sprintf(ret,
"%" PRId64
" ", num);
66 if (j && (i > 1) && (ret[count - 2] ==
'0')) {
68 ret[count - 1] =
'\0';
71 ret[count - 1] = ret[count - 2];
87 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
88 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
97 memset(storage, 0,
sizeof *storage);
102 if (value_len != 8) {
109 num = *(int64_t *)value;
113 LY_CHECK_GOTO(ret, cleanup);
117 LY_CHECK_GOTO(ret, cleanup);
121 storage->dec64 = num;
129 LY_CHECK_GOTO(ret, cleanup);
132 LY_CHECK_GOTO(ret, cleanup);
136 ret = decimal64_num2str(num, type_dec, &canon);
137 LY_CHECK_GOTO(ret, cleanup);
141 LY_CHECK_GOTO(ret, cleanup);
144 if (type_dec->
range) {
148 LY_CHECK_GOTO(ret, cleanup);
170 if (val1->dec64 != val2->dec64) {
178 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
183 *value_len =
sizeof value->dec64;
185 return &value->dec64;
209 .name = LY_TYPE_DEC64_STR,
211 .plugin.id =
"libyang 2 - decimal64, version 1",
213 .plugin.validate = NULL,
const struct lyplg_type_record plugins_decimal64[]
Plugin information for decimal64 type implementation.
API LY_ERR lyplg_type_store_decimal64(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 const void * lyplg_type_print_decimal64(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)
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.
API LY_ERR lyplg_type_compare_decimal64(const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for the built-in decimal64 type.
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_parse_dec64(uint8_t fraction_digits, const char *value, size_t value_len, int64_t *ret, struct ly_err_item **err)
Convert a string with a decimal64 value into libyang representation: ret = value * 10^fraction-digits...
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_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.
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.