29#include "plugins_internal.h"
45 uint32_t max_value = 0;
53 if (type_enum->
enums[u].value < 0) {
55 *fixed_size_bits = 32;
59 if ((
unsigned)type_enum->
enums[u].value > max_value) {
60 max_value = type_enum->
enums[u].value;
69lyplg_type_store_enum(
const struct ly_ctx *ctx,
const struct lysc_type *type,
const void *value, uint64_t value_size_bits,
70 uint32_t options,
LY_VALUE_FORMAT format,
void *UNUSED(prefix_data), uint32_t hints,
71 const struct lysc_node *UNUSED(ctx_node),
struct lyd_value *storage,
struct lys_glob_unres *UNUSED(unres),
77 uint64_t fixed_size_bits;
84 memset(storage, 0,
sizeof *storage);
88 lyplg_type_lyb_size_enum(type, NULL, &fixed_size_bits);
90 fixed_size_bits, &value_size, err);
91 LY_CHECK_GOTO(ret, cleanup);
95 memcpy(&num, value, value_size);
101 if (type_enum->
enums[u].value == num_val) {
114 storage->enum_item = &type_enum->
enums[u];
118 LY_CHECK_GOTO(ret, cleanup);
126 LY_CHECK_GOTO(ret, cleanup);
130 if (!ly_strncmp(type_enum->
enums[u].
name, value, value_size)) {
144 storage->enum_item = &type_enum->
enums[u];
149 options &= ~LYPLG_TYPE_STORE_DYNAMIC;
150 LY_CHECK_GOTO(ret, cleanup);
153 LY_CHECK_GOTO(ret, cleanup);
168lyplg_type_sort_enum(
const struct ly_ctx *UNUSED(ctx),
const struct lyd_value *val1,
171 if (val1->enum_item->value < val2->enum_item->value) {
173 }
else if (val1->enum_item->value > val2->enum_item->value) {
182 void *UNUSED(prefix_data),
ly_bool *dynamic, uint64_t *value_size_bits)
184 uint64_t fixed_size_bits;
185 int64_t prev_num = 0, num = 0;
189 lyplg_type_lyb_size_enum(value->
realtype, NULL, &fixed_size_bits);
191 prev_num = num = value->enum_item->value;
193 if (num == prev_num) {
196 if (value_size_bits) {
197 *value_size_bits = fixed_size_bits;
199 return &value->enum_item->value;
203 LY_CHECK_RET(!buf, NULL);
206 if (value_size_bits) {
207 *value_size_bits = fixed_size_bits;
209 memcpy(buf, &num, 4);
218 if (value_size_bits) {
219 *value_size_bits = strlen(value->
_canonical) * 8;
235 .name = LY_TYPE_ENUM_STR,
237 .plugin.id =
"ly2 enumeration",
238 .plugin.lyb_size = lyplg_type_lyb_size_enum,
239 .plugin.store = lyplg_type_store_enum,
240 .plugin.validate_value = NULL,
241 .plugin.validate_tree = NULL,
243 .plugin.sort = lyplg_type_sort_enum,
244 .plugin.print = lyplg_type_print_enum,
const struct lyplg_type_record plugins_enumeration[]
Plugin information for enumeration type implementation.
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
lyplg_lyb_size_type
Type of the LYB size of a value of a particular 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.
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...
LIBYANG_API_DECL LY_ERR lyplg_type_check_value_size(const char *type_name, LY_VALUE_FORMAT format, uint64_t value_size_bits, enum lyplg_lyb_size_type lyb_size_type, uint64_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.
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.
@ LYPLG_LYB_SIZE_FIXED_BITS
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_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.
#define LYPLG_TYPE_STORE_DYNAMIC
struct lysc_type_bitenum_item * enums
#define LY_ARRAY_FOR(ARRAY,...)
Sized-array iterator (for-loop).
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
#define LY_ARRAY_COUNT_TYPE
Type (i.e. size) of the sized array's size counter.
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.