src: Refactoring common.hpp and minimizing exposed includes

Face class has relatively large rewrite to hide internals using
Implementor pattern.  As of this commit, <boost/asio.hpp> is not
automatically included whenever ndn-cxx/face.hpp is included.  If it is
needed to directly work with io_service, asio.hpp should be specifically
included.

Change-Id: Ie742b851025b4e3da634eb981319df0f42937855
diff --git a/src/encoding/block-helpers.hpp b/src/encoding/block-helpers.hpp
index 317cd13..36c9474 100644
--- a/src/encoding/block-helpers.hpp
+++ b/src/encoding/block-helpers.hpp
@@ -12,21 +12,24 @@
  * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
  */
 
-#ifndef NDN_BLOCK_HELPERS_HPP
-#define NDN_BLOCK_HELPERS_HPP
+#ifndef NDN_ENCODING_BLOCK_HELPERS_HPP
+#define NDN_ENCODING_BLOCK_HELPERS_HPP
 
 #include "block.hpp"
+#include "encoding-buffer.hpp"
 
 namespace ndn {
 
 inline Block
 nonNegativeIntegerBlock(uint32_t type, uint64_t value)
 {
-  OBufferStream os;
-  Tlv::writeVarNumber(os, type);
-  Tlv::writeVarNumber(os, Tlv::sizeOfNonNegativeInteger(value));
-  Tlv::writeNonNegativeInteger(os, value);
-  return Block(os.buf());
+  EncodingEstimator estimator;
+  size_t totalLength = prependNonNegativeIntegerBlock(estimator, type, value);
+
+  EncodingBuffer encoder(totalLength, 0);
+  prependNonNegativeIntegerBlock(encoder, type, value);
+
+  return encoder.block();
 }
 
 inline uint64_t
@@ -39,45 +42,49 @@
 inline Block
 booleanBlock(uint32_t type)
 {
-  OBufferStream os;
-  Tlv::writeVarNumber(os, type);
-  Tlv::writeVarNumber(os, 0);
-  return Block(os.buf());
+  EncodingEstimator estimator;
+  size_t totalLength = prependBooleanBlock(estimator, type);
+
+  EncodingBuffer encoder(totalLength, 0);
+  prependBooleanBlock(encoder, type);
+
+  return encoder.block();
+}
+
+inline Block
+dataBlock(uint32_t type, const uint8_t* data, size_t dataSize)
+{
+  EncodingEstimator estimator;
+  size_t totalLength = prependByteArrayBlock(estimator, type, data, dataSize);
+
+  EncodingBuffer encoder(totalLength, 0);
+  prependByteArrayBlock(encoder, type, data, dataSize);
+
+  return encoder.block();
 }
 
 inline Block
 dataBlock(uint32_t type, const char* data, size_t dataSize)
 {
-  OBufferStream os;
-  Tlv::writeVarNumber(os, type);
-  Tlv::writeVarNumber(os, dataSize);
-  os.write(data, dataSize);
-
-  return Block(os.buf());
+  return dataBlock(type, reinterpret_cast<const uint8_t*>(data), dataSize);
 }
 
-inline Block
-dataBlock(uint32_t type, const unsigned char* data, size_t dataSize)
-{
-  return dataBlock(type, reinterpret_cast<const char*>(data), dataSize);
-}
+// template<class InputIterator>
+// inline Block
+// dataBlock(uint32_t type, InputIterator first, InputIterator last)
+// {
+//   size_t dataSize = 0;
+//   for (InputIterator i = first; i != last; i++)
+//     ++dataSize;
 
-template<class InputIterator>
-inline Block
-dataBlock(uint32_t type, InputIterator first, InputIterator last)
-{
-  size_t dataSize = 0;
-  for (InputIterator i = first; i != last; i++)
-    ++dataSize;
+//   OBufferStream os;
+//   Tlv::writeVarNumber(os, type);
+//   Tlv::writeVarNumber(os, dataSize);
+//   std::copy(first, last, std::ostream_iterator<uint8_t>(os));
 
-  OBufferStream os;
-  Tlv::writeVarNumber(os, type);
-  Tlv::writeVarNumber(os, dataSize);
-  std::copy(first, last, std::ostream_iterator<uint8_t>(os));
-
-  return Block(os.buf());
-}
+//   return Block(os.buf());
+// }
 
 } // namespace ndn
 
