27 #include "ly_common.h"
28 #include "plugins_internal.h"
41 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
42 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
53 memset(storage, 0,
sizeof *storage);
65 memcpy(&num, value, value_len);
71 if (type_enum->
enums[u].value == num_val) {
84 storage->enum_item = &type_enum->
enums[u];
88 LY_CHECK_GOTO(ret, cleanup);
96 LY_CHECK_GOTO(ret, cleanup);
100 if (!ly_strncmp(type_enum->
enums[u].
name, value, value_len)) {
114 storage->enum_item = &type_enum->
enums[u];
119 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
120 LY_CHECK_GOTO(ret, cleanup);
123 LY_CHECK_GOTO(ret, cleanup);
127 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
141 if (val1->enum_item->value > val2->enum_item->value) {
143 }
else if (val1->enum_item->value < val2->enum_item->value) {
150 LIBYANG_API_DEF
const void *
152 void *UNUSED(prefix_data),
ly_bool *dynamic,
size_t *value_len)
154 int64_t prev_num = 0, num = 0;
158 prev_num = num = value->enum_item->value;
160 if (num == prev_num) {
166 return &value->enum_item->value;
170 LY_CHECK_RET(!buf, NULL);
176 memcpy(buf, &num, 4);
202 .name = LY_TYPE_ENUM_STR,
204 .plugin.id =
"libyang 2 - enumeration, version 1",
206 .plugin.validate = NULL,
212 .plugin.lyb_data_len = 4,
LIBYANG_API_DECL LY_ERR lyplg_type_store_enum(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 *prefix_data, uint32_t hints, const struct lysc_node *ctx_node, struct lyd_value *storage, struct lys_glob_unres *unres, struct ly_err_item **err)
Implementation of lyplg_type_store_clb for the built-in enumeration type.
struct lysc_type * realtype
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
LIBYANG_API_DECL LY_ERR lyplg_type_compare_simple(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_compare_clb for a generic simple type.
uint8_t ly_bool
Type to indicate boolean value.
#define LYPLG_TYPE_STORE_DYNAMIC
struct lyplg_type_record plugins_enumeration[]
Plugin information for enumeration type implementation.
The main libyang public header.
YANG data representation.
Libyang full error structure.
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 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 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.
#define LY_ARRAY_FOR(ARRAY,...)
Sized-array iterator (for-loop).
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
LIBYANG_API_DECL const void * lyplg_type_print_enum(const struct ly_ctx *ctx, const struct lyd_value *value, LY_VALUE_FORMAT format, void *prefix_data, ly_bool *dynamic, size_t *value_len)
Implementation of lyplg_type_print_clb for the built-in enumeration type.
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, only a reference counter is incremented and no memory allocation is performed. This insert function variant avoids duplication of specified value - it is inserted into the dictionary directly.
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
struct lysc_type_bitenum_item * enums
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.
API for (user) types plugins.
LY_ERR
libyang's error codes returned by the libyang functions.
LIBYANG_API_DEF int lyplg_type_sort_enum(const struct ly_ctx *ctx, const struct lyd_value *val1, const struct lyd_value *val2)
Implementation of lyplg_type_sort_clb for the built-in enumeration type.