What is the difference between ASN.1 enumerated type and choice type?
-
26-09-2020 - |
Question
Can you give me an example to show when to use an enumeration and when to use a choice type with ASN.1?
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.