<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">%==========================================================================
\section{Serialization of Hazard and HazardSet Information}
%==========================================================================
\label{sec_serializing}

In the \var{lib\_ufld\_hazards} library there are two classes defined
relevant to this lab.  The \var{XYHazard} class and the
\var{XYHazardSet} class. The latter is essentially just a collection
of the former. It is recommend that you use this data structure
internally in your programs, but especially recommended that you use
this data structure for serializing.

\pskip

Serializing and De-serializing are explained further below, but
perhaps the best explanation is by example in the straw-man
\app{uFldHazardMgr} application. The \var{handleMailDetectionReport()} function
handles incoming reports from the sensor and builds up a hazardset object 
for later posting to the \app{MOOSDB}.

\subsection{Serializing and De-serializing XYHazard Objects}

Hazard objects are dealt with in the \var{XYHazard} class in \var{lib\_ufld\_hazards}. 
It may be best to just explore the class header file to understand its function, 
but the below example snippets should give the general idea:

\vspace{0.1in}
\begin{fileverb}
 #include "XYHazard.h"

 // Build the hazard object
 XYHazard my_hazard;
 my_hazard.setX(5);
 my_hazard.setY(8);
 my_hazard.setType("hazard");
 my_hazard.setLabel("128");

 // Serialize the object into a string
 string msg = my_hazard.getSpec()

 // Post to the MOOSDB
 Notify("HAZARD_INFO", msg);
\end{fileverb}
\normalsize

\noindent
The above would result in the following posting to the MOOSDB:

\prevgreen
\begin{verbatim}
   HAZARD_INFO = "x=5,y=8,type=hazard,label=128"
\end{verbatim}
\postverb

\noindent
In the reverse direction, creating an \var{XYHazard} object from a string:

\vspace{0.1in}
\begin{fileverb}
 #include "XYFormatUtilsHazard.h"

 string msg = "x=5,y=8,type=hazard,label=128";

 XYHazard my_hazard = string2Hazard(msg);
 cout &lt;&lt;  my_hazard.getX() &lt;&lt; ", ";
 cout &lt;&lt;  my_hazard.getY() &lt;&lt; ", ";
 cout &lt;&lt;  my_hazard.getType() ", ";
 cout &lt;&lt;  my_hazard.getLabel() &lt;&lt; endl;
\end{fileverb}
\vspace{0.1in}

\noindent
The above would result in the following written to the terminal:

\vspace{0.12in}
\begin{consoleverb}
  5, 8, hazard, 128
\end{consoleverb}

%------------------------------------------------------------------------
\subsection{Serializing and De-serializing XYHazardSet Objects}

HazardSet objects are essentially collections of XYHazard
objects. They are dealt with in the \var{XYHazardSet} class in
\var{lib\_ufld\_hazards}.  It may be best to just explore the class
header file to understand its function, but the below example snippets
should give the general idea:

\vspace{0.1in}
\begin{fileverb}
 #include "XYHazardSet.h"

 // Build the hazards
 XYHazard hazard_01;
 hazard_01.setX(15);
 hazard_01.setY(18);
 hazard_01.setType("hazard");
 hazard_01.setLabel(128);

 XYHazard hazard_02;
 hazard_02.setX(35);
 hazard_02.setY(38);
 hazard_02.setType("benign");
 hazard_02.setLabel(92);

 // Build the hazardset
 XYHazardSet my_hazard_set;
 my_hazard_set.setSource("betty");
 my_hazard_set.addHazard(hazard_01);
 my_hazard_set.addHazard(hazard_02);

 // Serialize the hazardset
 string msg = my_hazard_set.getSpec()

 // Post to the MOOSDB
 Notify("HAZARDSET_REPORT", msg);
\end{fileverb}
\vspace{0.1in}

\noindent
The above would result in the following posting to the MOOSDB:

\prevgreen
\begin{verbatim}
   HAZARDSET_REPORT = "source=betty # x=15,y=18,type=hazard,label=128 # 
                                      x=35,y=38,type=benign,label=92" 
\end{verbatim}
\postverb



</pre></body></html>