-#endif // NDN_BLOCK_HELPERS_HPP
+#endif // NDN_ENCODING_BLOCK_HELPERS_HPP
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index e3730c3..3f0cee3 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -15,11 +15,18 @@
 #include "common.hpp"
 
 #include "block.hpp"
+#include "block-helpers.hpp"
+
 #include "tlv.hpp"
 #include "encoding-buffer.hpp"
+#include "buffer-stream.hpp"
+
+#include <boost/lexical_cast.hpp>
 
 namespace ndn {
 
+const size_t MAX_SIZE_OF_BLOCK_FROM_STREAM = 8800;
+
 Block::Block()
   : m_type(std::numeric_limits<uint32_t>::max())
 {
@@ -96,44 +103,6 @@
     }
 }
 
-Block::Block(std::istream& is)
-{
-  std::istream_iterator<uint8_t> tmp_begin(is);
-  std::istream_iterator<uint8_t> tmp_end;
-
-  m_type = Tlv::readType(tmp_begin, tmp_end);
-  uint64_t length = Tlv::readVarNumber(tmp_begin, tmp_end);
-
-  // We may still have some problem here, if some exception happens in this constructor,
-  // we may completely lose all the bytes extracted from the stream.
-
-  OBufferStream os;
-  size_t headerLength = Tlv::writeVarNumber(os, m_type);
-  headerLength += Tlv::writeVarNumber(os, length);
-
-  char* buf = new char[length];
-  buf[0] = *tmp_begin;
-  is.read(buf+1, length-1);
-
-  if (length != static_cast<uint64_t>(is.gcount()) + 1)
-    {
-      delete [] buf;
-      throw Tlv::Error("Not enough data in the buffer to fully parse TLV");
-    }
-
-  os.write(buf, length);
-  delete [] buf;
-
-  m_buffer = os.buf();
-
-  m_begin = m_buffer->begin();
-  m_end = m_buffer->end();
-  m_size = m_end - m_begin;
-
-  m_value_begin = m_buffer->begin() + headerLength;
-  m_value_end   = m_buffer->end();
-}
-
 
 Block::Block(const uint8_t* buffer, size_t maxlength)
 {
@@ -210,6 +179,32 @@
   m_size = Tlv::sizeOfVarNumber(m_type) + Tlv::sizeOfVarNumber(value_size()) + value_size();
 }
 
+Block
+Block::fromStream(std::istream& is)
+{
+  std::istream_iterator<uint8_t> tmp_begin(is);
+  std::istream_iterator<uint8_t> tmp_end;
+
+  uint32_t type = Tlv::readType(tmp_begin, tmp_end);
+  uint64_t length = Tlv::readVarNumber(tmp_begin, tmp_end);
+
+  if (length > MAX_SIZE_OF_BLOCK_FROM_STREAM)
+    throw Tlv::Error("Length of block from stream is too large");
+
+  // We may still have some problem here, if some exception happens,
+  // we may completely lose all the bytes extracted from the stream.
+
+  char buf[MAX_SIZE_OF_BLOCK_FROM_STREAM];
+  buf[0] = *tmp_begin;
+  is.read(buf+1, length-1);
+
+  if (length != static_cast<uint64_t>(is.gcount()) + 1) {
+    throw Tlv::Error("Not enough data in the buffer to fully parse TLV");
+  }
+
+  return dataBlock(type, buf, length);
+}
+
 bool
 Block::fromBuffer(const ConstBufferPtr& wire, size_t offset, Block& block)
 {
@@ -376,4 +371,21 @@
                begin, end);
 }
 
+const Block&
+Block::get(uint32_t type) const
+{
+  for (element_const_iterator i = m_subBlocks.begin();
+       i != m_subBlocks.end();
+       i++)
+    {
+      if (i->type() == type)
+        {
+          return *i;
+        }
+    }
+
+  throw Error("(Block::get) Requested a non-existed type [" +
+              boost::lexical_cast<std::string>(type) + "] from Block");
+}
+
 } // namespace ndn
