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

Helper class to perform TLV encoding Interface of this class (mostly) matches interface of Estimator class. More...

#include <encoder.hpp>

Inheritance diagram for ndn::encoding::Encoder:

Public Types

typedef Buffer::value_type value_type
 
typedef Buffer::iterator iterator
 
typedef Buffer::const_iterator const_iterator
 

Public Member Functions

 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 Encoder &)=delete
 
Encoderoperator= (const Encoder &)=delete
 
size_t prependByte (uint8_t value)
 Prepend a byte. More...
 
size_t appendByte (uint8_t value)
 Append a byte. More...
 
size_t prependByteArray (const uint8_t *array, size_t length)
 Prepend a byte array array of length length. More...
 
size_t appendByteArray (const uint8_t *array, size_t length)
 Append a byte array array of length length. 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 varNumber)
 Prepend VarNumber varNumber of NDN TLV encoding. More...
 
size_t appendVarNumber (uint64_t varNumber)
 Prepend VarNumber varNumber of NDN TLV encoding. More...
 
size_t prependNonNegativeInteger (uint64_t integer)
 Prepend non-negative integer integer of NDN TLV encoding. More...
 
size_t appendNonNegativeInteger (uint64_t integer)
 Append non-negative integer integer of NDN TLV encoding. More...
 
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. More...
 
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. More...
 
size_t prependBlock (const Block &block)
 Prepend TLV block block. More...
 
size_t appendBlock (const Block &block)
 Append TLV block block. 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
 Get size of the underlying buffer. More...
 
shared_ptr< BuffergetBuffer ()
 Get underlying buffer. More...
 
iterator begin ()
 Get an iterator pointing to the first byte of the encoded buffer. More...
 
iterator end ()
 Get an iterator pointing to the past-the-end byte of the encoded buffer. More...
 
const_iterator begin () const
 Get an iterator pointing to the first byte of the encoded buffer. More...
 
const_iterator end () const
 
uint8_t * buf ()
 Get a pointer to the first byte of the encoded buffer. More...
 
const uint8_t * buf () const
 Get a pointer to the first byte of the encoded buffer. More...
 
size_t size () const
 Get 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 Interface of this class (mostly) matches interface of Estimator class.

See also
Estimator

Definition at line 36 of file encoder.hpp.

Member Typedef Documentation

§ value_type

typedef Buffer::value_type ndn::encoding::Encoder::value_type

Definition at line 143 of file encoder.hpp.

§ iterator

typedef Buffer::iterator ndn::encoding::Encoder::iterator

Definition at line 144 of file encoder.hpp.

§ const_iterator

typedef Buffer::const_iterator ndn::encoding::Encoder::const_iterator

Definition at line 145 of file encoder.hpp.

Constructor & Destructor Documentation

§ Encoder() [1/3]

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 27 of file encoder.cpp.

§ Encoder() [2/3]

ndn::encoding::Encoder::Encoder ( const Encoder )
delete

§ Encoder() [3/3]

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 34 of file encoder.cpp.

Member Function Documentation

§ operator=()

Encoder& ndn::encoding::Encoder::operator= ( const Encoder )
delete

§ prependByte()

size_t ndn::encoding::Encoder::prependByte ( uint8_t  value)

Prepend a byte.

Definition at line 104 of file encoder.cpp.

References reserveFront().

Referenced by prependNonNegativeInteger(), and prependVarNumber().

§ appendByte()

size_t ndn::encoding::Encoder::appendByte ( uint8_t  value)

Append a byte.

Definition at line 114 of file encoder.cpp.

References reserveBack().

Referenced by appendNonNegativeInteger(), and appendVarNumber().

§ prependByteArray()

size_t ndn::encoding::Encoder::prependByteArray ( const uint8_t *  array,
size_t  length 
)

Prepend a byte array array of length length.

Definition at line 125 of file encoder.cpp.

References reserveFront().

Referenced by prependBlock(), prependByteArrayBlock(), prependNonNegativeInteger(), and prependVarNumber().

