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 Java 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 ordinary BER/DER encode methods. 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 regular BER where encoding that is done from back-tofront. 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.