diff --git a/src/encoding/block.hpp b/src/encoding/block.hpp
index d23e8c8..d1a762f 100644
--- a/src/encoding/block.hpp
+++ b/src/encoding/block.hpp
@@ -12,8 +12,8 @@
  * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
  */
 
-#ifndef NDN_BLOCK_HPP
-#define NDN_BLOCK_HPP
+#ifndef NDN_ENCODING_BLOCK_HPP
+#define NDN_ENCODING_BLOCK_HPP
 
 #include "../common.hpp"
 
@@ -83,12 +83,6 @@
 
   Block(const void* buffer, size_t maxlength);
 
-  /*
-   * @brief A helper version of a constructor to create Block from the stream.
-   */
-  explicit
-  Block(std::istream& is);
-
   /**
    * @brief Create Block from the wire buffer (no parsing)
    *
@@ -124,6 +118,23 @@
   explicit
   Block(uint32_t type, const Block& value);
 
+  /*
+   * @brief A helper version of a constructor to create Block from the stream
+   *
+   * @deprecated Use Block::fromStream instead
+   */
+  explicit
+  Block(std::istream& is)
+  {
+    *this = Block::fromStream(is);
+  }
+
+  /*
+   * @brief A helper version of a constructor to create Block from the stream.
+   */
+  Block
+  fromStream(std::istream& is);
+
   /**
    * @brief Try to construct block from Buffer, referencing data block pointed by wire
    *
@@ -327,23 +338,6 @@
   return m_type;
 }
 
-inline const Block&
-Block::get(uint32_t type) const
-{
-  for (element_const_iterator i = m_subBlocks.begin();
-       i != m_subBlocks.end();
-       i++)
-    {
-      if (i->type() == type)
-        {
-          return *i;
-        }
-    }
-
-  throw Error("(Block::get) Requested a non-existed type [" +
-              boost::lexical_cast<std::string>(type) + "] from Block");
-}
-
 inline Block::element_const_iterator
 Block::find(uint32_t type) const
 {
@@ -504,6 +498,4 @@
 
 } // ndn
 
-#include "block-helpers.hpp"
-
-#endif // NDN_BLOCK_HPP
+#endif // NDN_ENCODING_BLOCK_HPP
diff --git a/src/encoding/buffer-stream.hpp b/src/encoding/buffer-stream.hpp
new file mode 100644
index 0000000..127d457
--- /dev/null
+++ b/src/encoding/buffer-stream.hpp
@@ -0,0 +1,100 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
+/**
+ * Copyright (c) 2013-2014,  Regents of the University of California.
+ * All rights reserved.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * This file licensed under New BSD License.  See COPYING for detailed information about
+ * ndn-cxx library copyright, permissions, and redistribution restrictions.
+ *
+ * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
+ */
+
+#ifndef NDN_ENCODING_BUFFER_STREAM_HPP
+#define NDN_ENCODING_BUFFER_STREAM_HPP
+
+#include "buffer.hpp"
+
+#include <boost/iostreams/detail/ios.hpp>
+#include <boost/iostreams/categories.hpp>
+#include <boost/iostreams/stream.hpp>
+
+namespace ndn {
+
+/// @cond include_hidden
+namespace iostreams
+{
+
+class buffer_append_device
+{
+public:
+  typedef char char_type;
+  typedef boost::iostreams::sink_tag category;
+
+  buffer_append_device(Buffer& container)
+    : m_container(container)
+  {
+  }
+
+  std::streamsize
+  write(const char_type* s, std::streamsize n)
+  {
+    std::copy(s, s+n, std::back_inserter(m_container));
+    return n;
+  }
+
+protected:
+  Buffer& m_container;
+};
+
+} // iostreams
+/// @endcond
+
+/**
+ * Class implementing interface similar to ostringstream, but to construct ndn::Buffer
+ *
+ * The benefit of using stream interface is that it provides automatic buffering of
+ * written data and eliminates (or reduces) overhead of resizing the underlying buffer
+ * when writing small pieces of data.
+ *
+ * Usage example:
+ * @code
+ *      OBufferStream obuf;
+ *      obuf.put(0);
+ *      obuf.write(another_buffer, another_buffer_size);
+ *      shared_ptr<Buffer> buf = obuf.get();
+ * @endcode
+ */
+class OBufferStream : public boost::iostreams::stream<iostreams::buffer_append_device>
+{
+public:
+  /**
+   * Default constructor
+   */
+  OBufferStream()
+    : m_buffer(make_shared<Buffer>())
+    , m_device(*m_buffer)
+  {
+    open(m_device);
+  }
+
+  /**
+   * Flush written data to the stream and return shared pointer to the underlying buffer
+   */
+  shared_ptr<Buffer>
+  buf()
+  {
+    flush();
+    return m_buffer;
+  }
+
+private:
+  BufferPtr m_buffer;
+  iostreams::buffer_append_device m_device;
+};
+
+} // ndn
+
+#endif // NDN_ENCODING_BUFFER_STREAM_HPP
diff --git a/src/encoding/buffer.hpp b/src/encoding/buffer.hpp
index d4b14c0..5701511 100644
--- a/src/encoding/buffer.hpp
+++ b/src/encoding/buffer.hpp
@@ -12,11 +12,13 @@
  * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
  */
 
