all: rename Tlv namespace to tlv for consistency
This commit renames the Tlv namespace defined in
tlv.hpp to tlv to be more consistent with tlv::security
and tlv::nfd. A Tlv namespace alias is provided for
backwards compatibility.
Change-Id: I21278d6a077afe7776802c3296997d4c1c44c6c6
diff --git a/src/encoding/block-helpers.hpp b/src/encoding/block-helpers.hpp
index 8163d0c..0a58aa0 100644
--- a/src/encoding/block-helpers.hpp
+++ b/src/encoding/block-helpers.hpp
@@ -45,7 +45,7 @@
readNonNegativeInteger(const Block& block)
{
Buffer::const_iterator begin = block.value_begin();
- return Tlv::readNonNegativeInteger(block.value_size(), begin, block.value_end());
+ return tlv::readNonNegativeInteger(block.value_size(), begin, block.value_end());
}
inline Block
@@ -87,8 +87,8 @@
// ++dataSize;
// OBufferStream os;
-// Tlv::writeVarNumber(os, type);
-// Tlv::writeVarNumber(os, dataSize);
+// tlv::writeVarNumber(os, type);
+// tlv::writeVarNumber(os, dataSize);
// std::copy(first, last, std::ostream_iterator<uint8_t>(os));
// return Block(os.buf());
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index eeb0c3f..9edebc2 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -51,11 +51,11 @@
m_value_begin = m_begin;
m_value_end = m_end;
- m_type = Tlv::readType(m_value_begin, m_value_end);
- uint64_t length = Tlv::readVarNumber(m_value_begin, m_value_end);
+ m_type = tlv::readType(m_value_begin, m_value_end);
+ uint64_t length = tlv::readVarNumber(m_value_begin, m_value_end);
if (length != static_cast<uint64_t>(m_value_end - m_value_begin))
{
- throw Tlv::Error("TLV length doesn't match buffer length");
+ throw tlv::Error("TLV length doesn't match buffer length");
}
}
@@ -82,12 +82,12 @@
m_value_begin = m_begin;
m_value_end = m_end;
- m_type = Tlv::readType(m_value_begin, m_value_end);
+ m_type = tlv::readType(m_value_begin, m_value_end);
- uint64_t length = Tlv::readVarNumber(m_value_begin, m_value_end);
+ uint64_t length = tlv::readVarNumber(m_value_begin, m_value_end);
if (length != static_cast<uint64_t>(m_value_end - m_value_begin))
{
- throw Tlv::Error("TLV length doesn't match buffer length");
+ throw tlv::Error("TLV length doesn't match buffer length");
}
}
@@ -102,13 +102,13 @@
m_value_begin = m_begin;
m_value_end = m_end;
- m_type = Tlv::readType(m_value_begin, m_value_end);
- uint64_t length = Tlv::readVarNumber(m_value_begin, m_value_end);
+ m_type = tlv::readType(m_value_begin, m_value_end);
+ uint64_t length = tlv::readVarNumber(m_value_begin, m_value_end);
if (verifyLength)
{
if (length != static_cast<uint64_t>(m_value_end - m_value_begin))
{
- throw Tlv::Error("TLV length doesn't match buffer length");
+ throw tlv::Error("TLV length doesn't match buffer length");
}
}
}
@@ -119,12 +119,12 @@
const uint8_t* tmp_begin = buffer;
const uint8_t* tmp_end = buffer + maxlength;
- m_type = Tlv::readType(tmp_begin, tmp_end);
- uint64_t length = Tlv::readVarNumber(tmp_begin, tmp_end);
+ m_type = tlv::readType(tmp_begin, tmp_end);
+ uint64_t length = tlv::readVarNumber(tmp_begin, tmp_end);
if (length > static_cast<uint64_t>(tmp_end - tmp_begin))
{
- throw Tlv::Error("Not enough data in the buffer to fully parse TLV");
+ throw tlv::Error("Not enough data in the buffer to fully parse TLV");
}
m_buffer = make_shared<Buffer>(buffer, (tmp_begin - buffer) + length);
@@ -144,12 +144,12 @@
const uint8_t* tmp_begin = buffer;
const uint8_t* tmp_end = buffer + maxlength;
- m_type = Tlv::readType(tmp_begin, tmp_end);
- uint64_t length = Tlv::readVarNumber(tmp_begin, tmp_end);
+ m_type = tlv::readType(tmp_begin, tmp_end);
+ uint64_t length = tlv::readVarNumber(tmp_begin, tmp_end);
if (length > static_cast<uint64_t>(tmp_end - tmp_begin))
{
- throw Tlv::Error("Not enough data in the buffer to fully parse TLV");
+ throw tlv::Error("Not enough data in the buffer to fully parse TLV");
}
m_buffer = make_shared<Buffer>(buffer, (tmp_begin - buffer) + length);
@@ -175,7 +175,7 @@
, m_value_begin(m_buffer->begin())
, m_value_end(m_buffer->end())
{
- m_size = Tlv::sizeOfVarNumber(m_type) + Tlv::sizeOfVarNumber(value_size()) + value_size();
+ m_size = tlv::sizeOfVarNumber(m_type) + tlv::sizeOfVarNumber(value_size()) + value_size();
}
Block::Block(uint32_t type, const Block& value)
@@ -186,7 +186,7 @@
, m_value_begin(value.begin())
, m_value_end(value.end())
{
- m_size = Tlv::sizeOfVarNumber(m_type) + Tlv::sizeOfVarNumber(value_size()) + value_size();
+ m_size = tlv::sizeOfVarNumber(m_type) + tlv::sizeOfVarNumber(value_size()) + value_size();
}
Block
@@ -195,11 +195,11 @@
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);
+ 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");
+ 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.
@@ -209,7 +209,7 @@
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");
+ throw tlv::Error("Not enough data in the buffer to fully parse TLV");
}
return dataBlock(type, buf, length);
@@ -221,12 +221,12 @@
Buffer::const_iterator tempBegin = wire->begin() + offset;
uint32_t type;
- bool isOk = Tlv::readType(tempBegin, wire->end(), type);
+ bool isOk = tlv::readType(tempBegin, wire->end(), type);
if (!isOk)
return false;
uint64_t length;
- isOk = Tlv::readVarNumber(tempBegin, wire->end(), length);
+ isOk = tlv::readVarNumber(tempBegin, wire->end(), length);
if (!isOk)
return false;
@@ -249,12 +249,12 @@
const uint8_t* tempEnd = buffer + maxSize;
uint32_t type = 0;
- bool isOk = Tlv::readType(tempBegin, tempEnd, type);
+ bool isOk = tlv::readType(tempBegin, tempEnd, type);
if (!isOk)
return false;
uint64_t length;
- isOk = Tlv::readVarNumber(tempBegin, tempEnd, length);
+ isOk = tlv::readVarNumber(tempBegin, tempEnd, length);
if (!isOk)
return false;
@@ -284,13 +284,13 @@
{
Buffer::const_iterator element_begin = begin;
- uint32_t type = Tlv::readType(begin, end);
- uint64_t length = Tlv::readVarNumber(begin, end);
+ uint32_t type = tlv::readType(begin, end);
+ uint64_t length = tlv::readVarNumber(begin, end);
if (length > static_cast<uint64_t>(end - begin))
{
m_subBlocks.clear();
- throw Tlv::Error("TLV length exceeds buffer length");
+ throw tlv::Error("TLV length exceeds buffer length");
}
Buffer::const_iterator element_end = begin + length;
@@ -311,16 +311,16 @@
return;
OBufferStream os;
- Tlv::writeVarNumber(os, type());
+ tlv::writeVarNumber(os, type());
if (hasValue())
{
- Tlv::writeVarNumber(os, value_size());
+ tlv::writeVarNumber(os, value_size());
os.write(reinterpret_cast<const char*>(value()), value_size());
}
else if (m_subBlocks.size() == 0)
{
- Tlv::writeVarNumber(os, 0);
+ tlv::writeVarNumber(os, 0);
}
else
{
@@ -329,14 +329,14 @@
valueSize += i->size();
}
- Tlv::writeVarNumber(os, valueSize);
+ tlv::writeVarNumber(os, valueSize);
for (element_const_iterator i = m_subBlocks.begin(); i != m_subBlocks.end(); ++i) {
if (i->hasWire())
os.write(reinterpret_cast<const char*>(i->wire()), i->size());
else if (i->hasValue()) {
- Tlv::writeVarNumber(os, i->type());
- Tlv::writeVarNumber(os, i->value_size());
+ tlv::writeVarNumber(os, i->type());
+ tlv::writeVarNumber(os, i->value_size());
os.write(reinterpret_cast<const char*>(i->value()), i->value_size());
}
else
@@ -354,8 +354,8 @@
m_value_begin = m_buffer->begin();
m_value_end = m_buffer->end();
- Tlv::readType(m_value_begin, m_value_end);
- Tlv::readVarNumber(m_value_begin, m_value_end);
+ tlv::readType(m_value_begin, m_value_end);
+ tlv::readVarNumber(m_value_begin, m_value_end);
}
Block
@@ -369,11 +369,11 @@
Buffer::const_iterator element_begin = begin;
- uint32_t type = Tlv::readType(begin, end);
- uint64_t length = Tlv::readVarNumber(begin, end);
+ uint32_t type = tlv::readType(begin, end);
+ uint64_t length = tlv::readVarNumber(begin, end);
if (length != static_cast<uint64_t>(end - begin))
- throw Tlv::Error("TLV length mismatches buffer length");
+ throw tlv::Error("TLV length mismatches buffer length");
return Block(m_buffer,
type,
diff --git a/src/encoding/block.hpp b/src/encoding/block.hpp
index 17192d8..9c2db13 100644
--- a/src/encoding/block.hpp
+++ b/src/encoding/block.hpp
@@ -51,12 +51,12 @@
typedef element_container::const_iterator element_const_iterator;
/// @brief Error that can be thrown from Block
- class Error : public Tlv::Error
+ class Error : public tlv::Error
{
public:
explicit
Error(const std::string& what)
- : Tlv::Error(what)
+ : tlv::Error(what)
{
}
};
diff --git a/src/encoding/tlv.hpp b/src/encoding/tlv.hpp
index 9d70ee6..87114eb 100644
--- a/src/encoding/tlv.hpp
+++ b/src/encoding/tlv.hpp
@@ -32,7 +32,7 @@
/**
* @brief Namespace defining NDN-TLV related constants and procedures
*/
-namespace Tlv {
+namespace tlv {
class Error : public std::runtime_error
{
@@ -125,7 +125,7 @@
/**
* @brief Read VAR-NUMBER in NDN-TLV encoding
*
- * @throws This call will throw ndn::Tlv::Error (aka std::runtime_error) if number cannot be read
+ * @throws This call will throw ndn::tlv::Error (aka std::runtime_error) if number cannot be read
*
* Note that after call finished, begin will point to the first byte after the read VAR-NUMBER
*/
@@ -136,7 +136,7 @@
/**
* @brief Read TLV Type
*
- * @throws This call will throw ndn::Tlv::Error (aka std::runtime_error) if number cannot be read
+ * @throws This call will throw ndn::tlv::Error (aka std::runtime_error) if number cannot be read
*
* This call is largely equivalent to tlv::readVarNumber, but exception will be thrown if type
* is larger than 2^32-1 (type in this library is implemented as uint32_t)
@@ -160,7 +160,7 @@
/**
* @brief Read nonNegativeInteger in NDN-TLV encoding
*
- * This call will throw ndn::Tlv::Error (aka std::runtime_error) if number cannot be read
+ * This call will throw ndn::tlv::Error (aka std::runtime_error) if number cannot be read
*
* Note that after call finished, begin will point to the first byte after the read VAR-NUMBER
*
@@ -536,7 +536,10 @@
}
-} // namespace Tlv
+} // namespace tlv
+
+/// @deprecated use namespace tlv instead
+namespace Tlv = tlv;
} // namespace ndn