Download Procedure for Calling C Decode Functions
Transcript
Event Handler Interface
The –events command line switch causes hooks for user-defined event handlers to be inserted into
the generated decode functions. What these event handlers do is up to the user. They fire when key
message-processing events or errors occur during the course of parsing an ASN.1 message. They
are similar in functionality to the Simple API for XML (SAX) that was introduced to provide a
simple interface for parsing XML messages.
The -notypes option can be used in conjunction with the -events option to generate pure parsing
functions. In this case, no C types or encode or decode functions are generated for the productions
within the given ASN.1 source file. Instead, only a set of parser functions are generated that invoke
the event handler callback functions. This gives the user total control over what is done with the
message data. Data that is not needed can be discarded and only the parts of the message needed
for a given application need to be saved.
How it Works
Users of XML parsers are probably already quite familiar with the concepts of
SAX. Significant events are defined that occur during the parsing of a message.
As a parser works through a message, these events are ‘fired’ as they occur by
invoking user defined callback functions. These callback functions are also known
as event handler functions. A diagram illustrating this parsing process is as fol-
lows:
The events are defined to be significant actions that occur during the parsing process. We will
define the following events that will be passed to the user when an ASN.1 message is parsed:
1. startElement – This event occurs when the parser moves into a new element. For example, if we
have a SEQUENCE { a, b, c } construct (type names omitted), this event will fire when we begin
parsing a, b, and c. The name of the element is passed to the event handling callback function.
251