Thoughts on the current state of ASN.1 and XML technologies.

Getting Started with ASN1C


So, you have an ASN.1 specification. And you have ASN1C. How do you use ASN1C in order to work with messages that conform to the specification?

The best way to find out how to use ASN1C with a given specification is to ask ASN1C itself. There are a few qualifiers to the asn1c command that, if used together, can get you started nicely working with your messages.

One qualifier is the -genwriter qualifier. This qualifier will cause ASN1C to generate a sample writer program in your chosen language (C, C++, Java, or C#). This sample writer program encodes a message according to the ASN.1 specification and writes the encoded message out to a file (message.dat by default). Many of the functions the writer calls are also generated code, so you can look at what needs to be done to encode the specific pieces of the message.

A second qualifier is the -genreader qualifier. This qualifier will cause ASN1C to generate a sample reader program in your chosen language. This sample reader program decodes a message from a file (message.dat by default). Many of the functions the reader calls are also generated code, so you can look at what needs to be done to decode the specific pieces of the message.

The third qualifier is the -gentest qualifier. This qualifier will cause ASN1C to generate code that populates an object instance with test data. The test data consist of meaningless, randomly generated values that conform to what the ASN.1 specification says the item should have. But this generated code, which is invoked by the writer, shows you how to populate an object before you encode it.

Sometimes ASN1C will need to choose a definition from the ASN.1 specification to use as the PDU in the generated writer and reader programs. You can tell ASN1C what definition to use for the PDU by adding the -usepdu qualifier.

All of these command line qualifiers have corresponding settings in the ASN1C GUI.

Comments are closed.