22 #ifndef NDN_CXX_ENCODING_ENCODER_HPP
23 #define NDN_CXX_ENCODING_ENCODER_HPP
56 template<
class Iterator>
63 template<
class Iterator>
155 return m_buffer->size();
228 return static_cast<size_t>(std::distance(m_begin, m_end));
239 block(
bool verifyLength =
true)
const;
242 shared_ptr<Buffer> m_buffer;
250 template<
class Iterator>
254 using ValueType =
typename std::iterator_traits<Iterator>::value_type;
255 static_assert(
sizeof(ValueType) == 1 && !std::is_same_v<ValueType, bool>);
257 size_t length = std::distance(first, last);
260 std::advance(m_begin, -length);
261 std::copy(first, last, m_begin);
265 template<
class Iterator>
269 using ValueType =
typename std::iterator_traits<Iterator>::value_type;
270 static_assert(
sizeof(ValueType) == 1 && !std::is_same_v<ValueType, bool>);
272 size_t length = std::distance(first, last);
275 std::copy(first, last, m_end);
276 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.
constexpr size_t MAX_NDN_PACKET_SIZE
Practical size limit of a network-layer packet.