model: Enabling serialization/deserialization of Exclude filter in ndnSIM wire format

Refs #1009 (http://redmine.named-data.net/issues/1009)
diff --git a/model/wire/ndnsim/wire-ndnsim.cc b/model/wire/ndnsim/wire-ndnsim.cc
index 66c2c44..013d78d 100644
--- a/model/wire/ndnsim/wire-ndnsim.cc
+++ b/model/wire/ndnsim/wire-ndnsim.cc
@@ -73,6 +73,103 @@
   return name;
 }
 
+
+size_t
+NdnSim::SerializeExclude (Buffer::Iterator &i, const Exclude &exclude)
+{
+  Buffer::Iterator start = i;
+
+  i.WriteU16 (static_cast<uint16_t> (SerializedSizeExclude (exclude)-2));
+
+  for (Exclude::const_reverse_iterator item = exclude.rbegin ();
+       item != exclude.rend ();
+       item++)
+    {
+      if (!item->first.empty ())
+        {
+          i.WriteU8 (ExcludeNameType);
+          i.WriteU16 (static_cast<uint16_t> (item->first.size ()));
+          i.Write (reinterpret_cast<const uint8_t*> (item->first.buf ()), item->first.size ());
+        }
+      if (item->second)
+        {
+          i.WriteU8 (ExcludeAnyType);
+        }
+    }
+  return i.GetDistanceFrom (start);
+}
+
+size_t
+NdnSim::SerializedSizeExclude (const Exclude &exclude)
+{
+  size_t excludeSerializedSize = 2;
+
+  for (Exclude::const_reverse_iterator item = exclude.rbegin ();
+       item != exclude.rend ();
+       item++)
+    {
+      if (!item->first.empty ())
+        {
+          excludeSerializedSize += 1 + 2 + item->first.size ();
+        }
+      if (item->second)
+        {
+          excludeSerializedSize += 1;
+        }
+    }
+
+  return excludeSerializedSize;
+}
+
+Ptr<Exclude>
+NdnSim::DeserializeExclude (Buffer::Iterator &i)
+{
+  Ptr<Exclude> exclude = Create<Exclude> ();
+
+  uint16_t excludeLength = i.ReadU16 ();
+  while (excludeLength > 0)
+    {
+      uint8_t type = i.ReadU8 ();
+      excludeLength --;
+      
+      if (type == ExcludeAnyType)
+        {
+          exclude->appendExclude (name::Component (), true);
+        }
+      else if (type == ExcludeNameType)
+        {
+          uint16_t length = i.ReadU16 ();
+          excludeLength = excludeLength - 2 - length;
+
+          uint8_t tmp[length];
+          i.Read (tmp, length);
+
+          bool any = false;
+          if (excludeLength > 0)
+            {
+              uint8_t type = i.ReadU8 ();
+              if (type != ExcludeAnyType)
+                {
+                  i.Prev ();
+                }
+              else
+                {
+                  any = true;
+                  excludeLength --;
+                }
+            }
+
+          exclude->appendExclude (name::Component (tmp, length), any);
+        }
+      else
+        {
+          NS_FATAL_ERROR ("Incorrect format of Exclude filter");
+        }
+    }
+  return exclude;
+}
+
+
 } // wire
 
 NDN_NAMESPACE_END