-#ifndef NDN_BUFFER_HPP
-#define NDN_BUFFER_HPP
+#ifndef NDN_ENCODING_BUFFER_HPP
+#define NDN_ENCODING_BUFFER_HPP
 
 #include "../common.hpp"
 
+#include <vector>
+
 namespace ndn {
 
 class Buffer;
@@ -134,78 +136,6 @@
   }
 };
 
-/// @cond include_hidden
-namespace iostreams
-{
-
-class buffer_append_device
-{
-public:
-  typedef char char_type;
-  typedef boost::iostreams::sink_tag category;
-
-  buffer_append_device(Buffer& container)
-  : m_container(container)
-  {
-  }
-
-  std::streamsize
-  write(const char_type* s, std::streamsize n)
-  {
-    std::copy(s, s+n, std::back_inserter(m_container));
-    return n;
-  }
-
-protected:
-  Buffer& m_container;
-};
-
-} // iostreams
-/// @endcond
-
-/**
- * Class implementing interface similar to ostringstream, but to construct ndn::Buffer
- *
- * The benefit of using stream interface is that it provides automatic buffering of
- * written data and eliminates (or reduces) overhead of resizing the underlying buffer
- * when writing small pieces of data.
- *
- * Usage example:
- * @code
- *      OBufferStream obuf;
- *      obuf.put(0);
- *      obuf.write(another_buffer, another_buffer_size);
- *      shared_ptr<Buffer> buf = obuf.get();
- * @endcode
- */
-struct OBufferStream : public boost::iostreams::stream<iostreams::buffer_append_device>
-{
-  /**
-   * Default constructor
-   */
-  OBufferStream()
-    : m_buffer(make_shared<Buffer>())
-    , m_device(*m_buffer)
-  {
-    open(m_device);
-  }
-
-  /**
-   * Flush written data to the stream and return shared pointer to the underlying buffer
-   */
-  shared_ptr<Buffer>
-  buf()
-  {
-    flush();
-    return m_buffer;
-  }
-
-private:
-  BufferPtr m_buffer;
-  iostreams::buffer_append_device m_device;
-};
-
-
 } // ndn
 
-#endif // NDN_BUFFER_HPP
+#endif // NDN_ENCODING_BUFFER_HPP
diff --git a/src/encoding/cryptopp/asn_ext.hpp b/src/encoding/cryptopp/asn_ext.hpp
index bbfe733..0d64d40 100644
--- a/src/encoding/cryptopp/asn_ext.hpp
+++ b/src/encoding/cryptopp/asn_ext.hpp
@@ -19,6 +19,8 @@
 #include "../../common.hpp"
 #include "../../security/cryptopp.hpp"
 
