libyang  4.0.2
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Printing Data

Data printers allows to serialize internal representation of a data tree in a specific format. libyang supports the following data formats for printing:

  • XML

    Basic format as specified in rules of mapping YANG modeled data to XML in RFC 6020.

  • JSON

    The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG can be found in RFC 7951.

  • LYB

    Proprietary binary format that is focused on efficiency. Should always be used for best performance except for cases when the YANG context used for printing may differ from the one used for parsing, such a scenario will fail. Also, this format ignores most printing flags except for ::LYD_PRINT_WITH_SIBLINGS and LYD_PRINT_SHRINK (functionality differs from the text formats). In addition to storing the data, this format also stores all the default values and data node flags meaning the loaded data can be used directly without any validation (unless LYD_PRINT_SHRINK is used).

By default, both text formats are printed with indentation (formatting), which can be avoided by LYD_PRINT_SHRINK printer option). Other options adjust e.g. with-defaults mode.

Besides the legacy functions from libyang 1.x (lyd_print_clb(), lyd_print_fd(), lyd_print_file(), lyd_print_mem() and lyd_print_path()) printing data into the specified output, there are also new functions using output handler introduced in libyang 2.0. In contrast to schema printers, there is no limit of the functionality and the functions can be used interchangeable. The only think to note is that the new functions lyd_print_all() and lyd_print_tree() does not accept LYD_PRINT_WITHSIBLINGS printer option) since this flag differentiate the functions themselves.

Functions List