CESNET / libyang

YANG data modeling language library
BSD 3-Clause "New" or "Revised" License
368 stars 292 forks source link

Only last set of changes are visible when used lyd_parse_data_mem() multiple times #2017

Open amitnagraj opened 1 year ago

amitnagraj commented 1 year ago

Hi,

I m trying to fetch the data using lyd_parse_data_mem() subscribing at the parent level(which also includes list inside it). I m filling the values by forming string of json format and passing it the lyd_parse_data_mem() API. I'm using the API multiple times to fill multiple list levels. But only the data which is filled last is visible by this method.

Is there any way so that the data will amend every time when i use this API?

Sysrepo version used: 2.2.12 Libyang Version used: 2.1.4

michalvasko commented 1 year ago

I would suggest to parse the data into a local variable and then append that to the final tree, lyd_parse_data_mem() is not able to append data to an existing tree.

amitnagraj commented 1 year ago

Thanks for the quick response.

Parsing the data locally will be costly when dealing with the large scale datasets, Is there any other way like lyd_new_path() which is able to append the data everytime.

michalvasko commented 1 year ago

Parsing the data locally will be costly when dealing with the large scale datasets

I do not understand why it should, you said you had already been parsing it one-by-one. Just store the result in a local variable and append it. It depend on the exact data you are parsing and the tree you are constructing but I guarantee that there is a (simple) way of not affecting the performance in any way.