[Ns-developers] How to serialize a array

Providence SALUMU MUNGA psalumu at gmail.com
Thu Dec 25 02:22:59 PST 2008


Hi,

Le Tue, 23 Dec 2008 19:29:09 +0100,
Mathieu Lacage <mathieu.lacage at sophia.inria.fr> a écrit :

> 
> Sorry if I missed something obvious, but, what is wrong about this ?
> 
> for (int i = 0; i < 50; i++)
>   {
>     p->AddHeader (example[i]);
>   }

We had offline discussions with Nuno about his code whose portions
I paste below (with his permission):

void
PREQDestination::Serialize (Buffer::Iterator start) const
{
  Buffer::Iterator i = start;
  WriteTo (i, m_destinationaddress);
}

void 
PREQPerDestinationFlags::Serialize (Buffer::Iterator start) const
{
  Buffer::Iterator i = start;
  i.WriteU8 (m_value);
}

class PREQInformation : public Header;

void 
PREQInformation::Serialize (Buffer::Iterator start) const
{
  Buffer::Iterator i = start;
  while (j != m_destinationcount)
  {
   m_perdestinationflags[j].Serialize (i);
   m_destination[j].Serialize (i);
   j++;
  }

}

His problem stemmed from passing iterator parameters by value before
serializing arrays elements :
- Buffer::Iterator i = start,
- PREQPerDestinationFlags::Serialize (Buffer::Iterator start)
- PREQDestination::Serialize (Buffer::Iterator start)

Passing iterator parameters by reference in PREQPerDestinationFlags and
PREQDestination Serialize (...) fixed his problem indeed.

Regards,

-- 
Providence SALUMU M.

Doctorant, Département Logiciels-Réseaux
TELECOM SudParis

"If you can't be strong, be clever, and make peace with someone who is
strong. But it's always better to be strong yourself! Always!" -- B.O.
LowLow.



More information about the Ns-developers mailing list