(RCS control information is at the end of this file.)


C ANY example README
------------------

This example shows how the snacc compiler handles the ANY DEFINED BY
type in C.  ANY types (not ANY DEFINED BY) require the modifications
to the generated code.  Type "make" to build this example.

This directory should have the following files in it:

        README
        genber.c
        example.c
        makefile

There are 3 programs generated by the makefile:

        genber - builds a BER value of the AnyTestType and writes it
                 to a file called "att.ber"

        def    - takes file name of an AnyTestType value.  Decodes the
                 file and re-encodes it to stdout.  Uses definite
                 lengths for constructed values.

        indef  - takes file name of an AnyTestType value.  Decodes the
                 file and re-encodes it to stdout.  Uses indefinite
                 lengths for constructed values.


These files use the code generated by snacc from the
snacc/asn1specs/any.asn1 file. (see the makefile)

Look at genber.c to see how values can be built and printed.

Look at the generated code in any_test.c and any_test.h to see how the
any hash table is built.


try the following commands in your c-shell:

%1 genber                   # generate the att.ber file

%2 indef att.ber > tmp.ber  # decode att.ber an re-encode into tmp.ber

%3 def tmp.ber > tmp2.ber   # decode tmp.ber an re-encode into tmp2.ber

%4 diff att.ber tmp2.ber    # compare .ber files (should be the same)

You can also try different memory buffers when running the indef and def
utilities. To try ExpBuf use the -E argument when executing these utilities.
Example:

indef -E att.ber > tmp.ber # decode att.ber using the ExpBuf and re-encode
into tmp.ber

def -E att.ber > tmp.ber   # decode att.ber using the ExpBuf and re-encode
into tmp.ber



When you are finished with the example type "make clean"  to remove
the binaries and generated code.



Things To Note
--------------

Snacc ASN.1 comment commands

In the snacc/asn1specs/any.asn1 file, the AnyTestType has a special
"--snacc" ASN.1 comment after ::= to give snacc some extra information
about the AnyTestType.

AnyTestType ::= --snacc isPdu:"TRUE" -- SEQUENCE { ... etc. ... }

The "isPdu" flag tells snacc that the AnyTestType is a PDU type that
you will be calling the encoding and decoding routines directly
from your code.  This causes snacc to generate the "BEncAnyTestType"
and "BDecAnyTestType" routines in addition to the standard
"BEncAnyTestTypeContent" and "BDecAnyTestTypeContent".

The Content encoding and decoding routines only deal with the content
of the type, ignoring all of the tag and length pairs on the given
type (in this case the UNIVERSAL (CONSTRUCTED) 16 tag and the length
for the SEQUENCE).  The "BEncAnyTestType" and "BDecAnyTestType"
routines do encode the SEQUENCE tag and its length.  This design is
motivated by IMPLICIT tagging.

The compiler generated routines generally only call the content
oriented routines except in the case of ANY and ANY DEFINED BY types.
For ANY and ANY DEFINED BY types the PDU form of the rouine is called
since the tags are not known by the containing type.


SNMP OBJECT-TYPE Macro

The SNMP OBJECT-TYPE macro is used to define the id to type mapping
for ANY DEFINED BY types.  The macro has been modified to accept both
INTEGERs and OBJECT IDENTIFIERs as values (see
snacc/asn1specs/any.asn1).  This macro can be used with other
protocols to define the id to type mapping.

Two hash tables are used to hold the id to type mappings. One for
INTEGER to type mappings and the other for OBJECT IDENTIFIER to type
mappings.  You must explicitly initialize the hash tables by calling
generated init routines once at the beginning of your program.  Each
module that has OBJECT-TYPE macros in it will generate an
"InitAny<module name>" routine.  You must call every init routine to
add all the mappings to the hash table(s).

#-------------------------------------------------------------------------------
# $Header: /baseline/SNACC/c-examples/any/readme,v 1.4 2003/12/17 19:05:03 gronej Exp $
# $Log: readme,v $
# Revision 1.4  2003/12/17 19:05:03  gronej
# SNACC baseline merged with PER v1_7 tag
#
# Revision 1.3.2.1  2003/11/05 14:58:53  gronej
# working PER code merged with esnacc_1_6
#
# Revision 1.3  2002/10/24 14:47:41  mcphersc
# Added comments to new test routines
#
# Revision 1.2  2002/10/23 12:42:56  mcphersc
# Added "C" files instead of C++ files
#
# Revision 1.3.1.1  1997/08/20 23:14:52  povey
#
#
# Revision 1.2  1997/02/16 20:26:14  rj
# check-in of a few cosmetic changes
#
# Revision 1.1  1994/08/31  08:46:17  rj
# first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
#
