NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
ndn::encoding::Encoder Class Reference

Helper class to perform TLV encoding. More...

#include <encoder.hpp>

Inheritance diagram for ndn::encoding::Encoder:
Collaboration diagram for ndn::encoding::Encoder:

Public Types

using value_type = Buffer::value_type
 
using iterator = Buffer::iterator
 
using const_iterator = Buffer::const_iterator
 

Public Member Functions

size_t prependBytes (span< const uint8_t > bytes)
 Prepend a sequence of bytes. More...
 
size_t appendBytes (span< const uint8_t > bytes)
 Append a sequence of bytes. More...
 
template<class Iterator >
size_t prependRange (Iterator first, Iterator last)
 Prepend range of bytes from the range [first, last) More...
 
template<class Iterator >
size_t appendRange (Iterator first, Iterator last)
 Append range of bytes from the range [first, last) More...
 
size_t prependVarNumber (uint64_t number)
 Prepend number encoded as a VAR-NUMBER in NDN-TLV format. More...
 
size_t appendVarNumber (uint64_t number)
 Append number encoded as a VAR-NUMBER in NDN-TLV format. More...
 
size_t prependNonNegativeInteger (uint64_t integer)
 Prepend integer encoded as a NonNegativeInteger in NDN-TLV format. More...
 
size_t appendNonNegativeInteger (uint64_t integer)
 Append integer encoded as a NonNegativeInteger in NDN-TLV format. More...
 
 Encoder (size_t totalReserve=MAX_NDN_PACKET_SIZE, size_t reserveFromBack=400)
 Create instance of the encoder with the specified reserved sizes. More...
 
 Encoder (const Block &block)
 Create EncodingBlock from existing block. More...
 
void reserve (size_t size, bool addInFront)
 Reserve size bytes for the underlying buffer. More...
 
void reserveBack (size_t size)
 Reserve at least size bytes at the back of the underlying buffer. More...
 
void reserveFront (size_t size)
 Reserve at least isze bytes at the beginning of the underlying buffer. More...
 
size_t capacity () const noexcept
 Get size of the underlying buffer. More...
 
shared_ptr< BuffergetBuffer () const noexcept
 Get underlying buffer. More...
 
iterator begin () noexcept
 Returns an iterator pointing to the first byte of the encoded buffer. More...
 
const_iterator begin () const noexcept
 Returns an iterator pointing to the first byte of the encoded buffer. More...
 
iterator end () noexcept
 Returns an iterator pointing to the past-the-end byte of the encoded buffer. More...
 
const_iterator end () const noexcept
 Returns an iterator pointing to the past-the-end byte of the encoded buffer. More...
 
uint8_t * data () noexcept
 Returns a pointer to the first byte of the encoded buffer. More...
 
const uint8_t * data () const noexcept
 Returns a pointer to the first byte of the encoded buffer. More...
 
size_t size () const noexcept
 Returns the size of the encoded buffer. More...
 
Block block (bool verifyLength=true) const
 Create Block from the underlying buffer. More...
 

Detailed Description

Helper class to perform TLV encoding.

The interface of this class (mostly) matches that of the Estimator class.

See also
Estimator

Definition at line 37 of file encoder.hpp.

Member Typedef Documentation

◆ value_type

using ndn::encoding::Encoder::value_type = Buffer::value_type

Definition at line 95 of file encoder.hpp.

◆ iterator

using ndn::encoding::Encoder::iterator = Buffer::iterator

Definition at line 96 of file encoder.hpp.

◆ const_iterator

using ndn::encoding::Encoder::const_iterator = Buffer::const_iterator

Definition at line 97 of file encoder.hpp.

Constructor & Destructor Documentation

◆ Encoder() [1/2]

ndn::encoding::Encoder::Encoder ( size_t  totalReserve = MAX_NDN_PACKET_SIZE,
size_t  reserveFromBack = 400 
)
explicit

Create instance of the encoder with the specified reserved sizes.

Parameters
totalReserveinitial buffer size to reserve
reserveFromBacknumber of bytes to reserve for append* operations

Definition at line 31 of file encoder.cpp.

◆ Encoder() [2/2]

ndn::encoding::Encoder::Encoder ( const Block block)
explicit

Create EncodingBlock from existing block.

This is a dangerous constructor and should be used with caution. It will modify contents of the buffer that is used by block and may impact data in other blocks.

The primary purpose for this method is to be used to extend Block after sign operation.

Definition at line 37 of file encoder.cpp.

Member Function Documentation

◆ prependBytes()

size_t ndn::encoding::Encoder::prependBytes ( span< const uint8_t >  bytes)

Prepend a sequence of bytes.

Definition at line 98 of file encoder.cpp.

References prependRange().

Referenced by prependNonNegativeInteger(), and prependVarNumber().

◆ appendBytes()

size_t ndn::encoding::Encoder::appendBytes ( span< const uint8_t >  bytes)

Append a sequence of bytes.

Definition at line 104 of file encoder.cpp.

References appendRange().

Referenced by appendNonNegativeInteger(), and appendVarNumber().

◆ prependRange()

template<class Iterator >
size_t ndn::encoding::Encoder::prependRange ( Iterator  first,
Iterator  last 
)

Prepend range of bytes from the range [first, last)

Definition at line 251 of file encoder.hpp.

References reserveFront().

Referenced by ndn::encoding::detail::BinaryBlockFast< Iterator >::makeBlock(), and prependBytes().

◆ appendRange()

template<class Iterator >
size_t ndn::encoding::Encoder::appendRange ( Iterator  first,
Iterator  last 
)

