Memory-buffer Based Definite Length Encoders

For each ASN.1 production defined in the ASN.1 source file, a C# memory-buffer based encode method may be generated. These are the default type of encode methods that are generated when the -ber command-line option is selected. To generate stream-based forward encoders, the -stream option must be specified as well.

An encode method is only generated if it is required to alter the encoding of the base class method. 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. These default implementations include support for adding the universal tags associated with the types as defined in the X.680 standard.

So for simple assignments, the generation of an encode method is not necessary. For example, the following production will not result in the generation of an encode method:

   X ::= INTEGER

In this case, the generated C# class inherits the Asn1Integer base class and the default encode method within this class is sufficient to encode a value of the generated type.

However, if the type is altered to contain a tag or constraint, then a custom encode method would be generated:

   X ::= [APPLICATION 1] INTEGER

In this case, special logic is necessary to apply the tag value.

Some types will always cause encode methods to be generated. At the primitive level, this is true for the ENUMERATED type. This type will always contain a custom set of enumerated values. All constructed types (SEQUENCE, SET, SEQUENCE/SET OF, and CHOICE) will cause encode methods to be added to the generated classes.