Do you have a sample application that illustrates step-by-step the use of the OSS ASN.1/C# Compiler to compile a simple ASN.1 module, and the use of the OSS C# API to invoke the encoder/decoder?

The sample application described here illustrates the use of the OSS ASN.1/C# Compiler to compile a simple ASN.1 module, and the use of the OSS C# runtime APIs to encode and decode data. By following these steps you can produce and run an executable program that encodes and then decodes a message. You can download the complete sample described below here: tbcas.windows.zip.

The C# application program in this example is tbcas.cs and the associated ASN.1 source file is bcas.asn.

Step 1: Invoking the OSS ASN.1 Compiler

The following describes how to compile the abstract syntax defined in bcas.asn:

INPUT

-- Baseball Card Abstract Syntax (BCAS)
BCAS DEFINITIONS ::= BEGIN
BBCard ::= SEQUENCE {
name IA5String (SIZE (1..60)),
team IA5String (SIZE (1..60)),
age INTEGER (1..100),
position IA5String (SIZE (1..60)),
handedness ENUMERATED {left-handed(0), right-handed(1), ambidextrous(2)},
batting-average REAL
}
myCard BBCard ::= {
name "Casey",
team "Mudville Nine",
age 32,
position "left field",
handedness ambidextrous,
batting-average {mantissa 250, base 10, exponent -3}
}
END

COMMAND

You enter the following command:

asn1cs bcas.asn

or equivalently:

asn1cs bcas

The above command informs the OSS ASN.1/C# Compiler that we want to convert the ASN.1 file bcas.asn to C#. This is implied by default when no command line option is specified.

The OSS ASN.1/C# Compiler will emit the following files and C# classes:

 

bcas\   // project class set directory
bcas\AssemblyInfo.cs   // administrative information for bcas assembly
bcas\bcas   // main namespace directory
bcas\bcas\BCAS   // BCAS module namespace directory
bcas\bcas\BCAS\BBCard.cs   // BBCard type class
bcas\bcas\BCAS\BCAS_values.cs   // BCAS module types values class
bcas\bcas\BCAS\NamespaceDoc.cs   // NamespaceDoc class
bcas\bcas\BcasFactory.cs   // Factory class
bcas\bcas\files   // generated cs files list
bcas\bcas\namespace-list   // generated namespaces list
bcas\bcas\overview.html   // overview

Step 2: Compiling and linking the sample application

The C# program tbcas.cs validates the myCard value of the BBCard PDU described by the bcas.asn abstract syntax, encodes the PDU (using BER), decodes it, and compares the unencoded and decoded PDUs. Note that the bcas C# classes (generated by the compiler) have been used by the application program.

INPUT

C# File, tbcas.cs

COMMAND

Next, build the sample application program as follows:

>csc -out:tbcas.exe tbcas.cs -recurse:bcas\*.cs -r:"%OSS_CSHARP_HOME%"\bin\asn1rt.dll

OUTPUT

The above command C#-compiles the compiler-generated and tbcas.cs C# files and builds the resulting application tbcas.exe using the OSS runtime asn1rt.dll.


Step 3: Invoking the encoder/decoder

INPUT

(None: For this example, the encoder input is generated by the ASN.1 compiler as a C# class instance initialized from the ASN.1 value notation.)

COMMAND

This command simply runs tbcas:

>tbcas

OUTPUT

Printing the unencoded PDU...

Printing the unencoded PDU...

value BBCard ::= {
name "Casey",
team "Mudville Nine",
age 32,
position "left field",
handedness ambidextrous,
batting-average {
base 2
}
}

Validating the unencoded PDU...
Validated successfully.

BER-encoding the PDU...
PDU encoded successfully.

Printing the BER-encoded PDU...

30 2d 80 05 43 61 73 65 79 81 0d 4d 75 64 76 69 6c 6c 65 20 4e 69 6e 65 82 01 20 83 0a 6c 65 66 74 20 66 69 65 6c 64 84 01 02 85 03 80 fe 01

BER-decoding the PDU...
Decoded successfully.

Printing the decoded PDU...

value BBCard ::= {
name "Casey",
team "Mudville Nine",
age 32,
position "left field",
handedness ambidextrous,
batting-average {
mantissa 1,
base 2,
exponent -2
}
}

Comparing the unencoded and decoded PDUs...
Compared successfully.


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, 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.