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