ConfD User Community

Enum to value in getElem


#1

Hello,

I have 2 service module where in 1st service module I defined leaf region and type is enumeration…

leaf region {
type enumeration {
enum “USA”;
enum “ASIA”;
}
}

and I used maapi.getElem in 2nd service module to get the region value it’s work but it give output value in Enum(1) and Eum(0) .

could you please suggest how to get the lable value in ref service package so I will get the value “USA” or “ASIA”…

Thanks
Dheeraj


#2

You will need to write your own string conversion routine from their enum values. There are #defines in the generated header files for the enum values when the YANG files are compiled by confdc. Only the enum constants are stored by ConfD, but not their string values.


#3

I have previously forgotten about the following utility function as described in the confd_lib_lib section of the ConfD User Guide which can be used if the schema information has been loaded from the ConfD daemon into the ConfD client library:

int confd_val2str(struct confd_type *type, const confd_value_t *val, char *buf, int bufsiz);

Prints the string representation of val into buf, which has the length bufsiz, using type information from the data model. Returns the length of the string as described for confd_pp_value(), or CONFD_ERR if the value could not be converted (e.g. wrong type). The type pointer can be obtained either from the struct confd_cs_node corresponding to the leaf that val pertains to, or via the confd_find_ns_type() function above. The struct confd_cs_node can in turn be obtained by variouscombinations of the functions that operate on the confd_cs_node trees (see above), or by user-defined functions for navigating those trees. Requires that schema information has been loaded from the ConfD daemon into the library, see confd_types(3).