src: Improving consistency and correcting code style
As of this commit, all data structures can be directly constructed from
wire format.
This commit excludes full correction of code style in security/ and
tools/ndnsec*, which will be part of a different commit.
Change-Id: I121ac1f81948bc7468990df52cdefeb2988d91a1
Refs: #1403
diff --git a/src/encoding/block-helpers.hpp b/src/encoding/block-helpers.hpp
index c3ae196..e29a20c 100644
--- a/src/encoding/block-helpers.hpp
+++ b/src/encoding/block-helpers.hpp
@@ -25,7 +25,7 @@
}
inline uint64_t
-readNonNegativeInteger(const Block &block)
+readNonNegativeInteger(const Block& block)
{
Buffer::const_iterator begin = block.value_begin();
return Tlv::readNonNegativeInteger(block.value_size(), begin, block.value_end());
@@ -41,7 +41,7 @@
}
inline Block
-dataBlock(uint32_t type, const char *data, size_t dataSize)
+dataBlock(uint32_t type, const char* data, size_t dataSize)
{
OBufferStream os;
Tlv::writeVarNumber(os, type);
@@ -52,7 +52,7 @@
}
inline Block
-dataBlock(uint32_t type, const unsigned char *data, size_t dataSize)
+dataBlock(uint32_t type, const unsigned char* data, size_t dataSize)
{
return dataBlock(type, reinterpret_cast<const char*>(data), dataSize);
}
diff --git a/src/encoding/block.cpp b/src/encoding/block.cpp
index a734c13..9c91aa8 100644
--- a/src/encoding/block.cpp
+++ b/src/encoding/block.cpp
@@ -110,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");
diff --git a/src/encoding/block.hpp b/src/encoding/block.hpp
index eef9b3d..388bac5 100644
--- a/src/encoding/block.hpp
+++ b/src/encoding/block.hpp
@@ -385,7 +385,7 @@
inline void
-Block::push_back(const Block &element)
+Block::push_back(const Block& element)
{
resetWire();
m_subBlocks.push_back(element);
diff --git a/src/encoding/buffer.hpp b/src/encoding/buffer.hpp
index a97edc1..0b9c327 100644
--- a/src/encoding/buffer.hpp
+++ b/src/encoding/buffer.hpp
@@ -50,7 +50,7 @@
* @param buf const pointer to buffer
* @param length length of the buffer to copy
*/
- Buffer(const void *buf, size_t 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)
{
@@ -69,7 +69,7 @@
: std::vector<uint8_t>(first, last)
{
}
-
+
/**
* @brief Get pointer to the first byte of the buffer
*/
@@ -126,7 +126,7 @@
get() const
{
return reinterpret_cast<const T*>(&front());
- }
+ }
};
/// @cond include_hidden
@@ -138,19 +138,19 @@
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;
};
diff --git a/src/encoding/cryptopp/asn_ext.cpp b/src/encoding/cryptopp/asn_ext.cpp
index 7741314..052226a 100644
--- a/src/encoding/cryptopp/asn_ext.cpp
+++ b/src/encoding/cryptopp/asn_ext.cpp
@@ -17,7 +17,8 @@
namespace ndn {
size_t
-DEREncodeGeneralTime(CryptoPP::BufferedTransformation &bt, const time::system_clock::TimePoint& time)
+DEREncodeGeneralTime(CryptoPP::BufferedTransformation& bt,
+ const time::system_clock::TimePoint& time)
{
std::string str = time::toIsoString(time);
// For example, 20131226T232254
@@ -32,7 +33,8 @@
}
void
-BERDecodeTime(CryptoPP::BufferedTransformation &bt, time::system_clock::TimePoint& time)
+BERDecodeTime(CryptoPP::BufferedTransformation& bt,
+ time::system_clock::TimePoint& time)
{
byte b;
if (!bt.Get(b) || (b != GENERALIZED_TIME && b != UTC_TIME))
@@ -48,14 +50,14 @@
std::string str;
str.assign (time_str.begin(), time_str.end());
-
+
if (b == UTC_TIME) {
if (boost::lexical_cast<int>(str.substr(0,2)) < 50)
str = "20" + str;
else
str = "19" + str;
}
-
+
time = time::fromIsoString(str.substr(0, 8) + "T" + str.substr(8, 6));
}
diff --git a/src/encoding/cryptopp/asn_ext.hpp b/src/encoding/cryptopp/asn_ext.hpp
index 9140ed9..5d726dc 100644
--- a/src/encoding/cryptopp/asn_ext.hpp
+++ b/src/encoding/cryptopp/asn_ext.hpp
@@ -15,17 +15,28 @@
namespace ndn {
-namespace Asn {
-struct Error : public std::runtime_error { Error(const std::string& what) : std::runtime_error(what) {} };
-}
+namespace asn {
+
+class Error : public std::runtime_error
+{
+public:
+ explicit
+ Error(const std::string& what)
+ : std::runtime_error(what)
+ {
+ }
+};
+
+} // namespace asn
size_t
-DEREncodeGeneralTime(CryptoPP::BufferedTransformation& bt, const time::system_clock::TimePoint& time);
+DEREncodeGeneralTime(CryptoPP::BufferedTransformation& bt,
+ const time::system_clock::TimePoint& time);
void
-BERDecodeTime(CryptoPP::BufferedTransformation& bt, time::system_clock::TimePoint& time);
+BERDecodeTime(CryptoPP::BufferedTransformation& bt,
+ time::system_clock::TimePoint& time);
} // namespace ndn
#endif // NDN_ASN_EXT_HPP
-
diff --git a/src/encoding/encoding-buffer.hpp b/src/encoding/encoding-buffer.hpp
index 4251fa9..78b1628 100644
--- a/src/encoding/encoding-buffer.hpp
+++ b/src/encoding/encoding-buffer.hpp
@@ -12,10 +12,6 @@
#include "../common.hpp"
-#include <list>
-#include <exception>
-#include <algorithm>
-
#include "buffer.hpp"
#include "tlv.hpp"
#include "block.hpp"
@@ -48,11 +44,11 @@
* The caller should make sure that that reserveFromBack does not exceed totalReserve,
* otherwise behavior is undefined.
*/
- EncodingImpl (size_t totalReserve = 8800,
- size_t reserveFromBack = 400)
- : m_buffer (new Buffer (totalReserve))
+ EncodingImpl(size_t totalReserve = 8800,
+ size_t reserveFromBack = 400)
+ : m_buffer(new Buffer(totalReserve))
{
- m_begin = m_end = m_buffer->end () - (reserveFromBack < totalReserve ? reserveFromBack : 0);
+ m_begin = m_end = m_buffer->end() - (reserveFromBack < totalReserve ? reserveFromBack : 0);
}
/**
@@ -66,24 +62,24 @@
* after sign operation.
*/
explicit
- EncodingImpl (const Block& block)
+ EncodingImpl(const Block& block)
: m_buffer(const_pointer_cast<Buffer>(block.m_buffer))
, m_begin(m_buffer->begin() + (block.begin() - m_buffer->begin()))
, m_end(m_buffer->begin() + (block.end() - m_buffer->begin()))
{
}
-
- inline size_t
- size () const;
inline size_t
- capacity () const;
+ size() const;
+
+ inline size_t
+ capacity() const;
inline uint8_t*
- buf ();
+ buf();
inline const uint8_t*
- buf () const;
+ buf() const;
/**
* @brief Create Block from the underlying EncodingBuffer
@@ -93,59 +89,59 @@
* length in the Block, otherwise ignored
*/
inline Block
- block (bool verifyLength = true) const;
+ block(bool verifyLength = true) const;
inline void
- resize (size_t sz, bool addInFront);
+ resize(size_t size, bool addInFront);
inline Buffer::iterator
- begin ();
+ begin();
inline Buffer::iterator
- end ();
+ end();
inline Buffer::const_iterator
- begin () const;
+ begin() const;
inline Buffer::const_iterator
- end () const;
+ end() const;
inline size_t
- prependByte (uint8_t val);
+ prependByte(uint8_t value);
inline size_t
- prependByteArray (const uint8_t *arr, size_t len);
+ prependByteArray(const uint8_t* array, size_t length);
inline size_t
- prependNonNegativeInteger (uint64_t varNumber);
+ prependNonNegativeInteger(uint64_t varNumber);
inline size_t
- prependVarNumber (uint64_t varNumber);
+ prependVarNumber(uint64_t varNumber);
inline size_t
- appendByte (uint8_t val);
+ appendByte(uint8_t value);
inline size_t
- appendByteArray (const uint8_t *arr, size_t len);
+ appendByteArray(const uint8_t* array, size_t length);
inline size_t
- appendNonNegativeInteger (uint64_t varNumber);
+ appendNonNegativeInteger(uint64_t varNumber);
inline size_t
- appendVarNumber (uint64_t varNumber);
+ appendVarNumber(uint64_t varNumber);
// inline void
- // removeByteFromFront ();
+ // removeByteFromFront();
// inline void
- // removeByteFromEnd ();
+ // removeByteFromEnd();
// inline void
- // removeVarNumberFromFront (uint64_t varNumber);
+ // removeVarNumberFromFront(uint64_t varNumber);
// inline void
- // removeVarNumberFromBack (uint64_t varNumber);
-
+ // removeVarNumberFromBack(uint64_t varNumber);
+
private:
BufferPtr m_buffer;
@@ -165,34 +161,34 @@
class EncodingImpl<encoding::Estimator>
{
public:
- EncodingImpl (size_t totalReserve = 8800,
- size_t reserveFromBack = 400)
+ EncodingImpl(size_t totalReserve = 8800,
+ size_t reserveFromBack = 400)
{
}
inline size_t
- prependByte (uint8_t val);
+ prependByte(uint8_t value);
inline size_t
- prependByteArray (const uint8_t *arr, size_t len);
+ prependByteArray(const uint8_t* array, size_t length);
inline size_t
- prependNonNegativeInteger (uint64_t varNumber);
+ prependNonNegativeInteger(uint64_t varNumber);
inline size_t
- prependVarNumber (uint64_t varNumber);
+ prependVarNumber(uint64_t varNumber);
inline size_t
- appendByte (uint8_t val);
+ appendByte(uint8_t value);
inline size_t
- appendByteArray (const uint8_t *arr, size_t len);
+ appendByteArray(const uint8_t* array, size_t length);
inline size_t
- appendNonNegativeInteger (uint64_t varNumber);
+ appendNonNegativeInteger(uint64_t varNumber);
inline size_t
- appendVarNumber (uint64_t varNumber);
+ appendVarNumber(uint64_t varNumber);
};
@@ -201,31 +197,31 @@
////////////////////////////////////////////////////////////////////////////////
inline size_t
-EncodingImpl<encoding::Buffer>::size () const
+EncodingImpl<encoding::Buffer>::size() const
{
return m_end - m_begin;
}
inline size_t
-EncodingImpl<encoding::Buffer>::capacity () const
+EncodingImpl<encoding::Buffer>::capacity() const
{
- return m_buffer->size ();
+ return m_buffer->size();
}
inline uint8_t*
-EncodingImpl<encoding::Buffer>::buf ()
+EncodingImpl<encoding::Buffer>::buf()
{
return &(*m_begin);
}
inline const uint8_t*
-EncodingImpl<encoding::Buffer>::buf () const
+EncodingImpl<encoding::Buffer>::buf() const
{
return &(*m_begin);
}
inline Block
-EncodingImpl<encoding::Buffer>::block (bool verifyLength/* = true*/) const
+EncodingImpl<encoding::Buffer>::block(bool verifyLength/* = true*/) const
{
return Block(m_buffer,
m_begin, m_end,
@@ -233,56 +229,56 @@
}
inline void
-EncodingImpl<encoding::Buffer>::resize (size_t sz, bool addInFront)
+EncodingImpl<encoding::Buffer>::resize(size_t size, bool addInFront)
{
if (addInFront)
{
- size_t diff_end = m_buffer->end () - m_end;
- size_t diff_begin = m_buffer->end () - m_begin;
+ size_t diff_end = m_buffer->end() - m_end;
+ size_t diff_begin = m_buffer->end() - m_begin;
- Buffer* buf = new Buffer (sz);
- std::copy_backward (m_buffer->begin (), m_buffer->end (), buf->end ());
+ Buffer* buf = new Buffer(size);
+ std::copy_backward(m_buffer->begin(), m_buffer->end(), buf->end());
- m_buffer.reset (buf);
+ m_buffer.reset(buf);
- m_end = m_buffer->end () - diff_end;
- m_begin = m_buffer->end () - diff_begin;
+ m_end = m_buffer->end() - diff_end;
+ m_begin = m_buffer->end() - diff_begin;
}
else
{
- size_t diff_end = m_end - m_buffer->begin ();
- size_t diff_begin = m_begin - m_buffer->begin ();
+ size_t diff_end = m_end - m_buffer->begin();
+ size_t diff_begin = m_begin - m_buffer->begin();
- Buffer* buf = new Buffer (sz);
- std::copy (m_buffer->begin (), m_buffer->end (), buf->begin ());
+ Buffer* buf = new Buffer(size);
+ std::copy(m_buffer->begin(), m_buffer->end(), buf->begin());
- m_buffer.reset (buf);
+ m_buffer.reset(buf);
- m_end = m_buffer->begin () + diff_end;
- m_begin = m_buffer->begin () + diff_begin;
+ m_end = m_buffer->begin() + diff_end;
+ m_begin = m_buffer->begin() + diff_begin;
}
}
inline Buffer::iterator
-EncodingImpl<encoding::Buffer>::begin ()
+EncodingImpl<encoding::Buffer>::begin()
{
return m_begin;
}
inline Buffer::iterator
-EncodingImpl<encoding::Buffer>::end ()
+EncodingImpl<encoding::Buffer>::end()
{
return m_end;
}
inline Buffer::const_iterator
-EncodingImpl<encoding::Buffer>::begin () const
+EncodingImpl<encoding::Buffer>::begin() const
{
return m_begin;
}
inline Buffer::const_iterator
-EncodingImpl<encoding::Buffer>::end () const
+EncodingImpl<encoding::Buffer>::end() const
{
return m_end;
}
@@ -293,69 +289,69 @@
//////////////////////////////////////////////////////////
inline size_t
-EncodingImpl<encoding::Buffer>::prependByte (uint8_t val)
+EncodingImpl<encoding::Buffer>::prependByte(uint8_t value)
{
- if (m_begin == m_buffer->begin ())
- resize (m_buffer->size () * 2, true);
+ if (m_begin == m_buffer->begin())
+ resize(m_buffer->size() * 2, true);
m_begin--;
- *m_begin = val;
+ *m_begin = value;
return 1;
}
inline size_t
-EncodingImpl<encoding::Estimator>::prependByte (uint8_t val)
+EncodingImpl<encoding::Estimator>::prependByte(uint8_t value)
{
return 1;
}
inline size_t
-EncodingImpl<encoding::Buffer>::prependByteArray (const uint8_t *arr, size_t len)
+EncodingImpl<encoding::Buffer>::prependByteArray(const uint8_t* array, size_t length)
{
- if ((m_buffer->begin () + len) > m_begin)
- resize (m_buffer->size () * 2 + len, true);
+ if ((m_buffer->begin() + length) > m_begin)
+ resize(m_buffer->size() * 2 + length, true);
- m_begin -= len;
- std::copy (arr, arr + len, m_begin);
- return len;
+ m_begin -= length;
+ std::copy(array, array + length, m_begin);
+ return length;
}
inline size_t
-EncodingImpl<encoding::Estimator>::prependByteArray (const uint8_t *arr, size_t len)
+EncodingImpl<encoding::Estimator>::prependByteArray(const uint8_t* array, size_t length)
{
- return len;
+ return length;
}
inline size_t
-EncodingImpl<encoding::Buffer>::prependNonNegativeInteger (uint64_t varNumber)
+EncodingImpl<encoding::Buffer>::prependNonNegativeInteger(uint64_t varNumber)
{
if (varNumber <= std::numeric_limits<uint8_t>::max()) {
- return prependByte (static_cast<uint8_t> (varNumber));
+ return prependByte(static_cast<uint8_t>(varNumber));
}
- else if (varNumber <= std::numeric_limits<uint16_t>::max ()) {
- uint16_t value = htobe16 (static_cast<uint16_t> (varNumber));
- return prependByteArray (reinterpret_cast<const uint8_t*> (&value), 2);
+ else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
+ uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
+ return prependByteArray(reinterpret_cast<const uint8_t*>(&value), 2);
}
- else if (varNumber <= std::numeric_limits<uint32_t>::max ()) {
- uint32_t value = htobe32 (static_cast<uint32_t> (varNumber));
- return prependByteArray (reinterpret_cast<const uint8_t*> (&value), 4);
+ else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
+ uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
+ return prependByteArray(reinterpret_cast<const uint8_t*>(&value), 4);
}
else {
- uint64_t value = htobe64 (varNumber);
- return prependByteArray (reinterpret_cast<const uint8_t*> (&value), 8);
+ uint64_t value = htobe64(varNumber);
+ return prependByteArray(reinterpret_cast<const uint8_t*>(&value), 8);
}
}
inline size_t
-EncodingImpl<encoding::Estimator>::prependNonNegativeInteger (uint64_t varNumber)
+EncodingImpl<encoding::Estimator>::prependNonNegativeInteger(uint64_t varNumber)
{
if (varNumber <= std::numeric_limits<uint8_t>::max()) {
return 1;
}
- else if (varNumber <= std::numeric_limits<uint16_t>::max ()) {
+ else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
return 2;
}
- else if (varNumber <= std::numeric_limits<uint32_t>::max ()) {
+ else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
return 4;
}
else {
@@ -364,42 +360,42 @@
}
inline size_t
-EncodingImpl<encoding::Buffer>::prependVarNumber (uint64_t varNumber)
+EncodingImpl<encoding::Buffer>::prependVarNumber(uint64_t varNumber)
{
if (varNumber < 253) {
- prependByte (static_cast<uint8_t> (varNumber));
+ prependByte(static_cast<uint8_t>(varNumber));
return 1;
}
- else if (varNumber <= std::numeric_limits<uint16_t>::max ()) {
- uint16_t value = htobe16 (static_cast<uint16_t> (varNumber));
- prependByteArray (reinterpret_cast<const uint8_t*> (&value), 2);
- prependByte (253);
+ else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
+ uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
+ prependByteArray(reinterpret_cast<const uint8_t*>(&value), 2);
+ prependByte(253);
return 3;
}
- else if (varNumber <= std::numeric_limits<uint32_t>::max ()) {
- uint32_t value = htobe32 (static_cast<uint32_t> (varNumber));
- prependByteArray (reinterpret_cast<const uint8_t*> (&value), 4);
- prependByte (254);
+ else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
+ uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
+ prependByteArray(reinterpret_cast<const uint8_t*>(&value), 4);
+ prependByte(254);
return 5;
}
else {
- uint64_t value = htobe64 (varNumber);
- prependByteArray (reinterpret_cast<const uint8_t*> (&value), 8);
- prependByte (255);
+ uint64_t value = htobe64(varNumber);
+ prependByteArray(reinterpret_cast<const uint8_t*>(&value), 8);
+ prependByte(255);
return 9;
}
}
inline size_t
-EncodingImpl<encoding::Estimator>::prependVarNumber (uint64_t varNumber)
+EncodingImpl<encoding::Estimator>::prependVarNumber(uint64_t varNumber)
{
if (varNumber < 253) {
return 1;
}
- else if (varNumber <= std::numeric_limits<uint16_t>::max ()) {
+ else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
return 3;
}
- else if (varNumber <= std::numeric_limits<uint32_t>::max ()) {
+ else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
return 5;
}
else {
@@ -412,94 +408,94 @@
/////////////////////////////////////////////////////////
inline size_t
-EncodingImpl<encoding::Buffer>::appendByte (uint8_t val)
+EncodingImpl<encoding::Buffer>::appendByte(uint8_t value)
{
- if (m_end == m_buffer->end ())
- resize (m_buffer->size () * 2, false);
+ if (m_end == m_buffer->end())
+ resize(m_buffer->size() * 2, false);
- *m_end = val;
+ *m_end = value;
m_end++;
return 1;
}
inline size_t
-EncodingImpl<encoding::Estimator>::appendByte (uint8_t val)
+EncodingImpl<encoding::Estimator>::appendByte(uint8_t value)
{
return 1;
}
inline size_t
-EncodingImpl<encoding::Buffer>::appendByteArray (const uint8_t *arr, size_t len)
+EncodingImpl<encoding::Buffer>::appendByteArray(const uint8_t* array, size_t length)
{
- if ((m_end + len) > m_buffer->end ())
- resize (m_buffer->size () * 2 + len, false);
+ if ((m_end + length) > m_buffer->end())
+ resize(m_buffer->size() * 2 + length, false);
- std::copy (arr, arr + len, m_end);
- m_end += len;
- return len;
+ std::copy(array, array + length, m_end);
+ m_end += length;
+ return length;
}
inline size_t
-EncodingImpl<encoding::Estimator>::appendByteArray (const uint8_t *arr, size_t len)
+EncodingImpl<encoding::Estimator>::appendByteArray(const uint8_t* array, size_t length)
{
- return prependByteArray(arr, len);
+ return prependByteArray(array, length);
}
inline size_t
-EncodingImpl<encoding::Buffer>::appendNonNegativeInteger (uint64_t varNumber)
+EncodingImpl<encoding::Buffer>::appendNonNegativeInteger(uint64_t varNumber)
{
- if (varNumber <= std::numeric_limits<uint8_t>::max ()) {
- return appendByte (static_cast<uint8_t> (varNumber));
+ if (varNumber <= std::numeric_limits<uint8_t>::max()) {
+ return appendByte(static_cast<uint8_t>(varNumber));
}
- else if (varNumber <= std::numeric_limits<uint16_t>::max ()) {
- uint16_t value = htobe16 (static_cast<uint16_t> (varNumber));
- return appendByteArray (reinterpret_cast<const uint8_t*> (&value), 2);
+ else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
+ uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
+ return appendByteArray(reinterpret_cast<const uint8_t*>(&value), 2);
}
- else if (varNumber <= std::numeric_limits<uint32_t>::max ()) {
- uint32_t value = htobe32 (static_cast<uint32_t> (varNumber));
- return appendByteArray (reinterpret_cast<const uint8_t*> (&value), 4);
+ else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
+ uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
+ return appendByteArray(reinterpret_cast<const uint8_t*>(&value), 4);
}
else {
- uint64_t value = htobe64 (varNumber);
- return appendByteArray (reinterpret_cast<const uint8_t*> (&value), 8);
+ uint64_t value = htobe64(varNumber);
+ return appendByteArray(reinterpret_cast<const uint8_t*>(&value), 8);
}
}
inline size_t
-EncodingImpl<encoding::Estimator>::appendNonNegativeInteger (uint64_t varNumber)
+EncodingImpl<encoding::Estimator>::appendNonNegativeInteger(uint64_t varNumber)
{
return prependNonNegativeInteger(varNumber);
}
inline size_t
-EncodingImpl<encoding::Buffer>::appendVarNumber (uint64_t varNumber)
+EncodingImpl<encoding::Buffer>::appendVarNumber(uint64_t varNumber)
{
if (varNumber < 253) {
- appendByte (static_cast<uint8_t> (varNumber));
+ appendByte(static_cast<uint8_t>(varNumber));
return 1;
}
- else if (varNumber <= std::numeric_limits<uint16_t>::max ()) {
- appendByte (253);
- uint16_t value = htobe16 (static_cast<uint16_t> (varNumber));
- appendByteArray (reinterpret_cast<const uint8_t*> (&value), 2);
+ else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
+ appendByte(253);
+ uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
+ appendByteArray(reinterpret_cast<const uint8_t*>(&value), 2);
return 3;
}
- else if (varNumber <= std::numeric_limits<uint32_t>::max ()) {
- appendByte (254);
- uint32_t value = htobe32 (static_cast<uint32_t> (varNumber));
- appendByteArray (reinterpret_cast<const uint8_t*> (&value), 4);
+ else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
+ appendByte(254);
+ uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
+ appendByteArray(reinterpret_cast<const uint8_t*>(&value), 4);
return 5;
}
else {
- appendByte (255);
- uint64_t value = htobe64 (varNumber);
- appendByteArray (reinterpret_cast<const uint8_t*> (&value), 8);
+ appendByte(255);
+ uint64_t value = htobe64(varNumber);
+ appendByteArray(reinterpret_cast<const uint8_t*>(&value), 8);
return 9;
}
}
inline size_t
-EncodingImpl<encoding::Estimator>::appendVarNumber (uint64_t varNumber)
+EncodingImpl<encoding::Estimator>::appendVarNumber(uint64_t varNumber)
{
return prependVarNumber(varNumber);
}
@@ -508,56 +504,57 @@
template<bool P>
inline size_t
-prependNonNegativeIntegerBlock(EncodingImpl<P>& blk, uint32_t type, uint64_t number)
+prependNonNegativeIntegerBlock(EncodingImpl<P>& encoder, uint32_t type, uint64_t number)
{
- size_t var_len = blk.prependNonNegativeInteger(number);
- size_t total_len = var_len;
- total_len += blk.prependVarNumber(var_len);
- total_len += blk.prependVarNumber(type);
+ size_t valueLength = encoder.prependNonNegativeInteger(number);
+ size_t totalLength = valueLength;
+ totalLength += encoder.prependVarNumber(valueLength);
+ totalLength += encoder.prependVarNumber(type);
- return total_len;
+ return totalLength;
}
template<bool P>
inline size_t
-prependByteArrayBlock(EncodingImpl<P>& blk, uint32_t type, const uint8_t* array, size_t arraySize)
+prependByteArrayBlock(EncodingImpl<P>& encoder, uint32_t type,
+ const uint8_t* array, size_t arraySize)
{
- size_t var_len = blk.prependByteArray(array, arraySize);
- size_t total_len = var_len;
- total_len += blk.prependVarNumber(var_len);
- total_len += blk.prependVarNumber(type);
+ size_t valueLength = encoder.prependByteArray(array, arraySize);
+ size_t totalLength = valueLength;
+ totalLength += encoder.prependVarNumber(valueLength);
+ totalLength += encoder.prependVarNumber(type);
- return total_len;
+ return totalLength;
}
template<bool P>
inline size_t
-prependBooleanBlock(EncodingImpl<P>& blk, uint32_t type)
+prependBooleanBlock(EncodingImpl<P>& encoder, uint32_t type)
{
- size_t total_len = blk.prependVarNumber(0);
- total_len += blk.prependVarNumber(type);
+ size_t totalLength = encoder.prependVarNumber(0);
+ totalLength += encoder.prependVarNumber(type);
- return total_len;
+ return totalLength;
}
template<bool P, class U>
inline size_t
-prependNestedBlock(EncodingImpl<P>& blk, uint32_t type, const U& nestedBlock)
+prependNestedBlock(EncodingImpl<P>& encoder, uint32_t type, const U& nestedBlock)
{
- size_t var_len = nestedBlock.wireEncode(blk);
- size_t total_len = var_len;
- total_len += blk.prependVarNumber(var_len);
- total_len += blk.prependVarNumber(type);
+ size_t valueLength = nestedBlock.wireEncode(encoder);
+ size_t totalLength = valueLength;
+ totalLength += encoder.prependVarNumber(valueLength);
+ totalLength += encoder.prependVarNumber(type);
- return total_len;
+ return totalLength;
}
template<bool P>
inline size_t
-prependBlock(EncodingImpl<P>& blk, const Block& block)
+prependBlock(EncodingImpl<P>& encoder, const Block& block)
{
- return blk.prependByteArray(block.wire(), block.size());
+ return encoder.prependByteArray(block.wire(), block.size());
}
diff --git a/src/encoding/oid.cpp b/src/encoding/oid.cpp
index 5f36473..cff98cd 100644
--- a/src/encoding/oid.cpp
+++ b/src/encoding/oid.cpp
@@ -16,7 +16,7 @@
namespace ndn {
-OID::OID(const char *oid)
+OID::OID(const char* oid)
{
construct(oid);
}
@@ -27,21 +27,21 @@
}
void
-OID::construct(const std::string &oid)
+OID::construct(const std::string& oid)
{
string str = oid + ".";
size_t pos = 0;
size_t ppos = 0;
- while(string::npos != pos){
+ while (string::npos != pos) {
ppos = pos;
pos = str.find_first_of('.', pos);
- if(pos == string::npos)
+ if (pos == string::npos)
break;
- oid_.push_back(atoi(str.substr(ppos, pos - ppos).c_str()));
+ m_oid.push_back(atoi(str.substr(ppos, pos - ppos).c_str()));
pos++;
}
@@ -50,54 +50,53 @@
string OID::toString() const
{
ostringstream convert;
-
- vector<int>::const_iterator it = oid_.begin();
- for(; it < oid_.end(); it++){
- if(it != oid_.begin())
+
+ for (vector<int>::const_iterator it = m_oid.begin(); it != m_oid.end(); ++it) {
+ if (it != m_oid.begin())
convert << ".";
convert << *it;
}
-
+
return convert.str();
}
bool
OID::equal(const OID& oid) const
{
- vector<int>::const_iterator i = oid_.begin();
- vector<int>::const_iterator j = oid.oid_.begin();
-
- for (; i != oid_.end () && j != oid.oid_.end (); i++, j++) {
- if(*i != *j)
+ vector<int>::const_iterator i = m_oid.begin();
+ vector<int>::const_iterator j = oid.m_oid.begin();
+
+ for (; i != m_oid.end () && j != oid.m_oid.end (); i++, j++) {
+ if (*i != *j)
return false;
}
- if (i == oid_.end () && j == oid.oid_.end ())
+ if (i == m_oid.end () && j == oid.m_oid.end ())
return true;
else
return false;
}
inline void
-EncodeValue(BufferedTransformation &bt, word32 v)
+EncodeValue(BufferedTransformation& bt, word32 v)
{
- for (unsigned int i=RoundUpToMultipleOf(STDMAX(7U,BitPrecision(v)), 7U)-7; i != 0; i-=7)
+ for (unsigned int i = RoundUpToMultipleOf(STDMAX(7U,BitPrecision(v)), 7U) - 7; i != 0; i -= 7)
bt.Put((byte)(0x80 | ((v >> i) & 0x7f)));
bt.Put((byte)(v & 0x7f));
}
inline size_t
-DecodeValue(BufferedTransformation &bt, word32 &v)
+DecodeValue(BufferedTransformation& bt, word32& v)
{
- byte b;
- size_t i=0;
v = 0;
+ size_t i = 0;
while (true)
{
+ byte b;
if (!bt.Get(b))
BERDecodeError();
i++;
- if (v >> (8*sizeof(v)-7)) // v about to overflow
+ if (v >> (8*sizeof(v) - 7)) // v about to overflow
BERDecodeError();
v <<= 7;
v += b & 0x7f;
@@ -107,20 +106,22 @@
}
void
-OID::encode(CryptoPP::BufferedTransformation &out) const
+OID::encode(CryptoPP::BufferedTransformation& out) const
{
- assert(oid_.size() >= 2);
+ BOOST_ASSERT(m_oid.size() >= 2);
+
ByteQueue temp;
- temp.Put(byte(oid_[0] * 40 + oid_[1]));
- for (size_t i=2; i<oid_.size(); i++)
- EncodeValue(temp, oid_[i]);
+ temp.Put(byte(m_oid[0] * 40 + m_oid[1]));
+ for (size_t i = 2; i < m_oid.size(); i++)
+ EncodeValue(temp, m_oid[i]);
+
out.Put(OBJECT_IDENTIFIER);
DERLengthEncode(out, temp.CurrentSize());
temp.TransferTo(out);
}
void
-OID::decode(CryptoPP::BufferedTransformation &in)
+OID::decode(CryptoPP::BufferedTransformation& in)
{
byte b;
if (!in.Get(b) || b != OBJECT_IDENTIFIER)
@@ -132,11 +133,11 @@
if (!in.Get(b))
BERDecodeError();
-
+
length--;
- oid_.resize(2);
- oid_[0] = b / 40;
- oid_[1] = b % 40;
+ m_oid.resize(2);
+ m_oid[0] = b / 40;
+ m_oid[1] = b % 40;
while (length > 0)
{
@@ -144,9 +145,9 @@
size_t valueLen = DecodeValue(in, v);
if (valueLen > length)
BERDecodeError();
- oid_.push_back(v);
+ m_oid.push_back(v);
length -= valueLen;
}
}
-}
+} // namespace ndn
diff --git a/src/encoding/oid.hpp b/src/encoding/oid.hpp
index 308da8e..e7b1beb 100644
--- a/src/encoding/oid.hpp
+++ b/src/encoding/oid.hpp
@@ -17,31 +17,31 @@
class OID {
public:
- OID ()
+ OID ()
{
}
-
- OID(const char *oid);
+
+ OID(const char* oid);
OID(const std::string& oid);
OID(const std::vector<int>& oid)
- : oid_(oid)
+ : m_oid(oid)
{
}
- const std::vector<int> &
+ const std::vector<int>&
getIntegerList() const
{
- return oid_;
+ return m_oid;
}
void
setIntegerList(const std::vector<int>& value){
- oid_ = value;
+ m_oid = value;
}
- std::string
+ std::string
toString() const;
bool operator == (const OID& oid) const
@@ -55,21 +55,21 @@
}
void
- encode(CryptoPP::BufferedTransformation &out) const;
+ encode(CryptoPP::BufferedTransformation& out) const;
void
- decode(CryptoPP::BufferedTransformation &in);
+ decode(CryptoPP::BufferedTransformation& in);
private:
void
- construct(const std::string &value);
-
+ construct(const std::string& value);
+
bool
equal(const OID& oid) const;
private:
- std::vector<int> oid_;
+ std::vector<int> m_oid;
};
}