The compiler would read this ASN.1 definition and produce the following
C type%
\footnote{\emph{-fnative-types} compiler option is used to produce basic C \emph{int}
types instead of infinite width INTEGER\_t structures. See Section
\vref{sec:Command-line-options}.%
}:
\begin{lyxcode}
typedef~struct~Rectangle\_s~\{
~~~~int~height;
~~~~int~width;
\}~Rectangle\_t;
\end{lyxcode}
C type:
\begin{codesample}
typedef struct Rectangle_s {
long height;
long width;
} Rectangle_t;
\end{codesample}
It would also create the code for converting this structure into platform-independent
wire representation (a serializer API) and the decoder of such wire
representation back into local, machine-specific type (a deserializer
...
...
@@ -138,29 +147,34 @@ API).
\section{Quick start with asn1c}
After building and installing the compiler, the \emph{asn1c}%
\footnote{The 1 symbol in asn\textbf{1}c is a digit, not an ``ell'' letter.%
} command may be used to compile the ASN.1 module%
After building and installing the compiler, the \emph{asn1c}
command may be used to compile the ASN.1 modules%
\footnote{This is probably \textbf{not} what you want to try out right now. Read through the rest of this chapter and check the Section \vref{sec:Command-line-options}
to find out about \textbf{-P} and \textbf{-R} options.%
}:
\begin{lyxcode}
asn1c~\emph{<module.asn1>}
\end{lyxcode}
\begin{bash}
asn1c %\emph{<modules.asn1>}%
\end{bash}
The asn1c takes a number of command line options,
such as an option to produce native long types
for integers instead of infinite width INTEGER\_t structures:
After compiling, the following entities will be created in your current
directory:
The asn1c compiler produces a number of files:
\begin{itemize}
\item A set of .c and .h files, generally a single pair for each type defined
in the ASN.1 specifications. These files will be named similarly to
\item A set of .c and .h files for each type defined
in the ASN.1 specification. These files will be named similarly to
the ASN.1 types (\emph{Rectangle.c} and \emph{Rectangle.h} for the
RectangleTest ASN.1 module defined in the beginning of this document).
\item A set of helper .c and .h files which contain generic encoders, decoders
and other useful routines. There will be quite a few of them, some
of them even are not always necessary, but the overall amount of code
\item A set of helper .c and .h files which contain the generic encoders,
decoders and other useful routines. There will be quite a few of them, some
of them are not even always necessary, but the overall amount of code
after compilation will be rather small anyway.
\item A \emph{converter-sample.c} file containing the \emph{int main()} function with a fully functioning decoder. It can convert a given PDU between BER, XER and possibly PER (if -gen-PER option to asn1c was in effect). At some point you will want to replace this file with your own file containing the \emph{int main()} function.
\item A \emph{Makefile.am.sample} file mentioning all the files created
at the earlier steps. This file is suitable for either automake suite
or the plain `make` utility.
or the plain `make` utility. Just rename it into \emph{Makefile}.
\end{itemize}
It is your responsibility to create .c file with the \emph{int main()}
routine.
In other words, after compiling the Rectangle module, you have the
following set of files: \{~Makefile.am.sample, Rectangle.c, Rectangle.h,
\textbf{\ldots{}}\}, where ``\textbf{\ldots{}}'' stands for the
set of additional ``helper'' files created by the compiler. If you
add a simple file with the \emph{int main()} routine, it would even
be possible to compile everything with the single instruction:
{-gen-PER}&{\small Generate Packed Encoding Rules (PER) support code.}\\
{-pdu=}\emph{auto}&{\small Generate PDU tables by discovering Protocol Data Units automatically. Also accepts a special keyword \emph{all} or a particular type to be used as a PDU.}\\\\
\textbf{Output Options}&\textbf{Description}\\
\midrule
{\small -print-constraints}&{\small When -EF are also specified, this option forces the compiler
to explain its internal understanding of subtype constraints.}\tabularnewline
Rectangle_t *rect = 0; /* %\textbf{\color{red}Note this 0\footnote{Forgetting to properly initialize the pointer to a destination structure is a major source of support requests.}!}% */
Rectangle_t *rect = 0; /* %\textbf{\color{red}Note this 0\footnote{Forgetting to properly initialize the pointer to a destination structure is a major source of support requests.}!}% */
Rectangle_t *rectangle = 0; /* Type to decode. %\textbf{\color{red}Note this 0\footnote{Forgetting to properly initialize the pointer to a destination structure is a major source of support requests.}!}% */