Chapter 8. Generated JER (JSON) Decode Methods

Table of Contents

Run-time and Generated Python Decode Methods
Procedure for Calling Python JER Decode Methods

Recall from the "ASN.1 Type to Python Class Mappings" chapter that, for many ASN.1 types, a built-in Python type or a type from the ASN1C Python run-time is used to represent values of the ASN.1 type. A Python class is generated for an ASN.1 type when either a) there is no such Python type that can be used to represent the value, OR b) the ASN.1 type is assigned a name and its definition includes constraints, tags, or encoding instructions that alter the type's value space or encoding from the basic ASN.1 type, such as for MyInteger ::= INTEGER(0..8)

For each ASN.1 type defined in an ASN.1 source file and for which a Python class is generated, a Python decode method may be generated (when an appropriate method is inherited, it is not necessary to generate a decode method).

When a Python class is generated, it is generated to either represent the ASN.1 type (such as for SEQUENCE) or to simply provide encode and decode methods. In the former case, the generated methods will be instance methods, while in the latter case the generated methods will be static methods. Naturally, decode methods which are instance methods will decode into the object on which the decode method is invoked. Decode methods which are static methods will return the result of decoding.

The Python JER run-time library provides decoding of basic ASN.1 types through the Asn1JsonDecodeBuffer class. The Asn1JsonDecodeBuffer class decodes data from any io.TextIOBase object.

If a Python class is NOT generated for a given ASN.1 type, the methods in Asn1JsonDecodeBuffer can be used to decode it. For example, no class will be generated for:

MyInteger ::= INTEGER

while a class with static methods will be generated for:

MyInteger ::= INTEGER(0..8)