11 #include "wire-ndnsim.h" 
   12 #include <boost/foreach.hpp> 
   23 NdnSim::SerializeName (Buffer::Iterator &i, 
const Name &name)
 
   25   Buffer::Iterator start = i;
 
   27   i.WriteU16 (static_cast<uint16_t> (SerializedSizeName (name)-2));
 
   29   for (Name::const_iterator item = name.
begin ();
 
   33       i.WriteU16 (static_cast<uint16_t> (item->size ()));
 
   34       i.Write (reinterpret_cast<const uint8_t*> (item->buf ()), item->size ());
 
   37   return i.GetDistanceFrom (start);
 
   41 NdnSim::SerializedSizeName (
const Name &name)
 
   43   size_t nameSerializedSize = 2;
 
   45   for (Name::const_iterator i = name.
begin ();
 
   49       nameSerializedSize += 2 + i->size ();
 
   51   NS_ASSERT_MSG (nameSerializedSize < 30000, 
"Name is too long (> 30kbytes)");
 
   53   return nameSerializedSize;
 
   57 NdnSim::DeserializeName (Buffer::Iterator &i)
 
   59   Ptr<Name> name = Create<Name> ();
 
   61   uint16_t nameLength = i.ReadU16 ();
 
   62   while (nameLength > 0)
 
   64       uint16_t length = i.ReadU16 ();
 
   65       nameLength = nameLength - 2 - length;
 
   70       name->append (tmp, length);
 
   78 NdnSim::SerializeExclude (Buffer::Iterator &i, 
const Exclude &exclude)
 
   80   Buffer::Iterator start = i;
 
   82   i.WriteU16 (static_cast<uint16_t> (SerializedSizeExclude (exclude)-2));
 
   84   for (Exclude::const_reverse_iterator item = exclude.
rbegin ();
 
   85        item != exclude.
rend ();
 
   88       if (!item->first.empty ())
 
   90           i.WriteU8 (ExcludeNameType);
 
   91           i.WriteU16 (static_cast<uint16_t> (item->first.size ()));
 
   92           i.Write (reinterpret_cast<const uint8_t*> (item->first.buf ()), item->first.size ());
 
   96           i.WriteU8 (ExcludeAnyType);
 
   99   return i.GetDistanceFrom (start);
 
  103 NdnSim::SerializedSizeExclude (
const Exclude &exclude)
 
  105   size_t excludeSerializedSize = 2;
 
  107   for (Exclude::const_reverse_iterator item = exclude.
rbegin ();
 
  108        item != exclude.
rend ();
 
  111       if (!item->first.empty ())
 
  113           excludeSerializedSize += 1 + 2 + item->first.size ();
 
  117           excludeSerializedSize += 1;
 
  121   return excludeSerializedSize;
 
  125 NdnSim::DeserializeExclude (Buffer::Iterator &i)
 
  127   Ptr<Exclude> exclude = Create<Exclude> ();
 
  129   uint16_t excludeLength = i.ReadU16 ();
 
  130   while (excludeLength > 0)
 
  132       uint8_t type = i.ReadU8 ();
 
  135       if (type == ExcludeAnyType)
 
  139       else if (type == ExcludeNameType)
 
  141           uint16_t length = i.ReadU16 ();
 
  142           excludeLength = excludeLength - 2 - length;
 
  145           i.Read (tmp, length);
 
  148           if (excludeLength > 0)
 
  150               uint8_t type = i.ReadU8 ();
 
  151               if (type != ExcludeAnyType)
 
  166           NS_FATAL_ERROR (
"Incorrect format of Exclude filter");
 
const_reverse_iterator rbegin() const 
Get begin iterator of the exclude terms. 
 
Name::const_iterator end() const 
End iterator (const) 
 
Class to represent Exclude component in NDN interests. 
 
Name::const_iterator begin() const 
Begin iterator (const) 
 
const_reverse_iterator rend() const 
Get end iterator of the exclude terms. 
 
Class to representing binary blob of NDN name component.