esp8266ndn
NDN Arduino library for ESP8266 and more
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | List of all members
ndnph::Encoder Class Reference

TLV encoder that accepts items in reverse order. More...

#include <encoder.hpp>

Inherited by ndnph::ScopedEncoder.

Public Types

enum  OmitEmptyTag { NoOmitEmpty = 0 , OmitEmpty = 1 }
 

Public Member Functions

 Encoder (uint8_t *buf, size_t capacity)
 Create over given buffer.
 
 Encoder (Region &region)
 Create over remaining space in a Region.
 
 operator bool () const
 Return true if no errors were encountered, such as running out of space.
 
const uint8_t * begin () const
 Get output begin.
 
const uint8_t * end () const
 Get output end.
 
size_t size () const
 Get output size.
 
size_t availableHeadroom () const
 Get available headroom.
 
void trim () const
 Release unused space to the Region.
 
void discard ()
 Release all space to the Region.
 
void resetFront (uint8_t *pos)
 Reset front to given position.
 
uint8_t * prependRoom (size_t size)
 Make room to prepend an object.
 
bool prependTypeLength (uint32_t type, size_t length)
 Prepend TLV-TYPE and TLV-LENGTH.
 
template<typename First , typename... Arg>
bool prepend (const First &first, const Arg &... arg)
 Prepend a sequence of values.
 
template<typename... Arg>
bool prependTlv (uint32_t type, OmitEmptyTag omitEmpty, const Arg &... arg)
 Prepend TLV, measuring TLV-LENGTH automatically.
 
template<typename First , typename... Arg>
std::enable_if<!std::is_same< First, OmitEmptyTag >::value, bool >::type prependTlv (uint32_t type, const First &first, const Arg &... arg)
 Prepend TLV, measuring TLV-LENGTH automatically.
 
bool prependTlv (uint32_t type)
 Prepend TLV with zero TLV-LENGTH.
 
void setError ()
 Indicate an error has occurred.
 

Detailed Description

TLV encoder that accepts items in reverse order.

Member Enumeration Documentation

◆ OmitEmptyTag

Enumerator
NoOmitEmpty 
OmitEmpty 

Constructor & Destructor Documentation

◆ Encoder() [1/2]

ndnph::Encoder::Encoder ( uint8_t *  buf,
size_t  capacity 
)
inlineexplicit

Create over given buffer.

◆ Encoder() [2/2]

ndnph::Encoder::Encoder ( Region region)
inlineexplicit

Create over remaining space in a Region.

After encoding, unused space can be released with trim().

Member Function Documentation

◆ availableHeadroom()

size_t ndnph::Encoder::availableHeadroom ( ) const
inline

Get available headroom.

◆ begin()

const uint8_t * ndnph::Encoder::begin ( ) const
inline

Get output begin.

◆ discard()

void ndnph::Encoder::discard ( )
inline

Release all space to the Region.

Postcondition
Output is empty.

This function has no effect if Encoder was not created from a Region.

◆ end()

const uint8_t * ndnph::Encoder::end ( ) const
inline

Get output end.

◆ operator bool()

ndnph::Encoder::operator bool ( ) const
inlineexplicit

Return true if no errors were encountered, such as running out of space.

◆ prepend()

template<typename First , typename... Arg>
bool ndnph::Encoder::prepend ( const First &  first,
const Arg &...  arg 
)
inline

Prepend a sequence of values.

Template Parameters
Firsteither `[] (Encoder&) -> void {}` or a class with `void encoderTo(Encoder&) const {}` method.
Argsame as First.
Returns
whether success.

◆ prependRoom()

uint8_t * ndnph::Encoder::prependRoom ( size_t  size)
inline

Make room to prepend an object.

Returns
room to write object.
Return values
nullptrno room available.

◆ prependTlv() [1/3]

bool ndnph::Encoder::prependTlv ( uint32_t  type)
inline

Prepend TLV with zero TLV-LENGTH.

◆ prependTlv() [2/3]

template<typename First , typename... Arg>
std::enable_if<!std::is_same< First, OmitEmptyTag >::value, bool >::type ndnph::Encoder::prependTlv ( uint32_t  type,
const First &  first,
const Arg &...  arg 
)
inline

Prepend TLV, measuring TLV-LENGTH automatically.

◆ prependTlv() [3/3]

template<typename... Arg>
bool ndnph::Encoder::prependTlv ( uint32_t  type,
OmitEmptyTag  omitEmpty,
const Arg &...  arg 
)
inline

Prepend TLV, measuring TLV-LENGTH automatically.

Template Parameters
Argsame as arguments of prepend().
Parameters
typeTLV-TYPE number.
omitEmptyif OmitEmpty, omit the TLV altogether if TLV-LENGTH is zero.
argzero or more items in TLV-VALUE.
Returns
whether success.

◆ prependTypeLength()

bool ndnph::Encoder::prependTypeLength ( uint32_t  type,
size_t  length 
)
inline

Prepend TLV-TYPE and TLV-LENGTH.

Returns
whether success.

◆ resetFront()

void ndnph::Encoder::resetFront ( uint8_t *  pos)
inline

Reset front to given position.

◆ setError()

void ndnph::Encoder::setError ( )
inline

Indicate an error has occurred.

◆ size()

size_t ndnph::Encoder::size ( ) const
inline

Get output size.

◆ trim()

void ndnph::Encoder::trim ( ) const
inline

Release unused space to the Region.

This function has no effect if Encoder was not created from a Region.


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