+#include "../../util/time.hpp"
+
 namespace ndn {
 
 size_t
diff --git a/src/encoding/encoding-buffer.hpp b/src/encoding/encoding-buffer.hpp
index 07ee33d..0464287 100644
--- a/src/encoding/encoding-buffer.hpp
+++ b/src/encoding/encoding-buffer.hpp
@@ -13,17 +13,14 @@
  * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
  */
 
-#ifndef NDN_ENCODING_BUFFER_HPP
-#define NDN_ENCODING_BUFFER_HPP
+#ifndef NDN_ENCODING_ENCODING_BUFFER_HPP
+#define NDN_ENCODING_ENCODING_BUFFER_HPP
 
 #include "../common.hpp"
 
 #include "buffer.hpp"
-#include "tlv.hpp"
 #include "block.hpp"
 
-#include <boost/lexical_cast.hpp>
-
 namespace ndn {
 
 namespace encoding {
@@ -566,4 +563,4 @@
 
 } // ndn
 
-#endif // NDN_ENCODING_BUFFER_HPP
+#endif // NDN_ENCODING_ENCODING_BUFFER_HPP
diff --git a/src/encoding/endian.hpp b/src/encoding/endian.hpp
index 5329112..8b330b9 100644
--- a/src/encoding/endian.hpp
+++ b/src/encoding/endian.hpp
@@ -12,17 +12,20 @@
  * @author Junxiao Shi <http://www.cs.arizona.edu/people/shijunxiao/>
  */
 
+#ifndef NDN_ENCODING_ENDIAN_HPP
+#define NDN_ENCODING_ENDIAN_HPP
+
 #ifdef __linux__
 
 #include <endian.h>
 
-#endif
+#endif // __linux__
 
 #ifdef __FreeBSD__
 
 #include <sys/endian.h>
 
-#endif
+#endif // __FreeBSD__
 
 #ifdef __APPLE__
 
@@ -40,4 +43,6 @@
 #define be64toh(x) OSSwapBigToHostInt64(x)
 #define le64toh(x) OSSwapLittleToHostInt64(x)
 
-#endif
+#endif // __APPLE__
+
+#endif // NDN_ENCODING_ENDIAN_HPP
diff --git a/src/encoding/oid.cpp b/src/encoding/oid.cpp
index edbfa1a..f9085b2 100644
--- a/src/encoding/oid.cpp
+++ b/src/encoding/oid.cpp
@@ -17,6 +17,8 @@
 
 #include "../security/cryptopp.hpp"
 
+#include <sstream>
+
 using namespace std;
 using namespace CryptoPP;
 
diff --git a/src/encoding/oid.hpp b/src/encoding/oid.hpp
index b9b41e0..9dc846f 100644
--- a/src/encoding/oid.hpp
+++ b/src/encoding/oid.hpp
@@ -10,11 +10,13 @@
  * ndn-cxx library copyright, permissions, and redistribution restrictions.
  */
 
-#ifndef NDN_OID_HPP
-#define NDN_OID_HPP
+#ifndef NDN_ENCODING_OID_HPP
+#define NDN_ENCODING_OID_HPP
 
 #include "../common.hpp"
 
+#include <vector>
+
 namespace CryptoPP {
 class BufferedTransformation;
 }
@@ -81,4 +83,4 @@
 
 }
 
-#endif
+#endif // NDN_ENCODING_OID_HPP
diff --git a/src/encoding/tlv-ndnd.hpp b/src/encoding/tlv-ndnd.hpp
deleted file mode 100644
index ddb3421..0000000
--- a/src/encoding/tlv-ndnd.hpp
+++ /dev/null
@@ -1,62 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (c) 2013-2014,  Regents of the University of California.
- * All rights reserved.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * This file licensed under New BSD License.  See COPYING for detailed information about
- * ndn-cxx library copyright, permissions, and redistribution restrictions.
- */
-
-#ifndef NDN_TLV_NDND_HPP
-#define NDN_TLV_NDND_HPP
-
-#include "tlv.hpp"
-
-namespace ndn {
-namespace tlv {
-namespace ndnd {
-
-enum {
-  FaceInstance       = 128,
-  ForwardingEntry    = 129,
-  StatusResponse     = 130,
-  Action             = 131,
-  FaceID             = 132,
-  IPProto            = 133,
-  Host               = 134,
-  Port               = 135,
-  MulticastInterface = 136,
-  MulticastTTL       = 137,
-  ForwardingFlags    = 138,
-  StatusCode         = 139,
-  StatusText         = 140
-};
-
-enum {
-  FORW_ACTIVE         = 1,
-  FORW_CHILD_INHERIT  = 2,
-  FORW_ADVERTISE      = 4,
-  FORW_LAST           = 8,
-  FORW_CAPTURE       = 16,
-  FORW_LOCAL         = 32,
-  FORW_TAP           = 64,
-  FORW_CAPTURE_OK   = 128
-};
-
-} // namespace ndnd
-} // namespace tlv
-
-
-// temporary, until all the dependent code is updated
-namespace Tlv {
-namespace FaceManagement {
-using namespace ::ndn::tlv::ndnd;
-} // namespace FaceManagement
-} // namespace Tlv
-
-} // namespace ndn
-
-#endif // NDN_TLV_NDND_HPP
diff --git a/src/encoding/tlv-nfd.hpp b/src/encoding/tlv-nfd.hpp
index 490b6da..ad86636 100644
--- a/src/encoding/tlv-nfd.hpp
+++ b/src/encoding/tlv-nfd.hpp
@@ -10,8 +10,8 @@
  * ndn-cxx library copyright, permissions, and redistribution restrictions.
  */
 
-#ifndef NDN_TLV_NFD_HPP
-#define NDN_TLV_NFD_HPP
+#ifndef NDN_ENCODING_TLV_NFD_HPP
+#define NDN_ENCODING_TLV_NFD_HPP
 
 #include "../common.hpp"
 
@@ -81,4 +81,4 @@
 
 } // namespace ndn
 
