28 #include "ly_common.h"
29 #include "plugins_internal.h"
40 #define ENUM_FIXED_SIZE_BITS(type) \
41 lyplg_type_get_highest_set_bit_pos(\
42 ((struct lysc_type_enum *)type)->enums[LY_ARRAY_COUNT(((struct lysc_type_enum *)type)->enums) - 1].value)
52 if (type_enum->
enums[0].value < 0) {
54 *fixed_size_bits = 32;
66 lyplg_type_store_enum(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value, uint32_t value_size_bits,
67 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
80 memset(storage, 0,
sizeof *storage);
86 LY_CHECK_GOTO(ret, cleanup);
90 memcpy(&num, value, value_size);
96 if (type_enum->
enums[u].value == num_val) {
109 storage->enum_item = &type_enum->
enums[u];
113 LY_CHECK_GOTO(ret, cleanup);
121 LY_CHECK_GOTO(ret, cleanup);
125 if (!ly_strncmp(type_enum->
enums[u].
name, value, value_size)) {
139 storage->enum_item = &type_enum->
enums[u];
144 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
145 LY_CHECK_GOTO(ret, cleanup);
148 LY_CHECK_GOTO(ret, cleanup);
152 if (options & LYPLG_TYPE_STORE_DYNAMIC) {
163 lyplg_type_sort_enum(
const struct ly_ctx *UNUSED(ctx),
const struct lyd_value *val1,
166 if (val1->enum_item->value > val2->enum_item->value) {
168 }
else if (val1->enum_item->value < val2->enum_item->value) {
177 void *UNUSED(prefix_data),
ly_bool *dynamic, uint32_t *value_size_bits)
179 int64_t prev_num = 0, num = 0;
183 prev_num = num = value->enum_item->value;
185 if (num == prev_num) {
188 if (value_size_bits) {
191 return &value->enum_item->value;
195 LY_CHECK_RET(!buf, NULL);
198 if (value_size_bits) {
201 memcpy(buf, &num, 4);
210 if (value_size_bits) {
211 *value_size_bits = strlen(value->
_canonical) * 8;
227 .name = LY_TYPE_ENUM_STR,
229 .plugin.id =
"ly2 enumeration",
230 .plugin.lyb_size = lyplg_type_lyb_size_enum,
231 .plugin.store = lyplg_type_store_enum,
232 .plugin.validate_value = NULL,
233 .plugin.validate_tree = NULL,
235 .plugin.sort = lyplg_type_sort_enum,
236 .plugin.print = lyplg_type_print_enum,
struct lysc_type * realtype
memset(value->fixed_mem, 0, LYD_VALUE_FIXED_MEM_SIZE)
LIBYANG_API_DECL LY_ERR lyplg_type_check_value_size(const char *type_name, LY_VALUE_FORMAT format, uint32_t value_size_bits, enum lyplg_lyb_size_type lyb_size_type, uint32_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.
lyplg_lyb_size_type
Type of the LYB size of a value of a particular type.
YANG extension compiled instance.
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.
LY_ERR
libyang's error codes returned by the libyang functions.
uint8_t ly_bool
Type to indicate boolean value.
#define LYPLG_TYPE_STORE_DYNAMIC
#define ENUM_FIXED_SIZE_BITS(type)
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...
#define LY_ARRAY_COUNT(ARRAY)
Get the number of records in the ARRAY.
#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 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.
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...
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.
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.
API for (user) types plugins.