22 #ifndef NDN_CXX_ENCODING_ENCODER_HPP
23 #define NDN_CXX_ENCODING_ENCODER_HPP
55 template<
class Iterator>
62 template<
class Iterator>
154 return m_buffer->size();
227 return static_cast<size_t>(std::distance(m_begin, m_end));
238 block(
bool verifyLength =
true)
const;
241 shared_ptr<Buffer> m_buffer;
249 template<
class Iterator>
253 using ValueType =
typename std::iterator_traits<Iterator>::value_type;
254 static_assert(
sizeof(ValueType) == 1 && !std::is_same<ValueType, bool>::value,
"");
256 size_t length = std::distance(first, last);
259 std::advance(m_begin, -length);
260 std::copy(first, last, m_begin);
264 template<
class Iterator>
268 using ValueType =
typename std::iterator_traits<Iterator>::value_type;
269 static_assert(
sizeof(ValueType) == 1 && !std::is_same<ValueType, bool>::value,
"");
271 size_t length = std::distance(first, last);
274 std::copy(first, last, m_end);
275 std::advance(m_end, length);
Represents a TLV element of the NDN packet format.
Helper class to perform TLV encoding.
void reserve(size_t size, bool addInFront)
Reserve size bytes for the underlying buffer.
size_t size() const noexcept
Returns the size of the encoded buffer.
Encoder(size_t totalReserve=MAX_NDN_PACKET_SIZE, size_t reserveFromBack=400)
Create instance of the encoder with the specified reserved sizes.
Buffer::value_type value_type
size_t appendBytes(span< const uint8_t > bytes)
Append a sequence of bytes.
const_iterator end() const noexcept
Returns an iterator pointing to the past-the-end byte of the encoded buffer.
void reserveFront(size_t size)
Reserve at least isze bytes at the beginning of the underlying buffer.
Buffer::const_iterator const_iterator
Block block(bool verifyLength=true) const
Create Block from the underlying buffer.
shared_ptr< Buffer > getBuffer() const noexcept
Get underlying buffer.
size_t prependBytes(span< const uint8_t > bytes)
Prepend a sequence of bytes.
size_t capacity() const noexcept
Get size of the underlying buffer.
size_t prependRange(Iterator first, Iterator last)
Prepend range of bytes from the range [first, last)
iterator begin() noexcept
Returns an iterator pointing to the first byte of the encoded buffer.
size_t prependVarNumber(uint64_t number)
Prepend number encoded as a VAR-NUMBER in NDN-TLV format.
size_t prependNonNegativeInteger(uint64_t integer)
Prepend integer encoded as a NonNegativeInteger in NDN-TLV format.
Buffer::iterator iterator
const_iterator begin() const noexcept
Returns an iterator pointing to the first byte of the encoded buffer.
const uint8_t * data() const noexcept
Returns a pointer to the first byte of the encoded buffer.
size_t appendNonNegativeInteger(uint64_t integer)
Append integer encoded as a NonNegativeInteger in NDN-TLV format.
size_t appendRange(Iterator first, Iterator last)
Append range of bytes from the range [first, last)
size_t appendVarNumber(uint64_t number)
Append number encoded as a VAR-NUMBER in NDN-TLV format.
void reserveBack(size_t size)
Reserve at least size bytes at the back of the underlying buffer.
uint8_t * data() noexcept
Returns a pointer to the first byte of the encoded buffer.
iterator end() noexcept
Returns an iterator pointing to the past-the-end byte of the encoded buffer.
const size_t MAX_NDN_PACKET_SIZE
Practical size limit of a network-layer packet.