model: Slight modification with wire format processing

Now it is possible to convert Name from/to wire format via ndn::Face
helper method (since Face is getting configured with specific wire
format)

Refs #1008 (http://redmine.named-data.net/issues/1008)
diff --git a/model/wire/ndnsim/wire-ndnsim.cc b/model/wire/ndnsim/wire-ndnsim.cc
new file mode 100644
index 0000000..7d383a4
--- /dev/null
+++ b/model/wire/ndnsim/wire-ndnsim.cc
@@ -0,0 +1,78 @@
+/** -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/* 
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Alexander Afanasyev
+ * 
+ * GNU 3.0 license, See the LICENSE file for more information
+ * 
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#include "wire-ndnsim.h"
+#include <boost/foreach.hpp>
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+
+//////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////
+
+size_t
+NdnSim::SerializeName (Buffer::Iterator &i, const Name &name)
+{
+  Buffer::Iterator start = i;
+
+  i.WriteU16 (static_cast<uint16_t> (SerializedSizeName (name)-2));
+
+  for (std::list<std::string>::const_iterator item = name.begin ();
+       item != name.end ();
+       item++)
+    {
+      i.WriteU16 (static_cast<uint16_t> (item->size ()));
+      i.Write (reinterpret_cast<const uint8_t*> (item->c_str ()), item->size ());
+    }
+
+  return i.GetDistanceFrom (start);
+}
+
+size_t
+NdnSim::SerializedSizeName (const Name &name)
+{
+  size_t nameSerializedSize = 2;
+
+  for (std::list<std::string>::const_iterator i = name.begin ();
+       i != name.end ();
+       i++)
+    {
+      nameSerializedSize += 2 + i->size ();
+    }
+  NS_ASSERT_MSG (nameSerializedSize < 30000, "Name is too long (> 30kbytes)");
+
+  return nameSerializedSize;
+}
+
+Ptr<Name>
+NdnSim::DeserializeName (Buffer::Iterator &i)
+{
+  Ptr<Name> name = Create<Name> ();
+
+  uint16_t nameLength = i.ReadU16 ();
+  while (nameLength > 0)
+    {
+      uint16_t length = i.ReadU16 ();
+      nameLength = nameLength - 2 - length;
+
+      uint8_t tmp[length];
+      i.Read (tmp, length);
+
+      name->Add (std::string (reinterpret_cast<const char*> (tmp), length));
+    }
+
+  return name;
+}
+
+} // wire
+
+NDN_NAMESPACE_END
diff --git a/model/wire/ndnsim/wire-ndnsim.h b/model/wire/ndnsim/wire-ndnsim.h
new file mode 100644
index 0000000..6e4b1e5
--- /dev/null
+++ b/model/wire/ndnsim/wire-ndnsim.h
@@ -0,0 +1,62 @@
+/** -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/* 
+ * Copyright (c) 2013, Regents of the University of California
+ *                     Alexander Afanasyev
+ * 
+ * GNU 3.0 license, See the LICENSE file for more information
+ * 
+ * Author: Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ */
+
+#ifndef NDN_WIRE_NDNSIM_SYNTAX_H
+#define NDN_WIRE_NDNSIM_SYNTAX_H
+
+#include "ns3/ptr.h"
+#include "ns3/nstime.h"
+#include "ns3/buffer.h"
+
+#include "ns3/ndn-common.h"
+#include "ns3/ndn-name.h"
+
+NDN_NAMESPACE_BEGIN
+
+namespace wire {
+
+/**
+ * \brief Helper to encode ndnSIM wire elements
+ */
+class NdnSim
+{
+public:
+  /**
+   * @brief Append Name in ndnSIM encoding
+   * @param start Buffer to store serialized Interest
+   * @param name constant reference to Name object
+   *
+   * @returns written length
+   */
+  static size_t
+  SerializeName (Buffer::Iterator &start, const Name &name);
+
+  /**
+   * @brief Estimate size of Name in ndnSIM encoding
+   * @param name constant reference to Name object
+   * @returns estimated length
+   */
+  static size_t
+  SerializedSizeName (const Name &name);
+
+  /**
+   * @brief Deserialize Name from ndnSIM encodeing
+   * @param start Buffer that stores serialized Interest
+   * @param name Name object
+   */
+  static Ptr<Name>
+  DeserializeName (Buffer::Iterator &start);
+}; // NdnSim
+
+} // wire
+
+NDN_NAMESPACE_END
+
+#endif // NDN_WIRE_NDNSIM_SYNTAX_H