25#include "plugins_internal.h"
45decimal64_num2str(int64_t num,
struct lysc_type_dec *type,
char **str)
50 ret = calloc(1, LY_NUMBER_MAXLEN);
54 int count = sprintf(ret,
"%" PRId64
" ", num);
61 count = sprintf(ret,
"%0*" PRId64
" ", (num > 0) ? (type->
fraction_digits + 1) : (type->fraction_digits + 2), num);
64 if (j && (i > 1) && (ret[count - 2] ==
'0')) {
66 ret[count - 1] =
'\0';
69 ret[count - 1] = ret[count - 2];
85 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
86 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
95 memset(storage, 0,
sizeof *storage);
100 if (value_len != 8) {
107 memcpy(&num, value, value_len);
112 LY_CHECK_GOTO(ret, cleanup);
116 LY_CHECK_GOTO(ret, cleanup);
120 storage->dec64 = num;
127 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
128 LY_CHECK_GOTO(ret, cleanup);
131 LY_CHECK_GOTO(ret, cleanup);
135 ret = decimal64_num2str(num, type_dec, &canon);
136 LY_CHECK_GOTO(ret, cleanup);
140 LY_CHECK_GOTO(ret, cleanup);
145 if (type_dec->
range) {
149 LY_CHECK_GOTO(ret, cleanup);
169 if (val1->dec64 != val2->dec64) {
178 if (val1->dec64 > val2->dec64) {
180 }
else if (val1->dec64 < val2->dec64) {
187LIBYANG_API_DEF
const void *
189 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
195 num = htole64(value->dec64);
196 if (num == value->dec64) {
200 *value_len =
sizeof value->dec64;
202 return &value->dec64;
205 buf = calloc(1,
sizeof value->dec64);
206 LY_CHECK_RET(!buf, NULL);
210 *value_len =
sizeof value->dec64;
212 memcpy(buf, &num,
sizeof value->dec64);
238 .name = LY_TYPE_DEC64_STR,
240 .plugin.id =
"libyang 2 - decimal64, version 1",
242 .plugin.validate = NULL,
248 .plugin.lyb_data_len = 8,
LIBYANG_API_DEF 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)
LIBYANG_API_DEF 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)
const struct lyplg_type_record plugins_decimal64[]
Plugin information for decimal64 type implementation.
LIBYANG_API_DEF int lyplg_type_sort_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
LIBYANG_API_DEF LY_ERR lyplg_type_compare_decimal64(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
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.
const char *const char * revision
LIBYANG_API_DECL 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.
LIBYANG_API_DECL 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.
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.
LIBYANG_API_DECL 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...
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.
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.