
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.
A BOOLEAN value causes an "extern" statement to be generated in the header file and a global declaration of type ASN1BOOL 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: ASN1BOOL <name> = <value>;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.
ivalue INTEGER ::= 5#define ASN1V_ivalue 5The 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.
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.
rvalue REAL ::= 5.5#define ASN1V_rvalue 5.5The reason the ASN1V_ prefix is added is to prevent collisions with other declarations such as enumeration items with the same name.
ASN.1 production: <name> <EnumType> ::= <value> Generated code: ASN1UINT <name> = <value>;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: ASN1UINT <name>_numocts = <length>; ASN1OCTET <name>_data[] = <data>;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 char* type for C or const char* type for C++.
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>;oid OBJECT IDENTIFIER ::= { ccitt b(5) 10 }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 section in the run-time API guide 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.
ASN.1 production: <name> <SeqType> ::= <value>SeqType ::= SEQUENCE { id INTEGER , name VisibleString } value SeqType ::= { id 12, name "abc" }SeqType value;value.id = 12; value.name = "abc";ASN.1 production: <name> <SeqOfType> ::= <value>SeqOfType ::= SEQUENCE OF (SIZE(2)) INTEGER value SeqOfType ::= { 1, 2 }SeqOfType value;value.n = 2; value.element[0] = 1; value.element[1] = 2;ASN.1 production: <name> <ChoiceType> ::= <value>ChoiceType ::= CHOICE { oid OBJECT IDENTIFIER, id INTEGER }value ChoiceType ::= id: 1ChoiceType value;value.t = T_ChoiceType_id; value.u.id = 1;
Objective Systems, Inc.102 Pickering Way, Suite #506Exton, 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 |