data: Corrections and separations for Data abstraction

MetaInfo and Signature are now defined in separate files

Change-Id: I8e370c7b3e057bf5f752e3271bf8375f44d603d0
diff --git a/include/ndn-cpp/key-locator.hpp b/include/ndn-cpp/key-locator.hpp
index f6c6f9d..3f53ef4 100644
--- a/include/ndn-cpp/key-locator.hpp
+++ b/include/ndn-cpp/key-locator.hpp
@@ -8,20 +8,20 @@
 #ifndef NDN_KEY_LOCATOR_HPP
 #define NDN_KEY_LOCATOR_HPP
 
-#include "encoding/tlv-element.hpp"
+#include "encoding/block.hpp"
 #include "name.hpp"
 
 namespace ndn {
 
-namespace error {
-struct KeyLocator : public std::runtime_error { KeyLocator(const std::string &what) : std::runtime_error(what) {} };
-} // error
-
 class KeyLocator {
 public:
+  struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+  
   enum {
     KeyLocator_None = -1,
-    KeyLocator_Name = 0
+    KeyLocator_Name = 0,
+    
+    KeyLocator_Unknown = 255
   };
   
   KeyLocator()
@@ -29,6 +29,12 @@
   {
   }
 
+  inline const Block& 
+  wireEncode() const;
+
+  inline void 
+  wireDecode(const Block &value);
+  
   inline bool
   empty() const
   {
@@ -37,42 +43,79 @@
   
   uint32_t 
   getType() const { return type_; }
-  
-  void 
-  setType(uint32_t type) { type_ = type; }
-    
-  const Block& 
-  getValue() const { return value_; }
-
-  void 
-  setValue(const Block &value) { value_ = value; }
-
+      
   ////////////////////////////////////////////////////////
   // Helper methods for different types of key locators
   //
   // For now only Name type is actually supported
   
-  Name
-  getName() const
-  {
-    if (type_ != KeyLocator_Name)
-      throw error::KeyLocator("Requested Name, but KeyLocator is not of the Name type");
+  inline const Name&
+  getName() const;
 
-    return Name(getValue());
-  }
-
-  void
-  setName(const Name &name)
-  {
-    type_ = KeyLocator_Name;
-    value_ = name.wireEncode();
-  }
+  inline void
+  setName(const Name &name);
   
 private:
   uint32_t type_;
-  Block value_;
+  Name name_;
+  
+  mutable Block wire_;
 };
 
+inline const Block& 
+KeyLocator::wireEncode() const
+{
+  if (empty())
+    throw Error("Wire encoding requested, but KeyLocator is empty");
+
+  if (wire_.hasWire())
+    return wire_;
+  
+  if (type_ != KeyLocator_Name)
+    throw Error("Unsupported KeyLocator type");
+  
+  // KeyLocator
+  wire_ = Block(Tlv::KeyLocator);
+  wire_.push_back(name_.wireEncode());
+  wire_.encode();
+  
+  return wire_;
 }
 
+inline void 
+KeyLocator::wireDecode(const Block &value)
+{
+  wire_ = value;
+  wire_.parse();
+  
+  if (!wire_.getAll().empty() && wire_.getAll().front().type() == Tlv::Name)
+    {
+      type_ = KeyLocator_Name;
+      name_.wireDecode(wire_.getAll().front());
+    }
+  else
+    {
+      type_ = KeyLocator_Unknown;
+    }
+}
+
+inline const Name&
+KeyLocator::getName() const
+{
+  if (type_ != KeyLocator_Name)
+    throw Error("Requested Name, but KeyLocator is not of the Name type");
+
+  return name_;
+}
+
+inline void
+KeyLocator::setName(const Name &name)
+{
+  type_ = KeyLocator_Name;
+  name_ = name;
+}
+
+
+} // namespace ndn
+
 #endif