How to read value of type union

I have following fragment in yang data model:

  leaf max-alarm-status-changes {
    type union {
      type uint16;
      type enumeration {
        enum infinite {
          description
            "The status-change entries are accumulated
             infinitely.";
        }
      }
    }
    default "32";
  }

My question: how to read the value of max-alarm-status-changes from CDB? How to determine actual type of this value?

I assume you are referring to reading the value using the CDB or MAAPI API.
You may then want to use the “non type safe” cdb_get() or maapi_get_elem() variants.

The type is found “confd_value_t” struct. See the “confd_types” man page.
For example, C_INT16 = 7 and C_ENUM_VALUE = 28.

For your YANG example, if you don’t want to have to check the type of the value, you can in your YANG model set the enum to an integer value that is not in the uint16 range.

      type enumeration {
        enum infinite {
          value -1;
        }
      }

See RFC 7950 for details on the YANG “enum” “value” statement: https://datatracker.ietf.org/doc/html/rfc7950#section-9.6.4.2

Thank you. cdb_get() that’s what I need.