Do you have a sample that shows how to decode a value of EXTERNAL, and its 'encoding' field?

When decoding a value of EXTERNAL, the decoder may not decode the encoding field but instead may leave it in encoded format. First, an explanation of why this happens follows. Then, a suggestion for a simpler alternative is given.

The single-ASN1-type field has a type of AbstractSyntax.&Type which is encoded and decoded as an OpenType.

The EXTERNAL type gives no way to link the direct-reference with the encoding in the sense that the decoder is able to decode the encoding automatically. It's the responsibility of the application to determine the semantics of the encoding from the examination of the direct-reference and indirect-reference fields. In other words, your application is supposed to examine the direct-reference object identifier and process the encoding s accordingly. Suppose, for example, that EXTERNAL is used in the following context:

MyDialogue ::= EXTERNAL

and the encoding contains the value of the type

DialoguePDU ::= CHOICE
dialogueRequest AARQ-apdu, 
dialogueResponse AARE-apdu, 
dialogueAbort ABRT-apdu 

that is identified by the

dialogue-as-id OBJECT IDENTIFIER ::= 
{ccitt recommendation q 773 as (1) dialogue-as (1) version1 (1)}

in the direct-reference component. Then you can complete the decoding of the value as follows: 

MyDialogue myDialogue = (MyDialogue)coder.decode(encodedData, new MyDialogue()); 

if (myDialogue.hasDirectReference() && ! 
// The direct-reference OPTIONAL component is present. 
if (myDialogue.getDirectReference().equals ( 
// The value of the "direct-reference" indicates that 
// the "encoding" contains the DialoguePDU. 
External.Encoding encoding = myDialogue.getEncoding(); 
if (encoding.hasSingleASN1Type()) { 
// Decode it as DialoguePDU. 
OpenType ot = (OpenType)encoding.getChosenValue(); 
AbstractData dialoguePDU = 
coder.decode(ot.getEncodedValueAsStream(), new DialoguePDU()); 

Alternatively, you can write more generic code if in your ASN.1 you define the information object set that will link possible values of direct-reference to the type of the encoding:

Links TYPE-IDENTIFIER ::= { {DialoguePDU IDENTIFIED BY dialogue-as-id},

The ellipsis at the end indicates that you will possibly add more "links" in the future. You can use this helper information object set in your application code as follows:

MyDialogue myDialogue = (MyDialogue)coder.decode(encodedData, new MyDialogue()); 
if (myDialogue.hasDirectReference() && ! myDialogue.hasIndirectReference()) { 
// The direct-reference OPTIONAL component is present. 
// Lookup the "Links" information object set for the 
// matching record. 
int n = DialoguePDUs.links.getSize(); 
ObjectIdentifier id = myDialogue.getDirectReference();
ASN1Type type = null; 
for (int i=0; i<n; i++) 
TYPE_IDENTIFIER link = (TYPE_IDENTIFIER)DialoguePDUs.links.getElement(i); 
if (id.equals(link.getId())) { 
type = link.getType(); 
if (type != null) { 
// We have a matching record in the "Links". 
External.Encoding encoding = myDialogue.getEncoding(); 
if (encoding.hasSingleASN1Type()) { 
// Decode it as "type". 
OpenType ot = (OpenType)encoding.getChosenValue(); 
AbstractData nestedPDU = coder.decode(ot.getEncodedValueAsStream(), type); 

Note, that this time the code never references the DialoguePDU type directly but determines the type of the encoding by looking up the information object set above. Finally, if it's always assumed that the contents of encoding in MyDialogue is defined in terms of ASN.1 and is encoded by the same encoding rules as the enclosing MyDialogue PDU (in other words, if direct-reference is always present, then indirect- reference is always absent and encoding always has the singleASN1Type alternative chosen), then you can safely replace the type:

MyDialogue ::= EXTERNAL


MyDialogue-1997 ::= INSTANCE OF TYPE-IDENTIFIER ({Links})

and then decode it in one pass as follows:

MyDialogue_1997 myDialogue = (MyDialogue_1997)coder.decode(encodedData, new MyDialogue_1997());

Unlike the EXTERNAL, the INSTANCE OF provides means to link the identification field to the real type in the open type field.

For more details about the EXTERNAL type as well as about the reasons why its original definition (1986-1988) was deprecated in the newer ASN.1 standard, see the books that are available at ASN.1 Books. These are: ASN.1 Complete by J. Larmouth and ASN.1 - Communication between Heterogeneous Systems by O. Dubuisson.

To make it easier for you to run the example from the command line, two scripts are included, a Unix .sh and a Windows .bat.

To run it on a Unix platform, cd to the "external" directory and type:


To run it on Windows, cd to the "external" directory and type:


To do a cleanup on Unix, type:

./ cleanup

To do a cleanup on Windows, type:

run cleanup

To download please click on the file below: 8 KB

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:
Free Trial

Test drive the OSS Nokalva ASN.1, 4G 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.