**breaking** consolidate src/tlv/*lsa* into src/lsa/*lsa*

Lsa de/serialize functions are replaced by wireEncode/Decode.
Update LSA wire formats. Change TLV assignments as required.
Update nlsrc to print using new encoding.

refs: #4787

Change-Id: Ie8d40b7836d51ea5bb444c8db208dc2b3a0d1cec
diff --git a/src/adjacent.cpp b/src/adjacent.cpp
index 1ae047e..9e85d4a 100644
--- a/src/adjacent.cpp
+++ b/src/adjacent.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /**
- * Copyright (c) 2014-2019,  The University of Memphis,
+ * Copyright (c) 2014-2020,  The University of Memphis,
  *                           Regents of the University of California
  *
  * This file is part of NLSR (Named-data Link State Routing).
@@ -20,11 +20,7 @@
 
 #include "adjacent.hpp"
 #include "logger.hpp"
-
-#include <iostream>
-#include <string>
-#include <cmath>
-#include <limits>
+#include "tlv/tlv-nlsr.hpp"
 
 namespace nlsr {
 
@@ -43,6 +39,11 @@
 {
 }
 
+Adjacent::Adjacent(const ndn::Block& block)
+{
+  wireDecode(block);
+}
+
 Adjacent::Adjacent(const ndn::Name& an)
     : m_name(an)
     , m_faceUri()
@@ -78,6 +79,87 @@
   m_linkCost = lc;
 }
 
+NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Adjacent);
+
+template<ndn::encoding::Tag TAG>
+size_t
+Adjacent::wireEncode(ndn::EncodingImpl<TAG>& encoder) const
+{
+  size_t totalLength = 0;
+
+  totalLength += prependDoubleBlock(encoder, ndn::tlv::nlsr::Cost, m_linkCost);
+
+  totalLength += prependStringBlock(encoder, ndn::tlv::nlsr::Uri, m_faceUri.toString());
+
+  totalLength += m_name.wireEncode(encoder);
+
+  totalLength += encoder.prependVarNumber(totalLength);
+  totalLength += encoder.prependVarNumber(ndn::tlv::nlsr::Adjacency);
+
+  return totalLength;
+}
+
+const ndn::Block&
+Adjacent::wireEncode() const
+{
+  if (m_wire.hasWire()) {
+    return m_wire;
+  }
+
+  ndn::EncodingEstimator estimator;
+  size_t estimatedSize = wireEncode(estimator);
+
+  ndn::EncodingBuffer buffer(estimatedSize, 0);
+  wireEncode(buffer);
+
+  m_wire = buffer.block();
+
+  return m_wire;
+}
+
+void
+Adjacent::wireDecode(const ndn::Block& wire)
+{
+  m_name.clear();
+  m_faceUri = ndn::FaceUri();
+  m_linkCost = 0;
+
+  m_wire = wire;
+
+  if (m_wire.type() != ndn::tlv::nlsr::Adjacency) {
+    BOOST_THROW_EXCEPTION(Error("Expected Adjacency Block, but Block is of a different type: #" +
+                                ndn::to_string(m_wire.type())));
+  }
+
+  m_wire.parse();
+
+  ndn::Block::element_const_iterator val = m_wire.elements_begin();
+
+  if (val != m_wire.elements_end() && val->type() == ndn::tlv::Name) {
+    m_name.wireDecode(*val);
+    ++val;
+  }
+  else {
+    BOOST_THROW_EXCEPTION(Error("Missing required Name field"));
+  }
+
+  if (val != m_wire.elements_end() && val->type() == ndn::tlv::nlsr::Uri) {
+    m_faceUri = ndn::FaceUri(readString(*val));
+    ++val;
+  }
+  else {
+    BOOST_THROW_EXCEPTION(Error("Missing required Uri field"));
+  }
+
+  if (val != m_wire.elements_end() && val->type() == ndn::tlv::nlsr::Cost) {
+    m_linkCost = ndn::encoding::readDouble(*val);
+    ++val;
+  }
+  else {
+    BOOST_THROW_EXCEPTION(Error("Missing required Cost field"));
+  }
+}
+
 bool
 Adjacent::operator==(const Adjacent& adjacent) const
 {
@@ -98,9 +180,11 @@
 std::ostream&
 operator<<(std::ostream& os, const Adjacent& adjacent)
 {
-  os << "Adjacent: " << adjacent.m_name << "\n Connecting FaceUri: " << adjacent.m_faceUri
-     << "\n Link cost: " << adjacent.m_linkCost << "\n Status: " << adjacent.m_status
-     << "\n Interest Timed Out: " << adjacent.m_interestTimedOutNo << std::endl;
+  os << "Adjacent: " << adjacent.m_name
+     << "\n\t\tConnecting FaceUri: " << adjacent.m_faceUri
+     << "\n\t\tLink cost: " << adjacent.m_linkCost
+     << "\n\t\tStatus: " << adjacent.m_status
+     << "\n\t\tInterest Timed Out: " << adjacent.m_interestTimedOutNo << std::endl;
   return os;
 }