[Ns-developers] How to serialize a array

Mathieu Lacage mathieu.lacage at sophia.inria.fr
Thu Dec 25 01:13:00 PST 2008


On Tue, 2008-12-23 at 20:38 +0200, Mihai Oprea wrote:
> From what I learned so far, AddHeader will try to call
> example[i].Serialize(), and since example[i] is not a class already
> inside NS-3, we have to implement the serialization function
> ourselves.

Ah, I see, thanks for the explanation. 

You could trivially write:

PreqElementHeader : public Header
{
public:
  PreqElementHeader (PreqElement *el) { m_el = el;}

  ... Serialize (...) { m_el-Serialize (...);}
  
private:
  PreqElementHeader *m_el;
};

And, if you don't feel like writing this code over and over again, it is
fairly easy to templatize it (it would probably make sense to submit a
patch to add such a HeaderWrapper template to ns-3-dev/src/common)

template <typename T>
class HeaderWrapper {
 public:
  HeaderWrapper (T *el); 
  ...
};

(pick a better name for this template if you find one :)

regards,
Mathieu



More information about the Ns-developers mailing list