Chapter 13. Generated JSON Encode Methods

Table of Contents

Generated Method Format and Calling Parameters
Populating Generated Variables for Encoding
Procedure for Calling JSON Encode Methods
Reuse of C# Encoding Objects

Encoding to JSON is similar to other encoding rules. For each ASN.1 production defined in an ASN.1 source file, an encode method may be generated. This function will convert a populated variable of the given type into an encoded ASN.1 message.

An encode method is only generated if it is required to alter the behavior of the base class. The C# model is built on inheritance from a set of common run-time base classes. These run-time classes contain default implementations of encode/decode methods that handle the encoding/decoding of the basic types. The generated classes for all constructed types (SEQUENCE, SEQUENCE OF, and CHOICE) will include generated encode methods.

Note

As of version 7.3, ASN1C supports ITU-T X.697 JER. BACKWARD COMPATIBILITY: Prior versions (starting with asn1c 6.6) used proprietary encoding rules for JSON, as this work predated the development of ITU-T X.697. If you need to work with our proprietary encoding rules, you must use the command-line arguments -compat 729 (or an older version number). We urge you to upgrade to using X.697 JER.

Our proprietary rules, and differences with X.697, are available on our website.