You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found that the reason for this behavior is that the lyplg_type_sort_enum function sorts the enumeration types from largest to smallest, while for the string type, its sorting function lyplg_type_compare_simple sorts from smallest to largest. For the boolean and decimal64 types, the sorting is also from smallest to largest.
Question:
1、I would like to know what considerations led to this difference?
2、I expect the libyang tree to maintain the original XML order. how should I do this?
Okay, I do not know what you are doing exactly. I have tested it myself, you can try it, too. The data are ordered in ascending order based on the enum value.
Is there any interface I can set up? Or do I need to implement the sorting method myself?
You can implement a type plugin for a specific typedef. In it you can define your own sorting callback and sort however you want. That is true for system-ordered lists. If you define a user-ordered list, it will always keep the same order of data that were received from the input.
Okay, I do not know what you are doing exactly. I have tested it myself, you can try it, too. The data are ordered in ascending order based on the enum value.
By the way, I found that the behavior of the lyplg_type_sort_enum interface is inconsistent with the behavior of other sort functions.
LIBYANG_API_DEF int
lyplg_type_sort_enum(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1,
const struct lyd_value *val2)
{
if (val1->enum_item->value > val2->enum_item->value) { // this the difference.
return -1;
} else if (val1->enum_item->value < val2->enum_item->value) { // this the difference.
return 1;
} else {
return 0;
}
}
LIBYANG_API_DEF int
lyplg_type_sort_int(const struct ly_ctx *UNUSED(ctx), const struct lyd_value *val1, const struct lyd_value *val2)
{
switch (val1->realtype->basetype) {
case LY_TYPE_INT8:
if (val1->int8 < val2->int8) { // this the difference.
return -1;
} else if (val1->int8 > val2->int8) { // this the difference.
return 1;
} else {
return 0;
}
break;
....
Activity
michalvasko commentedon Jan 22, 2026
Not true, it is sorted based on the
enumvalue, the string name is ignored. All the types should be sorted in ascending order.You must then define the list as
ordered-byuser.ExclusiveDY commentedon Jan 22, 2026
The enumeration type in the example above is defined as follows, but it appears in descending order. Why is this?
Is there any interface I can set up? Or do I need to implement the sorting method myself?
michalvasko commentedon Jan 22, 2026
Okay, I do not know what you are doing exactly. I have tested it myself, you can try it, too. The data are ordered in ascending order based on the enum value.
You can implement a type plugin for a specific typedef. In it you can define your own sorting callback and sort however you want. That is true for
system-ordered lists. If you define auser-ordered list, it will always keep the same order of data that were received from the input.ExclusiveDY commentedon Jan 26, 2026
The original message is as follows.
My test procedure is as follows:
Then I output the ntf tree, and it turned out like this:
By the way, I found that the behavior of the lyplg_type_sort_enum interface is inconsistent with the behavior of other sort functions.
LIBYANG_API_DEF int
michalvasko commentedon Jan 26, 2026
So that may be the issue, was fixed in version 4.0.8.