BER messages can be encoded directly to an output stream such as a file, network or memory stream. The ASN1C compiler has the –stream option to generate encode functions of this type. For each ASN.1 production defined in the ASN.1 source file, a C# encode method may be generated. This function will convert a populated variable of the given type into an encoded ASN.1 message.
The basic principles of the generation of the encode methods are the same as for the memory-buffer based BER/DER encode methods described in the preceding section. Stream-oriented BER encoding starts from the beginning of the message until the message is complete. This is sometimes referred to as “forward encoding”. This differs from memorybuffer based BER where encoding that is done from back-to-front. Indefinite lengths are used for all constructed elements in the message. Also, there is no permanent buffer for stream-oriented encoding, all octets are written directly to the output stream.