Why are the BER-encodings produced by the OSS encoder always 100% DEFINITE or 100% INDEFINITE?

The following two directives applied to the components of SEQUENCE do not have any effect on the way the PDU type S is encoded. They only have an effect if applied to the PDU type S itself.

S ::= SEQUENCE {
    a [0] SEQUENCE {} --<INDEFINITE>--,
    b [1] SET {} --<DEFINITE>--
}

In theory the above is possible, but in order to produce the most compact encodings (i.e., ones where lengths occupy the fewest possible number of bytes) with minimal CPU cycles being consumed, we encode PDUs as 100% definite or 100% indefinite.

In order to encode using definite length encoding with minimal CPU cycles and without having unnecessarily large length fields, we encode from the back of the buffer to the front. This way whenever the encoder is at the point that it needs to emit a length field, it will know what the minimum number of bytes are to hold the length (the length is known at this point since all the fields that it applies to would have been encoded by virtue of the value being encoded from the end of the output buffer to the start).

Contrast how indefinite length encodings are handled. Here values are encoded from the start of the output buffer to the end, for by its nature indefinite length encodings are of a length which might not be readily determined until the end of the value is reached.

If it is critical for you to be able to mix indefinite length encodings with definite length encodings, you can always use the DeferDecoding OSS ASN.1 compiler directive. This would allow you to encode a given SET or SEQUENCE using the indefinite (or definite) length form, then inject the encoded value into the parent structure which is encoded using the definite (indefinite) length form.

You can download examples of how you can do it in the answers to questions:


The samples included with some of the Knowledge Center answers are meant for your general understanding of the OSS products. Different versions of the products might produce slightly different outputs. Consult the products documentation and samples for the most up-to-date products information and code examples.



Contact Support
contact Our office hours
24 hours/day, 7 days/week

  • Phone: 1-888-OSS-2761 (USA and Canada)
  • Phone: 1-732-302-9669 (International)
  • Fax: 1-732-302-0023
  • Email: support@oss.com
Free Trial
download

Test drive the OSS Nokalva ASN.1, LTE, and XML Tools now! Your trial includes complete software, documentation, sample programs, free 24x7 technical support and more.




Learn ASN.1
Learn ASN.1

Our expert personnel can help you learn ASN.1!

We offer 4-day ASN.1 courses at our headquarters or your premises.