Chapter 1. Overview of ASN1C

The ASN1C code generation tool translates an Abstract Syntax Notation 1 (ASN.1) or XML Schema Definitions (XSD) source file into computer language source files that allow ASN.1 data to be encoded/decoded. This release of the compiler includes options to generate code in four different languages: C, C++, C#, or Java. This manual discusses the C and C++ code generation capabilities. The ASN1C Java User’s Manual discusses the Java code generation capability. The ASN1C C# User’s Manual discusses the C# code generation capability.

Each ASN.1 module that is encountered in an ASN.1 source file results in the generation of the following two types of C/C++ language files:

  1. An include (.h) file containing C/C++ typedefs and classes that represent each of the ASN.1 productions listed in the ASN.1 source file, and

  2. A set of C/C++ source (.c or .cpp) files containing C/C++ encode and decode functions. One encode and decode function is generated for each ASN.1 production. The number of files generated can be controlled through command-line options.

These files, when compiled and linked with the ASN.1 low-level encode/decode function library, provide a complete package for working with ASN.1 encoded data.

ASN1C works with the version of ASN.1 specified in ITU-T international standards X.680 through X.683 (ISO/IEC 8824). It generates code for encoding/decoding data in accordance with the following encoding rules:

Additional support for XML is provided in the form of an option to generate an equivalent XML Schema Definitions (XSD) file for a given ASN.1 specification. Encoders and decoders can then be generated using the -xml option to format or parse XML documents that conform to this schema. This level of support is closer to the W3C definition of XML then is the ITU-T X.693 XER definition. As of release version 6.0, it is possible to compile an XML schema definitions (XSD) file and generate encoders/decoders that can generate XML in compliance with the schema as well as binary encoders/encoders that implement the ASN.1 binary encoding rules.

The compiler is capable of parsing all ASN.1 syntax as defined in the standards. It is capable of parsing advanced syntax including Information Object Specifications as defined in the ITU-T X.681 standard as well as Parameterized Types as defined in ITU-T X.683. The compiler is also capable of using table constraints as defined in ITU-T X.682 to generate single-step encoders and decoders that can encode or decode multi-part messages in a single function call.

This release of the compiler contains a special command-line option - -asnstd x208 - that allows compilation of deprecated features from the older X.208 and X.209 standards. These include the ANY data type and unnamed fields in SEQUENCE, SET, and CHOICE types. This version can also parse type syntax from common macro definitions such as the OPERATION and ERROR macros in ROSE.