28 : m_buffer(new
Buffer(totalReserve))
30 m_begin = m_end = m_buffer->end() - (reserveFromBack < totalReserve ? reserveFromBack : 0);
37 , m_end(m_buffer->
begin() + (block.
end() - m_buffer->
begin()))
47 if ((m_end + size) > m_buffer->end())
54 if ((m_buffer->begin() +
size) > m_begin)
62 return Block(m_buffer,
70 if (size < m_buffer->
size()) {
71 size = m_buffer->size();
75 size_t diffEnd = m_buffer->end() - m_end;
76 size_t diffBegin = m_buffer->end() - m_begin;
79 std::copy_backward(m_buffer->begin(), m_buffer->end(), buf->end());
83 m_end = m_buffer->end() - diffEnd;
84 m_begin = m_buffer->end() - diffBegin;
87 size_t diffEnd = m_end - m_buffer->begin();
88 size_t diffBegin = m_begin - m_buffer->begin();
91 std::copy(m_buffer->begin(), m_buffer->end(), buf->begin());
95 m_end = m_buffer->begin() + diffEnd;
96 m_begin = m_buffer->begin() + diffBegin;
130 std::copy(array, array + length, m_begin);
139 std::copy(array, array + length, m_end);
148 if (varNumber < 253) {
152 else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
153 uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
158 else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
159 uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
165 uint64_t value = htobe64(varNumber);
175 if (varNumber < 253) {
179 else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
181 uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
185 else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
187 uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
193 uint64_t value = htobe64(varNumber);
203 if (varNumber <= std::numeric_limits<uint8_t>::max()) {
204 return prependByte(static_cast<uint8_t>(varNumber));
206 else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
207 uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
210 else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
211 uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
215 uint64_t value = htobe64(varNumber);
223 if (varNumber <= std::numeric_limits<uint8_t>::max()) {
224 return appendByte(static_cast<uint8_t>(varNumber));
226 else if (varNumber <= std::numeric_limits<uint16_t>::max()) {
227 uint16_t value = htobe16(static_cast<uint16_t>(varNumber));
230 else if (varNumber <= std::numeric_limits<uint32_t>::max()) {
231 uint32_t value = htobe32(static_cast<uint32_t>(varNumber));
235 uint64_t value = htobe64(varNumber);
size_t prependByteArray(const uint8_t *array, size_t length)
Prepend a byte array array of length length.
void reserveFront(size_t size)
Reserve at least isze bytes at the beginning of the underlying buffer.
size_t appendVarNumber(uint64_t varNumber)
Prepend VarNumber varNumber of NDN TLV encoding.
bool hasWire() const
Check if the Block has fully encoded wire.
iterator begin()
Get an iterator pointing to the first byte of the encoded buffer.
Copyright (c) 2011-2015 Regents of the University of California.
size_t value_size() const
const uint8_t * wire() const
size_t prependByte(uint8_t value)
Prepend a byte.
iterator end()
Get an iterator pointing to the past-the-end byte of the encoded buffer.
Class representing a wire element of NDN-TLV packet format.
void reserve(size_t size, bool addInFront)
Reserve size bytes for the underlying buffer.
const uint8_t * value() const
void reserveBack(size_t size)
Reserve at least size bytes at the back of the underlying buffer.
size_t prependVarNumber(uint64_t varNumber)
Prepend VarNumber varNumber of NDN TLV encoding.
Block block(bool verifyLength=true) const
Create Block from the underlying buffer.
size_t prependBlock(const Block &block)
Prepend TLV block block.
size_t appendBlock(const Block &block)
Append TLV block block.
shared_ptr< Buffer > getBuffer()
Get underlying buffer.
size_t appendByte(uint8_t value)
Append a byte.
size_t prependByteArrayBlock(uint32_t type, const uint8_t *array, size_t arraySize)
Prepend TLV block of type type and value from buffer array of size arraySize.
size_t appendByteArray(const uint8_t *array, size_t length)
Append a byte array array of length length.
uint8_t * buf()
Get a pointer to the first byte of the encoded buffer.
size_t prependNonNegativeInteger(uint64_t integer)
Prepend non-negative integer integer of NDN TLV encoding.
size_t size() const
Get size of the encoded buffer.
size_t appendByteArrayBlock(uint32_t type, const uint8_t *array, size_t arraySize)
Append TLV block of type type and value from buffer array of size arraySize.
size_t appendNonNegativeInteger(uint64_t integer)
Append non-negative integer integer of NDN TLV encoding.
Class representing a general-use automatically managed/resized buffer.
Encoder(size_t totalReserve=MAX_NDN_PACKET_SIZE, size_t reserveFromBack=400)
Create instance of the encoder with the specified reserved sizes.