ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
Loading...
Searching...
No Matches
ndn::TlvDecoder Class Reference

TLV decoder. More...

#include <ndn/tlv.hpp>

Classes

struct  TlvHeader
 TLV header information. More...
 

Public Member Functions

 TlvDecoder (const uint8_t *buf, size_t len)
 Constructor.
 
Result< uint64_treadVarNumber ()
 Read a value in VAR-NUMBER format.
 
Result< uint64_treadNonNegativeInteger (size_t numBytes)
 Read a non-negative integer of specified byte count.
 
Result< uint32_treadType ()
 Read a TLV Type.
 
Result< size_treadLength ()
 Read a TLV Length.
 
Result< TlvHeaderreadTlvHeader ()
 Read a TLV header (Type and Length) at once.
 
Error readBytes (uint8_t *out, size_t len)
 Read a specified number of bytes.
 
Error skip (size_t len)
 Skip a specified number of bytes.
 
size_t remaining () const
 Remaining readable bytes.
 
const uint8_tcurrent () const
 Pointer to current position.
 
bool hasMore () const
 Check if there is more data.
 
size_t position () const
 Get current position.
 
void setPosition (size_t pos)
 Set current position.
 

Detailed Description

TLV decoder.

A class for reading TLV-formatted data from a buffer.

auto header = decoder.readTlvHeader();
if (header.ok()) {
printf("Type: %u, Length: %zu\n", header.value.type, header.value.length);
}
TLV decoder.
Definition tlv.hpp:235
Result type template.
Definition common.hpp:147
bool ok() const
Check if the operation succeeded.
Definition common.hpp:155
T value
Result value.
Definition common.hpp:148

Definition at line 235 of file tlv.hpp.

Constructor & Destructor Documentation

◆ TlvDecoder()

ndn::TlvDecoder::TlvDecoder ( const uint8_t buf,
size_t  len 
)

Constructor.

Parameters
bufPointer to the input buffer
lenBuffer length

Definition at line 145 of file tlv.cpp.

Member Function Documentation

◆ current()

const uint8_t * ndn::TlvDecoder::current ( ) const
inline

Pointer to current position.

Returns
Pointer to the current read position

Definition at line 308 of file tlv.hpp.

Referenced by ndn::Link::fromData(), ndn::Data::fromWire(), ndn::Interest::fromWire(), and ndn::Name::fromWire().

◆ hasMore()

bool ndn::TlvDecoder::hasMore ( ) const
inline

Check if there is more data.

Returns
true if data remains

Definition at line 314 of file tlv.hpp.

Referenced by ndn::Link::fromData().

◆ position()

size_t ndn::TlvDecoder::position ( ) const
inline

Get current position.

Returns
Current position offset

Definition at line 320 of file tlv.hpp.

Referenced by ndn::Data::fromWire(), ndn::Interest::fromWire(), ndn::ValidityPeriod::fromWire(), and ndn::Name::fromWire().

◆ readBytes()

Error ndn::TlvDecoder::readBytes ( uint8_t out,
size_t  len 
)

Read a specified number of bytes.

Parameters
outOutput buffer
lenNumber of bytes to read
Returns
Error::Success on success

Definition at line 239 of file tlv.cpp.

References remaining().

Referenced by ndn::Data::fromWire(), ndn::Interest::fromWire(), and ndn::ValidityPeriod::fromWire().

◆ readLength()

Result< size_t > ndn::TlvDecoder::readLength ( )

Read a TLV Length.

Returns
Length value and Error::Success on success

Definition at line 216 of file tlv.cpp.

References readVarNumber().

Referenced by readTlvHeader().

◆ readNonNegativeInteger()

Result< uint64_t > ndn::TlvDecoder::readNonNegativeInteger ( size_t  numBytes)

Read a non-negative integer of specified byte count.

Parameters
numBytesNumber of bytes to read (1, 2, 4, or 8)
Returns
Value and Error::Success on success

Definition at line 191 of file tlv.cpp.

References remaining(), and ndn::Result< T >::value.

Referenced by ndn::Data::fromWire(), and ndn::Interest::fromWire().

◆ readTlvHeader()

Result< TlvDecoder::TlvHeader > ndn::TlvDecoder::readTlvHeader ( )

Read a TLV header (Type and Length) at once.

Returns
TlvHeader and Error::Success on success

Definition at line 224 of file tlv.cpp.

References readLength(), and readType().

Referenced by ndn::Data::fromWire(), ndn::Interest::fromWire(), ndn::ValidityPeriod::fromWire(), and ndn::Name::fromWire().

◆ readType()

Result< uint32_t > ndn::TlvDecoder::readType ( )

Read a TLV Type.

Returns
Type number and Error::Success on success

Definition at line 204 of file tlv.cpp.

References readVarNumber().

Referenced by readTlvHeader().

◆ readVarNumber()

Result< uint64_t > ndn::TlvDecoder::readVarNumber ( )

Read a value in VAR-NUMBER format.

Returns
Value and Error::Success on success, Error::DecodeFailed on failure

Definition at line 147 of file tlv.cpp.

References remaining(), and ndn::Result< T >::value.

Referenced by readLength(), and readType().

◆ remaining()

size_t ndn::TlvDecoder::remaining ( ) const
inline

Remaining readable bytes.

Returns
Number of remaining bytes

Definition at line 302 of file tlv.hpp.

Referenced by ndn::Link::fromData(), ndn::Data::fromWire(), ndn::Interest::fromWire(), ndn::Name::fromWire(), readBytes(), readNonNegativeInteger(), readVarNumber(), and skip().

◆ setPosition()

void ndn::TlvDecoder::setPosition ( size_t  pos)
inline

Set current position.

Parameters
posNew position

Definition at line 326 of file tlv.hpp.

Referenced by ndn::Data::fromWire(), and ndn::Interest::fromWire().

◆ skip()

Error ndn::TlvDecoder::skip ( size_t  len)

Skip a specified number of bytes.

Parameters
lenNumber of bytes to skip
Returns
Error::Success on success

Definition at line 248 of file tlv.cpp.

References remaining().

Referenced by ndn::Link::fromData(), ndn::Data::fromWire(), ndn::Interest::fromWire(), and ndn::Name::fromWire().


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