src: Code style corrections in Block and Buffer
Change-Id: Ic63ef97fa1e9f0d993ac2d9eb177628aa55c773a
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index 07ec2f0..a734c13 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -37,10 +37,10 @@
}
}
-Block::Block(const ConstBufferPtr &wire,
+Block::Block(const ConstBufferPtr& wire,
uint32_t type,
- const Buffer::const_iterator &begin, const Buffer::const_iterator &end,
- const Buffer::const_iterator &valueBegin, const Buffer::const_iterator &valueEnd)
+ const Buffer::const_iterator& begin, const Buffer::const_iterator& end,
+ const Buffer::const_iterator& valueBegin, const Buffer::const_iterator& valueEnd)
: m_buffer(wire)
, m_type(type)
, m_begin(begin)
@@ -51,7 +51,7 @@
{
}
-Block::Block(const ConstBufferPtr &buffer)
+Block::Block(const ConstBufferPtr& buffer)
: m_buffer(buffer)
, m_begin(m_buffer->begin())
, m_end(m_buffer->end())
@@ -69,8 +69,8 @@
}
}
-Block::Block(const ConstBufferPtr &buffer,
- const Buffer::const_iterator &begin, const Buffer::const_iterator &end,
+Block::Block(const ConstBufferPtr& buffer,
+ const Buffer::const_iterator& begin, const Buffer::const_iterator& end,
bool verifyLength/* = true*/)
: m_buffer(buffer)
, m_begin(begin)
@@ -99,7 +99,8 @@
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.
+ // 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);
@@ -109,7 +110,7 @@
buf[0] = *tmp_begin;
is.read(buf+1, length-1);
- if(length != static_cast<uint64_t>(is.gcount())+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");
@@ -129,10 +130,10 @@
}
-Block::Block(const uint8_t *buffer, size_t maxlength)
+Block::Block(const uint8_t* buffer, size_t maxlength)
{
- const uint8_t * tmp_begin = buffer;
- const uint8_t * tmp_end = buffer + maxlength;
+ 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);
@@ -142,7 +143,7 @@
throw Tlv::Error("Not enough data in the buffer to fully parse TLV");
}
- m_buffer = ptr_lib::make_shared<Buffer> (buffer, (tmp_begin - buffer) + length);
+ m_buffer = ptr_lib::make_shared<Buffer>(buffer, (tmp_begin - buffer) + length);
m_begin = m_buffer->begin();
m_end = m_buffer->end();
@@ -152,12 +153,12 @@
m_value_end = m_buffer->end();
}
-Block::Block(const void *bufferX, size_t maxlength)
+Block::Block(const void* bufferX, size_t maxlength)
{
- const uint8_t * buffer = reinterpret_cast<const uint8_t*>(bufferX);
+ const uint8_t* buffer = reinterpret_cast<const uint8_t*>(bufferX);
- const uint8_t * tmp_begin = buffer;
- const uint8_t * tmp_end = buffer + maxlength;
+ 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);
@@ -167,7 +168,7 @@
throw Tlv::Error("Not enough data in the buffer to fully parse TLV");
}
- m_buffer = ptr_lib::make_shared<Buffer> (buffer, (tmp_begin - buffer) + length);
+ m_buffer = ptr_lib::make_shared<Buffer>(buffer, (tmp_begin - buffer) + length);
m_begin = m_buffer->begin();
m_end = m_buffer->end();
@@ -182,7 +183,7 @@
{
}
-Block::Block(uint32_t type, const ConstBufferPtr &value)
+Block::Block(uint32_t type, const ConstBufferPtr& value)
: m_buffer(value)
, m_type(type)
, m_begin(m_buffer->end())
@@ -193,7 +194,7 @@
m_size = Tlv::sizeOfVarNumber(m_type) + Tlv::sizeOfVarNumber(value_size()) + value_size();
}
-Block::Block(uint32_t type, const Block &value)
+Block::Block(uint32_t type, const Block& value)
: m_buffer(value.m_buffer)
, m_type(type)
, m_begin(m_buffer->end())
@@ -210,13 +211,13 @@
Buffer::const_iterator tempBegin = wire->begin() + offset;
uint32_t type;
- bool ok = Tlv::readType(tempBegin, wire->end(), type);
- if (!ok)
+ bool isOk = Tlv::readType(tempBegin, wire->end(), type);
+ if (!isOk)
return false;
uint64_t length;
- ok = Tlv::readVarNumber(tempBegin, wire->end(), length);
- if (!ok)
+ isOk = Tlv::readVarNumber(tempBegin, wire->end(), length);
+ if (!isOk)
return false;
if (length > static_cast<uint64_t>(wire->end() - tempBegin))
@@ -238,13 +239,13 @@
const uint8_t* tempEnd = buffer + maxSize;
uint32_t type;
- bool ok = Tlv::readType(tempBegin, tempEnd, type);
- if (!ok)
+ bool isOk = Tlv::readType(tempBegin, tempEnd, type);
+ if (!isOk)
return false;
uint64_t length;
- ok = Tlv::readVarNumber(tempBegin, tempEnd, length);
- if (!ok)
+ isOk = Tlv::readVarNumber(tempBegin, tempEnd, length);
+ if (!isOk)
return false;
if (length > static_cast<uint64_t>(tempEnd - tempBegin))
@@ -263,11 +264,11 @@
void
Block::parse() const
{
- if (!m_subBlocks.empty() || value_size()==0)
+ if (!m_subBlocks.empty() || value_size() == 0)
return;
- Buffer::const_iterator begin = value_begin(),
- end = value_end();
+ Buffer::const_iterator begin = value_begin();
+ Buffer::const_iterator end = value_end();
while (begin != end)
{
@@ -350,7 +351,7 @@
Block
Block::blockFromValue() const
{
- if (value_size()==0)
+ if (value_size() == 0)
throw Error("Underlying value buffer is empty");
Buffer::const_iterator begin = value_begin(),
diff --git a/src/encoding/block.hpp b/src/encoding/block.hpp
index a2507b5..09bc93d 100644
--- a/src/encoding/block.hpp
+++ b/src/encoding/block.hpp
@@ -31,9 +31,14 @@
typedef element_container::const_iterator element_const_iterator;
/// @brief Error that can be thrown from the block
- struct Error : public std::runtime_error
+ class Error : public std::runtime_error
{
- Error(const std::string& what) : std::runtime_error(what) {}
+ public:
+ explicit
+ Error(const std::string& what)
+ : std::runtime_error(what)
+ {
+ }
};
/**
@@ -49,6 +54,8 @@
/**
* @brief A helper version of a constructor to create Block from the raw buffer (type and value-length parsing)
+ *
+ * This constructor provides ability of implicit conversion from ConstBufferPtr to Block
*/
Block(const ConstBufferPtr& buffer);
@@ -72,6 +79,7 @@
/*
* @brief A helper version of a constructor to create Block from the stream.
*/
+ explicit
Block(std::istream& is);
/**
@@ -132,31 +140,31 @@
/**
* @brief Check if the Block is empty
*/
- inline bool
+ bool
empty() const;
/**
* @brief Check if the Block has fully encoded wire
*/
- inline bool
+ bool
hasWire() const;
/**
* @brief Check if the Block has value block (no type and length are encoded)
*/
- inline bool
+ bool
hasValue() const;
/**
* @brief Reset wire buffer of the element
*/
- inline void
+ void
reset();
/**
* @brief Reset wire buffer but keep sub elements (if any)
*/
- inline void
+ void
resetWire();
/**
@@ -174,70 +182,67 @@
void
encode();
- inline uint32_t
+ uint32_t
type() const;
/**
* @brief Get the first subelement of the requested type
*/
- inline const Block&
+ const Block&
get(uint32_t type) const;
- inline element_const_iterator
+ element_const_iterator
find(uint32_t type) const;
- inline void
+ void
remove(uint32_t type);
- inline element_iterator
+ element_iterator
erase(element_iterator position);
- inline element_iterator
+ element_iterator
erase(element_iterator first, element_iterator last);
- inline void
+ void
push_back(const Block& element);
- inline Buffer::const_iterator
+ Buffer::const_iterator
begin() const;
- inline Buffer::const_iterator
+ Buffer::const_iterator
end() const;
- inline const uint8_t*
+ const uint8_t*
wire() const;
- inline size_t
+ size_t
size() const;
- // inline const uint8_t*
- // buf() const;
-
- inline Buffer::const_iterator
+ Buffer::const_iterator
value_begin() const;
- inline Buffer::const_iterator
+ Buffer::const_iterator
value_end() const;
- inline const uint8_t*
+ const uint8_t*
value() const;
- inline size_t
+ size_t
value_size() const;
/**
* @brief Get all subelements
*/
- inline const element_container&
- elements () const;
+ const element_container&
+ elements() const;
- inline element_const_iterator
+ element_const_iterator
elements_begin() const;
- inline element_const_iterator
+ element_const_iterator
elements_end() const;
- inline size_t
+ size_t
elements_size() const;
Block
@@ -289,7 +294,7 @@
m_subBlocks.clear(); // remove all parsed subelements
m_type = std::numeric_limits<uint32_t>::max();
- m_begin = m_end = m_value_begin = m_value_end = Buffer::const_iterator(); // not really necessary, but for safety
+ m_begin = m_end = m_value_begin = m_value_end = Buffer::const_iterator();
}
inline void
@@ -299,7 +304,7 @@
// keep subblocks
// keep type
- m_begin = m_end = m_value_begin = m_value_end = Buffer::const_iterator(); // not really necessary, but for safety
+ m_begin = m_end = m_value_begin = m_value_end = Buffer::const_iterator();
}
inline uint32_t
@@ -311,27 +316,28 @@
inline const Block&
Block::get(uint32_t type) const
{
- for (element_const_iterator i = m_subBlocks.begin ();
+ for (element_const_iterator i = m_subBlocks.begin();
i != m_subBlocks.end();
i++)
{
- if (i->type () == type)
+ if (i->type() == type)
{
return *i;
}
}
- throw Error("(Block::get) Requested a non-existed type [" + boost::lexical_cast<std::string>(type) + "] from Block");
+ 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
{
- for (element_const_iterator i = m_subBlocks.begin ();
+ for (element_const_iterator i = m_subBlocks.begin();
i != m_subBlocks.end();
i++)
{
- if (i->type () == type)
+ if (i->type() == type)
{
return i;
}
@@ -446,7 +452,7 @@
}
inline const Block::element_container&
-Block::elements () const
+Block::elements() const
{
return m_subBlocks;
}
diff --git a/src/encoding/buffer.hpp b/src/encoding/buffer.hpp
index 398817f..a97edc1 100644
--- a/src/encoding/buffer.hpp
+++ b/src/encoding/buffer.hpp
@@ -31,7 +31,7 @@
/**
* @brief Creates an empty buffer
*/
- Buffer ()
+ Buffer()
{
}
@@ -39,8 +39,9 @@
* @brief Creates a buffer with pre-allocated size
* @param size size of the buffer to be allocated
*/
- Buffer (size_t size)
- : std::vector<uint8_t> (size, 0)
+ explicit
+ Buffer(size_t size)
+ : std::vector<uint8_t>(size, 0)
{
}
@@ -49,8 +50,9 @@
* @param buf const pointer to buffer
* @param length length of the buffer to copy
*/
- Buffer (const void *buf, size_t length)
- : std::vector<uint8_t> (reinterpret_cast<const uint8_t*> (buf), reinterpret_cast<const uint8_t*> (buf) + length)
+ Buffer(const void *buf, size_t length)
+ : std::vector<uint8_t>(reinterpret_cast<const uint8_t*>(buf),
+ reinterpret_cast<const uint8_t*>(buf) + length)
{
}
@@ -63,27 +65,27 @@
* @param last iterator to an element immediately following the last element to copy
*/
template <class InputIterator>
- Buffer (InputIterator first, InputIterator last)
- : std::vector<uint8_t> (first, last)
+ Buffer(InputIterator first, InputIterator last)
+ : std::vector<uint8_t>(first, last)
{
}
/**
* @brief Get pointer to the first byte of the buffer
*/
- inline uint8_t*
- get ()
+ uint8_t*
+ get()
{
- return &front ();
+ return &front();
}
/**
* @brief Get pointer to the first byte of the buffer (alternative version)
*/
- inline uint8_t*
- buf ()
+ uint8_t*
+ buf()
{
- return &front ();
+ return &front();
}
/**
@@ -91,28 +93,28 @@
* it (reinterpret_cast) to the requested type T
*/
template<class T>
- inline T*
- get ()
+ T*
+ get()
{
- return reinterpret_cast<T *>(&front ());
+ return reinterpret_cast<T*>(&front());
}
/**
* @brief Get pointer to the first byte of the buffer (alternative version)
*/
- inline const uint8_t*
- buf () const
+ const uint8_t*
+ buf() const
{
- return &front ();
+ return &front();
}
/**
* @brief Get const pointer to the first byte of the buffer
*/
- inline const uint8_t*
- get () const
+ const uint8_t*
+ get() const
{
- return &front ();
+ return &front();
}
/**
@@ -120,10 +122,10 @@
* it (reinterpret_cast) to the requested type T
*/
template<class T>
- inline const T*
- get () const
+ const T*
+ get() const
{
- return reinterpret_cast<const T *>(&front ());
+ return reinterpret_cast<const T*>(&front());
}
};
@@ -131,20 +133,21 @@
namespace iostreams
{
-class buffer_append_device {
+class buffer_append_device
+{
public:
- typedef char char_type;
- typedef boost::iostreams::sink_tag category;
+ typedef char char_type;
+ typedef boost::iostreams::sink_tag category;
- buffer_append_device (Buffer& container)
- : m_container (container)
+ 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));
+ std::copy(s, s+n, std::back_inserter(m_container));
return n;
}
@@ -158,8 +161,9 @@
/**
* 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.
+ * 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
@@ -174,20 +178,20 @@
/**
* Default constructor
*/
- OBufferStream ()
- : m_buffer (ptr_lib::make_shared<Buffer> ())
- , m_device (*m_buffer)
+ OBufferStream()
+ : m_buffer(ptr_lib::make_shared<Buffer>())
+ , m_device(*m_buffer)
{
- open (m_device);
+ open(m_device);
}
/**
* Flush written data to the stream and return shared pointer to the underlying buffer
*/
ptr_lib::shared_ptr<Buffer>
- buf ()
+ buf()
{
- flush ();
+ flush();
return m_buffer;
}
diff --git a/src/encoding/tlv.hpp b/src/encoding/tlv.hpp
index 2ef008c..9cb1a0f 100644
--- a/src/encoding/tlv.hpp
+++ b/src/encoding/tlv.hpp
@@ -22,7 +22,15 @@
*/
namespace Tlv {
-struct Error : public std::runtime_error { Error(const std::string &what) : std::runtime_error(what) {} };
+class Error : public std::runtime_error
+{
+public:
+ explicit
+ Error(const std::string& what)
+ : std::runtime_error(what)
+ {
+ }
+};
enum {
Interest = 5,
@@ -31,7 +39,7 @@
NameComponent = 8,
Selectors = 9,
Nonce = 10,
- Scope = 11,
+ Scope = 11, // deprecated
InterestLifetime = 12,
MinSuffixComponents = 13,
MaxSuffixComponents = 14,
@@ -79,7 +87,7 @@
*/
template<class InputIterator>
inline bool
-readVarNumber(InputIterator &begin, const InputIterator &end, uint64_t& number);
+readVarNumber(InputIterator& begin, const InputIterator& end, uint64_t& number);
/**
* @brief Read TLV Type
@@ -95,7 +103,7 @@
*/
template<class InputIterator>
inline bool
-readType(InputIterator &begin, const InputIterator &end, uint32_t& type);
+readType(InputIterator& begin, const InputIterator& end, uint32_t& type);
/**
@@ -107,7 +115,7 @@
*/
template<class InputIterator>
inline uint64_t
-readVarNumber(InputIterator &begin, const InputIterator &end);
+readVarNumber(InputIterator& begin, const InputIterator& end);
/**
* @brief Read TLV Type
@@ -119,7 +127,7 @@
*/
template<class InputIterator>
inline uint32_t
-readType(InputIterator &begin, const InputIterator &end);
+readType(InputIterator& begin, const InputIterator& end);
/**
* @brief Get number of bytes necessary to hold value of VAR-NUMBER
@@ -131,7 +139,7 @@
* @brief Write VAR-NUMBER to the specified stream
*/
inline size_t
-writeVarNumber(std::ostream &os, uint64_t varNumber);
+writeVarNumber(std::ostream& os, uint64_t varNumber);
/**
* @brief Read nonNegativeInteger in NDN-TLV encoding
@@ -145,7 +153,7 @@
*/
template<class InputIterator>
inline uint64_t
-readNonNegativeInteger(size_t size, InputIterator &begin, const InputIterator &end);
+readNonNegativeInteger(size_t size, InputIterator& begin, const InputIterator& end);
/**
* @brief Get number of bytes necessary to hold value of nonNegativeInteger
@@ -157,7 +165,7 @@
* @brief Write nonNegativeInteger to the specified stream
*/
inline size_t
-writeNonNegativeInteger(std::ostream &os, uint64_t varNumber);
+writeNonNegativeInteger(std::ostream& os, uint64_t varNumber);
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
@@ -171,18 +179,18 @@
template<class InputIterator>
inline bool
-readVarNumber(InputIterator &begin, const InputIterator &end, uint64_t& number)
+readVarNumber(InputIterator& begin, const InputIterator& end, uint64_t& number)
{
if (begin == end)
return false;
- uint8_t value = *begin;
+ uint8_t firstOctet = *begin;
++begin;
- if (value < 253)
+ if (firstOctet < 253)
{
- number = value;
+ number = firstOctet;
}
- else if (value == 253)
+ else if (firstOctet == 253)
{
if (end - begin < 2)
return false;
@@ -191,7 +199,7 @@
begin += 2;
number = be16toh(value);
}
- else if (value == 254)
+ else if (firstOctet == 254)
{
if (end - begin < 4)
return false;
@@ -200,7 +208,7 @@
begin += 4;
number = be32toh(value);
}
- else // if (value == 255)
+ else // if (firstOctet == 255)
{
if (end - begin < 8)
return false;
@@ -216,7 +224,7 @@
template<class InputIterator>
inline bool
-readType(InputIterator &begin, const InputIterator &end, uint32_t& type)
+readType(InputIterator& begin, const InputIterator& end, uint32_t& type)
{
uint64_t number;
bool ok = readVarNumber(begin, end, number);
@@ -225,24 +233,24 @@
return false;
}
- type = static_cast<uint64_t> (number);
+ type = static_cast<uint64_t>(number);
return true;
}
template<class InputIterator>
inline uint64_t
-readVarNumber(InputIterator &begin, const InputIterator &end)
+readVarNumber(InputIterator& begin, const InputIterator& end)
{
if (begin == end)
throw Error("Empty buffer during TLV processing");
- uint8_t value = *begin;
+ uint8_t firstOctet = *begin;
++begin;
- if (value < 253)
+ if (firstOctet < 253)
{
- return value;
+ return firstOctet;
}
- else if (value == 253)
+ else if (firstOctet == 253)
{
if (end - begin < 2)
throw Error("Insufficient data during TLV processing");
@@ -251,7 +259,7 @@
begin += 2;
return be16toh(value);
}
- else if (value == 254)
+ else if (firstOctet == 254)
{
if (end - begin < 4)
throw Error("Insufficient data during TLV processing");
@@ -260,7 +268,7 @@
begin += 4;
return be32toh(value);
}
- else // if (value == 255)
+ else // if (firstOctet == 255)
{
if (end - begin < 8)
throw Error("Insufficient data during TLV processing");
@@ -274,19 +282,19 @@
template<>
inline uint64_t
-readVarNumber<std::istream_iterator<uint8_t> >(std::istream_iterator<uint8_t> &begin,
- const std::istream_iterator<uint8_t> &end)
+readVarNumber<std::istream_iterator<uint8_t> >(std::istream_iterator<uint8_t>& begin,
+ const std::istream_iterator<uint8_t>& end)
{
if (begin == end)
throw Error("Empty buffer during TLV processing");
- uint8_t value = *begin;
+ uint8_t firstOctet = *begin;
++begin;
- if (value < 253)
+ if (firstOctet < 253)
{
- return value;
+ return firstOctet;
}
- else if (value == 253)
+ else if (firstOctet == 253)
{
uint8_t buffer[2];
int count = 0;
@@ -303,7 +311,7 @@
uint16_t value = *reinterpret_cast<const uint16_t*>(buffer);
return be16toh(value);
}
- else if (value == 254)
+ else if (firstOctet == 254)
{
uint8_t buffer[4];
int count = 0;
@@ -320,7 +328,7 @@
uint32_t value = *reinterpret_cast<const uint32_t*>(buffer);
return be32toh(value);
}
- else // if (value == 255)
+ else // if (firstOctet == 255)
{
uint8_t buffer[8];
int count = 0;
@@ -341,15 +349,15 @@
template<class InputIterator>
inline uint32_t
-readType(InputIterator &begin, const InputIterator &end)
+readType(InputIterator& begin, const InputIterator& end)
{
- uint64_t type = readVarNumber(begin, end);
+ uint64_t type = readVarNumber(begin, end);
if (type > std::numeric_limits<uint32_t>::max())
{
throw Error("TLV type code exceeds allowed maximum");
}
- return static_cast<uint32_t> (type);
+ return static_cast<uint32_t>(type);
}
size_t
@@ -370,7 +378,7 @@
}
inline size_t
-writeVarNumber(std::ostream &os, uint64_t varNumber)
+writeVarNumber(std::ostream& os, uint64_t varNumber)
{
if (varNumber < 253) {
os.put(static_cast<uint8_t> (varNumber));
@@ -379,26 +387,26 @@
else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
os.put(253);
uint16_t value = htobe16(static_cast<uint16_t> (varNumber));
- os.write(reinterpret_cast<const char*> (&value), 2);
+ os.write(reinterpret_cast<const char*>(&value), 2);
return 3;
}
else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
os.put(254);
uint32_t value = htobe32(static_cast<uint32_t> (varNumber));
- os.write(reinterpret_cast<const char*> (&value), 4);
+ os.write(reinterpret_cast<const char*>(&value), 4);
return 5;
}
else {
os.put(255);
uint64_t value = htobe64(varNumber);
- os.write(reinterpret_cast<const char*> (&value), 8);
+ os.write(reinterpret_cast<const char*>(&value), 8);
return 9;
}
}
template<class InputIterator>
inline uint64_t
-readNonNegativeInteger(size_t size, InputIterator &begin, const InputIterator &end)
+readNonNegativeInteger(size_t size, InputIterator& begin, const InputIterator& end)
{
switch (size) {
case 1:
@@ -444,13 +452,13 @@
template<>
inline uint64_t
readNonNegativeInteger<std::istream_iterator<uint8_t> >(size_t size,
- std::istream_iterator<uint8_t> &begin,
- const std::istream_iterator<uint8_t> &end)
+ std::istream_iterator<uint8_t>& begin,
+ const std::istream_iterator<uint8_t>& end)
{
switch (size) {
case 1:
{
- if(begin == end)
+ if (begin == end)
throw Error("Insufficient data during TLV processing");
uint8_t value = *begin;
@@ -462,7 +470,7 @@
uint8_t buffer[2];
int count = 0;
- while(begin != end && count < 2){
+ while (begin != end && count < 2) {
buffer[count] = *begin;
begin++;
count++;
@@ -479,7 +487,7 @@
uint8_t buffer[4];
int count = 0;
- while(begin != end && count < 4){
+ while (begin != end && count < 4) {
buffer[count] = *begin;
begin++;
count++;
@@ -496,7 +504,7 @@
uint8_t buffer[8];
int count = 0;
- while(begin != end && count < 8){
+ while (begin != end && count < 8){
buffer[count] = *begin;
begin++;
count++;
@@ -531,7 +539,7 @@
inline size_t
-writeNonNegativeInteger(std::ostream &os, uint64_t varNumber)
+writeNonNegativeInteger(std::ostream& os, uint64_t varNumber)
{
if (varNumber < 253) {
os.put(static_cast<uint8_t> (varNumber));
@@ -539,23 +547,24 @@
}
else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
uint16_t value = htobe16(static_cast<uint16_t> (varNumber));
- os.write(reinterpret_cast<const char*> (&value), 2);
+ os.write(reinterpret_cast<const char*>(&value), 2);
return 2;
}
else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
uint32_t value = htobe32(static_cast<uint32_t> (varNumber));
- os.write(reinterpret_cast<const char*> (&value), 4);
+ os.write(reinterpret_cast<const char*>(&value), 4);
return 4;
}
else {
uint64_t value = htobe64(varNumber);
- os.write(reinterpret_cast<const char*> (&value), 8);
+ os.write(reinterpret_cast<const char*>(&value), 8);
return 8;
}
}
-} // namespace tlv
+} // namespace Tlv
+
} // namespace ndn
#endif // NDN_TLV_HPP