Question

Can you give me an example to show when to use an enumeration and when to use a choice type with ASN.1?

Was it helpful?

Solution

CHOICE and ENUMERATED are used for different purposes, as different as "enum" and "union" in C.

ENUMERATED only lists a set of elements :

MyFruit ::= ENUMERATED { banana (1), apple (2), pear (3) }

CHOICE allows to select one element from a list, and define its attributes:

MyCHOICE ::= CHOICE { a INTEGER, b BOOLEAN, c SEQUENCE (SIZE(1..10)) OF MyFruit }

If you use the ASN.1 value notation to declare variables of these types it would look like:

aFruit MyFruit ::= banana

aChoice MyCHOICE ::= c:{banana, apple, banana, pear}

anotherChoice MyCHOICE ::= a:10

See? The CHOICE allows to use the same typename to store different types (thus values). Like the "union" in C.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top