tlv: Use the encoding/decoding functions for "double" from ndn-cxx

refs: #4615

Change-Id: I0bde7085876646f272ee6006f4d3cfbd513d4ffd
diff --git a/src/tlv/coordinate-lsa.cpp b/src/tlv/coordinate-lsa.cpp
index fc74241..20af101 100644
--- a/src/tlv/coordinate-lsa.cpp
+++ b/src/tlv/coordinate-lsa.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
 /*
- * Copyright (c) 2014-2018,  The University of Memphis,
+ * Copyright (c) 2014-2019,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -52,10 +52,10 @@
   size_t totalLength = 0;
 
   for (auto it = m_hyperbolicAngle.rbegin(); it != m_hyperbolicAngle.rend(); ++it) {
-    totalLength += prependDouble(block, ndn::tlv::nlsr::HyperbolicAngle, *it);
+    totalLength += ndn::encoding::prependDoubleBlock(block, ndn::tlv::nlsr::HyperbolicAngle, *it);
   }
 
-  totalLength += prependDouble(block, ndn::tlv::nlsr::HyperbolicRadius, m_hyperbolicRadius);
+  totalLength += ndn::encoding::prependDoubleBlock(block, ndn::tlv::nlsr::HyperbolicRadius, m_hyperbolicRadius);
 
   totalLength += m_lsaInfo.wireEncode(block);
 
@@ -109,22 +109,20 @@
     ++val;
   }
   else {
-    std::cout << "Missing required LsaInfo field" << std::endl;
     BOOST_THROW_EXCEPTION(Error("Missing required LsaInfo field"));
   }
 
   if (val != m_wire.elements_end() && val->type() == ndn::tlv::nlsr::HyperbolicRadius) {
-    m_hyperbolicRadius = ndn::tlv::nlsr::readDouble(*val);
+    m_hyperbolicRadius = ndn::encoding::readDouble(*val);
     ++val;
   }
   else {
-    std::cout << "Missing required HyperbolicRadius field" << std::endl;
     BOOST_THROW_EXCEPTION(Error("Missing required HyperbolicRadius field"));
   }
 
   for (; val != m_wire.elements_end(); ++val) {
     if (val->type() == ndn::tlv::nlsr::HyperbolicAngle) {
-      m_hyperbolicAngle.push_back(ndn::tlv::nlsr::readDouble(*val));
+      m_hyperbolicAngle.push_back(ndn::encoding::readDouble(*val));
     }
   }
 }
diff --git a/src/tlv/nexthop.cpp b/src/tlv/nexthop.cpp
index 2db9c3c..d05473e 100644
--- a/src/tlv/nexthop.cpp
+++ b/src/tlv/nexthop.cpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2018,  The University of Memphis,
+/*
+ * Copyright (c) 2014-2019,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -50,7 +50,7 @@
 {
   size_t totalLength = 0;
 
-  totalLength += prependDouble(block, ndn::tlv::nlsr::Double, m_cost);
+  totalLength += ndn::encoding::prependDoubleBlock(block, ndn::tlv::nlsr::CostDouble, m_cost);
 
   totalLength += block.prependByteArrayBlock(
     ndn::tlv::nlsr::Uri, reinterpret_cast<const uint8_t*>(m_uri.c_str()), m_uri.size());
@@ -108,7 +108,7 @@
     BOOST_THROW_EXCEPTION(Error("Missing required Uri field"));
   }
 
-  m_cost = ndn::tlv::nlsr::readDouble(*val);
+  m_cost = ndn::encoding::readDouble(*val);
 }
 
 std::ostream&
diff --git a/src/tlv/tlv-nlsr.hpp b/src/tlv/tlv-nlsr.hpp
index 0e400ea..265b2c6 100644
--- a/src/tlv/tlv-nlsr.hpp
+++ b/src/tlv/tlv-nlsr.hpp
@@ -1,6 +1,6 @@
 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/**
- * Copyright (c) 2014-2018,  The University of Memphis,
+/*
+ * Copyright (c) 2014-2019,  The University of Memphis,
  *                           Regents of the University of California,
  *                           Arizona Board of Regents.
  *
@@ -23,7 +23,6 @@
 #define NLSR_TLV_NLSR_HPP
 
 #include <ndn-cxx/encoding/tlv.hpp>
-#include <ndn-cxx/encoding/block-helpers.hpp>
 
 namespace ndn {
 namespace tlv {
@@ -41,7 +40,7 @@
   AdjacencyLsa     = 131,
   Adjacency        = 132,
   CoordinateLsa    = 133,
-  Double           = 134,
+  CostDouble       = 134,
   HyperbolicRadius = 135,
   HyperbolicAngle  = 136,
   NameLsa          = 137,
@@ -52,48 +51,9 @@
   Destination      = 142,
   NextHop          = 143,
   RoutingTable     = 144,
-  RouteTableEntry  = 145
+  RouteTableEntry  = 145,
 };
 
-/*! \brief Read a double from a TLV element
- *  \param block the TLV element
- *  \throw ndn::tlv::Error block does not contain a double
- *  \sa prependDouble
- */
-inline double
-readDouble(const ndn::Block& block)
-{
-  block.parse();
-  auto it = block.elements_begin();
-
-  double doubleFromBlock = 0.0;
-  if (it == it->elements_end() || it->type() != ndn::tlv::nlsr::Double ||
-      it->value_size() != sizeof(doubleFromBlock)) {
-    BOOST_THROW_EXCEPTION(ndn::tlv::Error("Block does not contain a double"));
-  }
-  memcpy(&doubleFromBlock, it->value(), sizeof(doubleFromBlock));
-  return doubleFromBlock;
-}
-
-/*! \brief Prepend a TLV element containing a double.
- *  \param encoder an EncodingBuffer or EncodingEstimator
- *  \param type TLV-TYPE number
- *  \param value double value
- */
-template<ndn::encoding::Tag TAG>
-inline size_t
-prependDouble(ndn::EncodingImpl<TAG>& encoder, uint32_t type, double value)
-{
-  size_t totalLength = 0;
-
-  const uint8_t* doubleBytes = reinterpret_cast<const uint8_t*>(&value);
-  totalLength = encoder.prependByteArrayBlock(ndn::tlv::nlsr::Double, doubleBytes, 8);
-  totalLength += encoder.prependVarNumber(totalLength);
-  totalLength += encoder.prependVarNumber(type);
-
-  return totalLength;
-}
-
 } // namespace nlsr
 } // namespace tlv
 } // namespace ndn