The compiler would read this ASN.1 definition and produce the following
The compiler would read this ASN.1 definition and produce the following
C type%
C type:
\footnote{\emph{-fnative-types} compiler option is used to produce basic C \emph{int}
\begin{codesample}
types instead of infinite width INTEGER\_t structures. See Section
typedef struct Rectangle_s {
\vref{sec:Command-line-options}.%
long height;
}:
long width;
\begin{lyxcode}
} Rectangle_t;
typedef~struct~Rectangle\_s~\{
\end{codesample}
~~~~int~height;
~~~~int~width;
\}~Rectangle\_t;
\end{lyxcode}
It would also create the code for converting this structure into platform-independent
It would also create the code for converting this structure into platform-independent
wire representation (a serializer API) and the decoder of such wire
wire representation (a serializer API) and the decoder of such wire
representation back into local, machine-specific type (a deserializer
representation back into local, machine-specific type (a deserializer
...
@@ -138,29 +147,34 @@ API).
...
@@ -138,29 +147,34 @@ API).
\section{Quick start with asn1c}
\section{Quick start with asn1c}
After building and installing the compiler, the \emph{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 modules%
} command may be used to compile the ASN.1 module%
\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}
\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.%
to find out about \textbf{-P} and \textbf{-R} options.%
}:
}:
\begin{lyxcode}
\begin{bash}
asn1c~\emph{<module.asn1>}
asn1c %\emph{<modules.asn1>}%
\end{lyxcode}
\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
The asn1c compiler produces a number of files:
directory:
\begin{itemize}
\begin{itemize}
\item A set of .c and .h files, generally a single pair for each type defined
\item A set of .c and .h files for each type defined
in the ASN.1 specifications. These files will be named similarly to
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
the ASN.1 types (\emph{Rectangle.c} and \emph{Rectangle.h} for the
RectangleTest ASN.1 module defined in the beginning of this document).
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
\item A set of helper .c and .h files which contain the generic encoders,
and other useful routines. There will be quite a few of them, some
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
of them are not even always necessary, but the overall amount of code
after compilation will be rather small anyway.
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
\item A \emph{Makefile.am.sample} file mentioning all the files created
at the earlier steps. This file is suitable for either automake suite
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}
\end{itemize}
It is your responsibility to create .c file with the \emph{int main()}
It is possible to compile everything with just a couple of instructions:
{\small -gen-PER}&{\small Generate Packed Encoding Rules (PER) support code.}\tabularnewline
{-gen-PER}&{\small Generate Packed Encoding Rules (PER) support code.}\\
{\small -pdu=}\emph{\small auto}&{\small Generate PDU tables by discovering Protocol Data Units automatically.}\tabularnewline
{-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.}\\\\
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.}!}% */