Chapter 9. Generated JER (JSON) Encode Methods

Table of Contents

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

For each ASN.1 production defined in an ASN.1 source file, a Python encode method may be generated. This method will convert a populated variable of the given type into an encoded ASN.1 message.

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)

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.

The Python JER run-time library provides encoding of basic ASN.1 types through the Asn1JsonEncodeBuffer class. If a Python class is NOT generated for a given ASN.1 type, the methods in Asn1JsonEncodeBuffer can be used to encode 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)