10 #ifndef NDN_BUFFER_HPP
11 #define NDN_BUFFER_HPP
13 #include "../common.hpp"
28 class Buffer :
public std::vector<uint8_t>
44 : std::vector<uint8_t>(size, 0)
54 : std::vector<uint8_t>(reinterpret_cast<const uint8_t*>(buf),
55 reinterpret_cast<const uint8_t*>(buf) + length)
67 template <
class InputIterator>
68 Buffer(InputIterator first, InputIterator last)
69 : std::vector<uint8_t>(first, last)
99 return reinterpret_cast<T*
>(&front());
128 return reinterpret_cast<const T*
>(&front());
136 class buffer_append_device
139 typedef char char_type;
140 typedef boost::iostreams::sink_tag category;
142 buffer_append_device(
Buffer& container)
143 : m_container(container)
148 write(
const char_type* s, std::streamsize n)
150 std::copy(s, s+n, std::back_inserter(m_container));
176 struct OBufferStream :
public boost::iostreams::stream<iostreams::buffer_append_device>
182 : m_buffer(ptr_lib::make_shared<
Buffer>())
183 , m_device(*m_buffer)
191 ptr_lib::shared_ptr<Buffer>
200 iostreams::buffer_append_device m_device;
206 #endif // NDN_BUFFER_HPP
Class implementing interface similar to ostringstream, but to construct ndn::Buffer.
Buffer()
Creates an empty buffer.
Buffer(const void *buf, size_t length)
Create a buffer by copying the supplied data from a const buffer.
ptr_lib::shared_ptr< Buffer > BufferPtr
ptr_lib::shared_ptr< const Buffer > ConstBufferPtr
const uint8_t * buf() const
Get pointer to the first byte of the buffer (alternative version)
uint8_t * buf()
Get pointer to the first byte of the buffer (alternative version)
ptr_lib::shared_ptr< Buffer > buf()
Flush written data to the stream and return shared pointer to the underlying buffer.
Buffer(InputIterator first, InputIterator last)
Create a buffer by copying the supplied data using iterator interface.
Buffer(size_t size)
Creates a buffer with pre-allocated size.
Class representing a general-use automatically managed/resized buffer.
OBufferStream()
Default constructor.