ENUMERATED

The Go mapping for an ASN.1 ENUMERATED type is the same as for INTEGER. By default, uint64 is used. If the ENUMERATED type contains negative-value identifiers, then int64 is used. Go constants are generated for each of the enumerated identifiers. The constant names consist of the type name concatanated with the enumerated identifier name in order to provide unique names. Note that for Go, camel-case is used in the generated identifiers and underscores are not used.

If the enumerated type is extensible, a special UNKNOWN identifier constant is added to the enumerated contant list.

If an enumerated type is referenced directly in an element within a constructed type, a compiler-generated type is generated for it consisting of the constructed type name concatanated with the element name to form a camel-cased identifer. This identifier is then used as the prefix for generated enumerated identifiers.

Example - Enumerated Type Assignment

ASN.1:

   MyEnum ::= ENUMERATED { red(0), green(1), blue(2), ... }

Generated Go code:

   type MyEnum uint64
const (
	MyEnumRed = 0
	MyEnumGreen = 1
	MyEnumBlue = 2
	MyEnumUNKNOWN = 3
)

Example - Enumerated Type Referenced in Element

ASN.1:

   MySeq ::= SEQUENCE {
     enum ENUMERATED { a, b, c }
   }

Generated Go code:

   type MySeqEnum uint64
   const (
      MySeqEnumA = 0
      MySeqEnumB = 1
      MySeqEnumC = 2
   )
      
   type MySeq struct {
      Enum MySeqEnum
   }