Populating Generated Variables for Encoding

Populating attributes of instances of classes generated for constructed types can be done by creating an instance of the class and then directly populating each attribute. For primitive types, nothing needs to be populated. The values to be encoded are passed directly to the methods.

For classes generated for SEQUENCE/SET OF constructs, the standard Python list structure is used. The typical method is to create an empty list (x = []) and then append items to it.

The only primitive type that is an instance of a class having multiple attributes is BIT STRING. In this case, the Asn1BitString class contains an attribute named numbits to specify the number of bits in the string and a value to hold the actual data.

Some primitive type encode methods can accept data in multiple forms. An example of this is the encode method generated for an INTEGER with named numbers. In this case, the encode method will accept an argument of type string which is assumed to be a named number identifier or it can accept an argument of type int which is the integer value to be encoded.