# How to read value of type union

**URL:** <https://dmap-community.ductus.global/t/how-to-read-value-of-type-union/3709>\
**Category:** CDB and CDB API\
**Created:** [June 14, 2021, 2:10pm UTC](https://dmap-community.ductus.global/t/how-to-read-value-of-type-union/3709 "2021-06-14T14:10:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ypopov](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@ypopov](https://dmap-community.ductus.global/u/ypopov)\
**Post date:** [June 14, 2021, 2:10pm UTC](https://dmap-community.ductus.global/t/how-to-read-value-of-type-union/3709/1 "2021-06-14T14:10:30Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)\
**Post date:** [June 15, 2021, 10:36am UTC](https://dmap-community.ductus.global/t/how-to-read-value-of-type-union/3709/2 "2021-06-15T10:36:50Z")

</div>

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.

```auto
      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](https://datatracker.ietf.org/doc/html/rfc7950#section-9.6.4.2)

---

<div class="post-metadata">

**Author:** ![ypopov](https://avatars.discourse-cdn.com/v4/letter/y/6bbea6/32.png) [@ypopov](https://dmap-community.ductus.global/u/ypopov)\
**Post date:** [June 15, 2021, 12:33pm UTC](https://dmap-community.ductus.global/t/how-to-read-value-of-type-union/3709/3 "2021-06-15T12:33:37Z")

</div>

Thank you. cdb\_get() that’s what I need.