-#endif // NDN_TLV_NFD_HPP
+#endif // NDN_ENCODING_TLV_NFD_HPP
diff --git a/src/encoding/tlv-nrd.hpp b/src/encoding/tlv-nrd.hpp
deleted file mode 100644
index 3a3076f..0000000
--- a/src/encoding/tlv-nrd.hpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
-/**
- * Copyright (c) 2013-2014,  Regents of the University of California.
- * All rights reserved.
- *
- * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
- * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
- *
- * This file licensed under New BSD License.  See COPYING for detailed information about
- * ndn-cxx library copyright, permissions, and redistribution restrictions.
- */
-
-#ifndef NDN_TLV_NRD_HPP
-#define NDN_TLV_NRD_HPP
-
-#include "tlv.hpp"
-
-namespace ndn {
-namespace tlv {
-namespace nrd {
-
-// \deprecated use NFD RIB Management
-enum {
-  PrefixRegOptions = 101,
-  FaceId           = 102,
-  Flags            = 103,
-  Cost             = 104,
-  ExpirationPeriod = 105,
-  StrategyName     = 106,
-  Protocol         = 107
-};
-
-enum {
-  NDN_FORW_CHILD_INHERIT = 1,
-  NDN_FORW_CAPTURE       = 2
-};
-
-} // namespace nrd
-} // namespace tlv
-} // namespace ndn
-
-#endif // NDN_TLV_NRD_HPP
diff --git a/src/encoding/tlv-security.hpp b/src/encoding/tlv-security.hpp
index 8e1f224..ab10201 100644
--- a/src/encoding/tlv-security.hpp
+++ b/src/encoding/tlv-security.hpp
@@ -10,8 +10,8 @@
  * ndn-cxx library copyright, permissions, and redistribution restrictions.
  */
 
-#ifndef NDN_TLV_SECURITY_HPP
-#define NDN_TLV_SECURITY_HPP
+#ifndef NDN_ENCODING_TLV_SECURITY_HPP
+#define NDN_ENCODING_TLV_SECURITY_HPP
 
 #include "tlv.hpp"
 
@@ -29,4 +29,4 @@
 } // namespace tlv
 } // namespace ndn
 
-#endif // NDN_TLV_SECURITY_HPP
+#endif // NDN_ENCODING_TLV_SECURITY_HPP
diff --git a/src/encoding/tlv.hpp b/src/encoding/tlv.hpp
index 594cdce..d071a2e 100644
--- a/src/encoding/tlv.hpp
+++ b/src/encoding/tlv.hpp
@@ -10,8 +10,8 @@
  * ndn-cxx library copyright, permissions, and redistribution restrictions.
  */
 
-#ifndef NDN_TLV_HPP
-#define NDN_TLV_HPP
+#ifndef NDN_ENCODING_TLV_HPP
+#define NDN_ENCODING_TLV_HPP
 
 #include <stdexcept>
 #include <iterator>
@@ -527,4 +527,4 @@
 
 } // namespace ndn
 
-#endif // NDN_TLV_HPP
+#endif // NDN_ENCODING_TLV_HPP