§ appendByteArray()

size_t ndn::encoding::Encoder::appendByteArray ( const uint8_t *  array,
size_t  length 
)

§ prependRange()

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

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

Definition at line 317 of file encoder.hpp.

References reserveFront().

Referenced by ndn::encoding::DataBlockFast< Iterator >::makeBlock().

§ appendRange()

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

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

Definition at line 330 of file encoder.hpp.

References reserveBack().

Referenced by ndn::encoding::DataBlockSlow< Iterator >::makeBlock().

§ prependVarNumber()

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

§ appendVarNumber()

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

Prepend VarNumber varNumber of NDN TLV encoding.

See also
http://named-data.net/doc/ndn-tlv/

Definition at line 173 of file encoder.cpp.

References appendByte(), and appendByteArray().

Referenced by appendByteArrayBlock().

§ prependNonNegativeInteger()

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

Prepend non-negative integer integer of NDN TLV encoding.

See also
http://named-data.net/doc/ndn-tlv/

Definition at line 201 of file encoder.cpp.

References prependByte(), and prependByteArray().

§ appendNonNegativeInteger()

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

Append non-negative integer integer of NDN TLV encoding.

See also
http://named-data.net/doc/ndn-tlv/

Definition at line 221 of file encoder.cpp.

References appendByte(), and appendByteArray().

§ prependByteArrayBlock()

size_t ndn::encoding::Encoder::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.

Definition at line 241 of file encoder.cpp.

References prependByteArray(), and prependVarNumber().

Referenced by ndn::encoding::makeBinaryBlock(), and prependBlock().

§ appendByteArrayBlock()

size_t ndn::encoding::Encoder::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.

Definition at line 251 of file encoder.cpp.

References appendByteArray(), and appendVarNumber().

Referenced by appendBlock().

§ prependBlock()

size_t ndn::encoding::Encoder::prependBlock ( const Block block)

§ appendBlock()

size_t ndn::encoding::Encoder::appendBlock ( const Block block)

§ 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 68 of file encoder.cpp.

References buf(), and 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 appendByte(), appendByteArray(), and 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 prependByte(), prependByteArray(), and prependRange().

§ capacity()

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

Get size of the underlying buffer.

Definition at line 274 of file encoder.hpp.

§ getBuffer()

shared_ptr< Buffer > ndn::encoding::Encoder::getBuffer ( )
inline

Get underlying buffer.

Definition at line 268 of file encoder.hpp.

§ begin() [1/2]

Buffer::iterator ndn::encoding::Encoder::begin ( )
inline

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

Definition at line 280 of file encoder.hpp.

§ end() [1/2]

Buffer::iterator ndn::encoding::Encoder::end ( )
inline

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

Definition at line 286 of file encoder.hpp.

§ begin() [2/2]

Buffer::const_iterator ndn::encoding::Encoder::begin ( ) const
inline

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

Definition at line 292 of file encoder.hpp.

§ end() [2/2]

Buffer::const_iterator ndn::encoding::Encoder::end ( ) const
inline

Definition at line 298 of file encoder.hpp.

§ buf() [1/2]

uint8_t * ndn::encoding::Encoder::buf ( )
inline

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

Definition at line 304 of file encoder.hpp.

Referenced by reserve().

§ buf() [2/2]

const uint8_t * ndn::encoding::Encoder::buf ( ) const
inline

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

Definition at line 310 of file encoder.hpp.

§ size()

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

Get size of the encoded buffer.

Definition at line 262 of file encoder.hpp.

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 60 of file encoder.cpp.

Referenced by ndn::encoding::makeBinaryBlock(), ndn::encoding::DataBlockFast< Iterator >::makeBlock(), ndn::encoding::DataBlockSlow< Iterator >::makeBlock(), ndn::encoding::makeEmptyBlock(), ndn::encoding::makeNestedBlock(), ndn::encoding::makeNonNegativeIntegerBlock(), and ndn::encoding::makeStringBlock().


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