name: More changes related to TLV encoding/decoding implementation

Change-Id: Ib1d7b2e7fdc57ac96b0193858f13e6b3297013d5
diff --git a/include/ndn-cpp/name.hpp b/include/ndn-cpp/name.hpp
index 00f6d21..d2c1afe 100644
--- a/include/ndn-cpp/name.hpp
+++ b/include/ndn-cpp/name.hpp
@@ -72,6 +72,11 @@
     {
     }
     
+    Component(const char *string)
+      : ConstBufferPtr (new Buffer(string, ::strlen(string)))
+    {
+    }
+
     const Buffer& 
     getValue() const { return **this; }
 
@@ -292,6 +297,9 @@
 
   const Block &
   wireEncode() const;
+
+  void
+  wireDecode(const Block &wire);
   
   /**
    * Parse the uri according to the NDN URI Scheme and set the name with the components.
diff --git a/src/name.cpp b/src/name.cpp
index 3d9b395..44e6039 100644
--- a/src/name.cpp
+++ b/src/name.cpp
@@ -49,7 +49,7 @@
   return Component(value);
 }
 
-Name::Component 
+Name::Component
 Name::Component::fromNumberWithMarker(uint64_t number, uint8_t marker)
 {
   ptr_lib::shared_ptr<Buffer> value(new Buffer);
@@ -332,4 +332,39 @@
   return os;
 }
 
+const Block &
+Name::wireEncode() const
+{
+  if (wire_.hasWire())
+    return wire_;
+
+  wire_ = Block(Tlv::Name);
+  for (Name::const_iterator i = begin(); i != end(); i++) {
+    OBufferStream os;
+    Tlv::writeVarNumber(os, Tlv::NameComponent);
+    Tlv::writeVarNumber(os, i->getValue().size());
+    os.write(reinterpret_cast<const char*>(i->getValue().buf()), i->getValue().size());
+
+    wire_.push_back(Block(os.buf()));
+  }
+        
+  wire_.encode();
+  return wire_;
+}
+
+void
+Name::wireDecode(const Block &wire)
+{
+  wire_ = wire;
+  wire_.parse();
+
+  for (Block::element_const_iterator i = wire_.getAll().begin();
+       i != wire_.getAll().end();
+       ++i)
+    {
+      append(i->value(), i->value_size());
+    }
+}
+
+
 }