Append range of bytes from the range [first, last)

Definition at line 266 of file encoder.hpp.

References reserveBack().

Referenced by appendBytes(), and ndn::encoding::detail::BinaryBlockSlow< Iterator >::makeBlock().

◆ prependVarNumber()

size_t ndn::encoding::Encoder::prependVarNumber ( uint64_t  number)

◆ appendVarNumber()

size_t ndn::encoding::Encoder::appendVarNumber ( uint64_t  number)

Append number encoded as a VAR-NUMBER in NDN-TLV format.

See also
https://named-data.net/doc/NDN-packet-spec/current/tlv.html

Definition at line 137 of file encoder.cpp.

References appendBytes().

Referenced by ns3::ndn::Producer::OnInterest().

◆ prependNonNegativeInteger()

size_t ndn::encoding::Encoder::prependNonNegativeInteger ( uint64_t  integer)

Prepend integer encoded as a NonNegativeInteger in NDN-TLV format.

See also
https://named-data.net/doc/NDN-packet-spec/current/tlv.html

Definition at line 164 of file encoder.cpp.

References prependBytes().

◆ appendNonNegativeInteger()

size_t ndn::encoding::Encoder::appendNonNegativeInteger ( uint64_t  integer)

Append integer encoded as a NonNegativeInteger in NDN-TLV format.

See also
https://named-data.net/doc/NDN-packet-spec/current/tlv.html

Definition at line 184 of file encoder.cpp.

References appendBytes().

◆ reserve()

void ndn::encoding::Encoder::reserve ( size_t  size,
bool  addInFront 
)

Reserve size bytes for the underlying buffer.

Parameters
sizeamount of bytes to reserve in the underlying buffer
addInFrontif true, then size bytes will be available in front (i.e., subsequent call to prepend* will not need to allocate memory). If false, then reservation will be done at the end of the buffer (i.d., for subsequent append* calls)
Note
Reserve size is exact, unlike reserveFront and reserveBack methods
See also
reserveFront, reserveBack

Definition at line 65 of file encoder.cpp.

References size().

Referenced by reserveBack(), and reserveFront().

◆ reserveBack()

void ndn::encoding::Encoder::reserveBack ( size_t  size)

Reserve at least size bytes at the back of the underlying buffer.

Note
the actual reserve size can be (and in most cases is) larger than specified reservation length

Definition at line 45 of file encoder.cpp.

References reserve(), and size().

Referenced by appendRange().

◆ reserveFront()

void ndn::encoding::Encoder::reserveFront ( size_t  size)

Reserve at least isze bytes at the beginning of the underlying buffer.

Note
the actual reserve size can be (and in most cases is) larger than specified reservation length

Definition at line 52 of file encoder.cpp.

References reserve(), and size().

Referenced by prependRange().

◆ capacity()

size_t ndn::encoding::Encoder::capacity ( ) const
inlinenoexcept

Get size of the underlying buffer.

Definition at line 152 of file encoder.hpp.

◆ getBuffer()

shared_ptr<Buffer> ndn::encoding::Encoder::getBuffer ( ) const
inlinenoexcept

Get underlying buffer.

Definition at line 161 of file encoder.hpp.

◆ begin() [1/2]

iterator ndn::encoding::Encoder::begin ( )
inlinenoexcept

Returns an iterator pointing to the first byte of the encoded buffer.

Definition at line 171 of file encoder.hpp.

◆ begin() [2/2]

const_iterator ndn::encoding::Encoder::begin ( ) const
inlinenoexcept

Returns an iterator pointing to the first byte of the encoded buffer.

Definition at line 180 of file encoder.hpp.

◆ end() [1/2]

iterator ndn::encoding::Encoder::end ( )
inlinenoexcept

Returns an iterator pointing to the past-the-end byte of the encoded buffer.

Definition at line 189 of file encoder.hpp.

◆ end() [2/2]

const_iterator ndn::encoding::Encoder::end ( ) const
inlinenoexcept

Returns an iterator pointing to the past-the-end byte of the encoded buffer.

Definition at line 198 of file encoder.hpp.

◆ data() [1/2]

uint8_t* ndn::encoding::Encoder::data ( )
inlinenoexcept

Returns a pointer to the first byte of the encoded buffer.

Definition at line 207 of file encoder.hpp.

◆ data() [2/2]

const uint8_t* ndn::encoding::Encoder::data ( ) const
inlinenoexcept

Returns a pointer to the first byte of the encoded buffer.

Definition at line 216 of file encoder.hpp.

◆ size()

size_t ndn::encoding::Encoder::size ( ) const
inlinenoexcept

Returns the size of the encoded buffer.

Definition at line 225 of file encoder.hpp.

References block().

Referenced by reserve(), reserveBack(), and reserveFront().

◆ block()

Block ndn::encoding::Encoder::block ( bool  verifyLength = true) const

Create Block from the underlying buffer.

Parameters
verifyLengthIf this parameter set to true, Block's constructor will be requested to verify consistency of the encoded length in the Block, otherwise ignored

Definition at line 59 of file encoder.cpp.

Referenced by ndn::encoding::makeBinaryBlock(), ndn::encoding::detail::BinaryBlockFast< Iterator >::makeBlock(), ndn::encoding::detail::BinaryBlockSlow< Iterator >::makeBlock(), ndn::encoding::makeDoubleBlock(), ndn::encoding::makeEmptyBlock(), ndn::encoding::makeNestedBlock(), ndn::encoding::makeNonNegativeIntegerBlock(), and size().


The documentation for this class was generated from the following files: