YANG provides the "union" data type which is processed by matching values against each member type.


   type union {
     type int32;
     type boolean;
     type string;
   }

 

In this example the value "test" would be tried as an int32 and fail.

Then it would be tried as boolean (true or false) and fail.

Then it would match as a string.  Internally, the typedef for the string would be used.


The val_value_t struct that represents YANG data contains a "typdef" field.

This will be set to the member type that matched if the base type is union (NCX_BT_UNION).


     member type == val->typdef


In addition, the YANG type name for this type is also available using the function val_get_yang_typename


const xmlChar *type_name = val_get_yang_typename(val);

 

For example:

 

  type union {
      type ipv4-address;
      type ipv6-address;
  }


In this case, both member types have base type string.

In order to tell them apart, the val_get_yang_typename() function will return "ipv4-address"

if the first typedef matched, and "ipv6-address" if the second typedef matched.