TOC PREV NEXT INDEX


Value Specifications



The compiler can parse any type of ASN.1 value specification, but the standard version of the ASN1C compiler will only generate code for following value specifications:


All value types except INTEGER and REAL cause an "extern" statement to be generated in the header file and a global value assignment to be added to the C or C++ source file. INTEGER and REAL value specifications cause #define statements to be generated.


BOOLEAN Value Specification

A BOOLEAN value causes an extern statement to be generated in the header file and a global declaration of type OSBOOL to be generated in the C or C++ source file. The mapping of ASN.1 declaration to global C or C++ value declaration is as follows:

    ASN.1 production:   <name> BOOLEAN ::= <value>
 

 
    Generated code:    OSBOOL <name> = <value>;
 


INTEGER Value Specification

The INTEGER type causes a #define statement to be generated in the header file of the form ASN1V_<valueName> where <valueName> would be replaced with the name in the ASN.1 source file. The reason for doing this is the common use of INTEGER values for size and value range constraints in the ASN.1 specifications. By generating #define statements, the symbolic names can be included in the source code making it easier to adjust the boundary values on the fly.

For example, the following declaration:

ivalue INTEGER ::= 5
 

will cause the following statement to be added to the generated header file:

#define ASN1V_ivalue 5
 

The reason the ASN1V_ prefix is added is to prevent collisions with INTEGER value declarations and other declarations such as enumeration items with the same name.


REAL Value Specification

The REAL type causes a #define statement to be generated in the header file of the form ASN1V_<valueName> where <valueName> would be replaced with the name in the ASN.1 source file. By generating #define statements, the symbolic names can be included in the source code making it easier to adjust the boundary values on the fly.

For example, the following declaration:

rvalue REAL ::= 5.5
 

will cause the following statement to be added to the generated header file:

#define ASN1V_rvalue 5.5
 

The reason the ASN1V_ prefix is added is to prevent collisions with other declarations such as enumeration items with the same name.


Enumerated Value Specification

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

    ASN.1 production:   <name> <EnumType> ::= <value>
 

 
    Generated code:     OSUINT32 <name> = <value>;
 


Binary and Hexadecimal String Value Specification

These value specifications cause two global C variables to be generated: a numocts variable describing the length of the string and a data variable describing the string contents. The mapping for a binary string is as follows (note: BIT STRING can also be used as the type in this type of declaration):

    ASN.1 production:  <name> OCTET STRING ::= `<bstring>'B
 

 
    Generated code:    OSUINT32  <name>_numocts = <length>;
 
                   OSOCTET <name>_data[]  = <data>; 
 

Hexadecimal string would be the same except the ASN.1 constant would end in a `H'.


Character String Value Specification

A character string declaration would cause a C or C++ const char* declaration to be generated:

    ASN.1 production:   <name> <string-type> ::= <value>
 

 
    Generated code:     ASN1ConstCharPtr <name> = <value>;
 

In this definition, <string-type> could be any of the standard 8-bit characters string types such as IA5String, PrintableString, etc. (note: this version of the compiler does not contain support for value declarations of larger character string type such as BMPString). The ASN1ConstCharPtr type used in the generated code is a type defined in asn1type.h designed to be a const char* type for C or C++.


Object Identifier Value Specification

Object identifier values are somewhat different in that they result in a structure being populated in the C or C++ source file.

    ASN.1 production:   <name> OBJECT IDENTIFIER ::= <value>
 

 
    Generated code:   ASN1OBJID <name> = <value>;
 


For example, consider the following declaration:

oid OBJECT IDENTIFIER ::= { ccitt b(5) 10 }
 

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

ASN1OBJID oid = {
 
   3,
 
   { 0, 5, 10 }
 
} ;
 

To populate a variable in a generated structure with this value, the rtSetOID utility function can be used (see the C/C++ Run-Time Library Reference Manual for a full description of this function). In addition, the C++ base type for this construct (ASN1TObjId) contains constructors and assignment operators that allow direct assignment of values in this from to the target variable.

The professional version of the ASN1C compiler will generate code for following remaining value definitions.

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 (ASN1CTXT* 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 Value Specification
The mapping of an ASN.1 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 unitization function:

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

 
SET Value Specification

SET value code generation is the same as SEQUENCE value code generation.

SEQUENCE OF Value Specification
The mapping of the ASN.1 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 value initialization function:

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

SET OF Value Specification
SET OF value code generation is the same as SEQUENCE OF value code generation.

CHOICE Value Specification
The mapping of ASN.1 declaration to 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 value initialization function:

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


Objective Systems, Inc.

102 Pickering Way, Suite #506
Exton, Pennsylvania 19341
http://www.obj-sys.com
Phone: (484) 875-9841
Toll-free: (877) 307-6855 (US only)
Fax: (484) 875-9830
info@obj-sys.com
TOC PREV NEXT INDEX