Constructed Type Values

ASN1C will generate code for following remaining value definitions only when their use is required in legacy table constraint validation code:

Note

SEQUENCE, SET , SEQUENCE OF, SET OF and CHOICE values are available only when the -tables option is selected.

The values are initialized in a module value initialization function. The format of this function name is as follows:

init_<ModuleName>Value (OSCTXT*
                           pctxt)

Where <ModuleName> would be replaced with the name of the module containing the value specifications.

The only required argument is an initialized context block structure used to hold dynamic memory allocated in the creation of the value structures.

If the value definitions are used in table constraint definitions, then the generated table constraint processing code will handle the initialization of these definitions; otherwise, the initialization function must be called explicitly.

SEQUENCE or SET Value Specification

The mapping of an ASN.1 SEQUENCE or SET value declaration to a global C or C++ value declaration is as follows:

ASN.1 production:

   <name> <SeqType> ::= <value>

Generated code :

   <SeqType> <name>;

The sequence value will be initialized in the value initialization function.

For example, consider the following declaration:

   SeqType ::= SEQUENCE {
      id INTEGER ,
      name VisibleString
   }
                
   value SeqType ::= { id 12, name "abc" }

This would result in the following definition in the C or C++ source file:

   SeqType value;

Code generated in value initialization function would be as follows:

   value.id = 12;
   value.name = "abc";

SEQUENCE OF/SET OF Value

The mapping of an ASN.1 SEQUENCE OF or SET OF value declaration to a global C or C++ value declaration is as follows:

ASN.1 production:

   <name> <SeqOfType> ::= <value>

Generated code :

   <SeqOfType> <name>;

The sequence of value will be initialized in the value initialization function.

For example, consider the following declaration:

   SeqOfType ::= SEQUENCE OF (SIZE(2)) INTEGER
                
   value SeqOfType ::= { 1, 2 }

This would result in the following definition in the C or C++ source file:

   SeqOfType value;

Code generated in the value initialization function would be as follows:

   value.n = 2;
   value.element[0] = 1;
   value.element[1] = 2;

CHOICE Value

The mapping of an ASN.1 CHOICE value declaration to a global C or C++ value declaration is as follows:

ASN.1 production:

   <name> <ChoiceType> ::= <value>

Generated code :

   <ChoiceType> <name>;

The choice value will be initialized in the value initialization function.

For example, consider the following declaration:

   ChoiceType ::= CHOICE { oid OBJECT IDENTIFIER, id INTEGER }
                
   value ChoiceType ::= id: 1

This would result in the following definition in the C or C++ source file:

   ChoiceType value;

Code generated in the value initialization function would be as follows:

   value.t = T_ChoiceType_id;
   value.u.id = 1;