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

TLV encoder. More...

#include <ndn/tlv.hpp>

Public Member Functions

 TlvEncoder (uint8_t *buf, size_t capacity)
 Constructor.
 
Error writeVarNumber (uint64_t value)
 Write a value in VAR-NUMBER format.
 
Error writeNonNegativeInteger (uint64_t value)
 Write a non-negative integer (big-endian, minimum bytes)
 
Error writeType (uint32_t type)
 Write a TLV Type.
 
Error writeLength (size_t length)
 Write a TLV Length.
 
Error writeBytes (const uint8_t *data, size_t len)
 Write a byte sequence.
 
Error writeTlv (uint32_t type, const uint8_t *value, size_t valueLen)
 Write a complete TLV structure.
 
Error writeTlvNonNegativeInteger (uint32_t type, uint64_t value)
 Write a non-negative integer as a TLV.
 
size_t size () const
 Current write position (= number of bytes written)
 
size_t remaining () const
 Remaining writable bytes.
 
uint8_tcurrent ()
 Pointer to current position.
 
size_t position () const
 Get current position.
 
void setPosition (size_t pos)
 Set current position.
 

Detailed Description

TLV encoder.

A class for writing data to a buffer in TLV format.

encoder.writeType(tlv::Name);
encoder.writeLength(5);
encoder.writeBytes(data, 5);
TLV encoder.
Definition tlv.hpp:116
constexpr uint32_t Name
Name.
Definition tlv.hpp:34
Result type template.
Definition common.hpp:147

Definition at line 116 of file tlv.hpp.

Constructor & Destructor Documentation

◆ TlvEncoder()

ndn::TlvEncoder::TlvEncoder ( uint8_t buf,
size_t  capacity 
)

Constructor.

Parameters
bufPointer to the output buffer
capacityBuffer capacity (bytes)

Definition at line 10 of file tlv.cpp.

Member Function Documentation

◆ current()

uint8_t * ndn::TlvEncoder::current ( )
inline

Pointer to current position.

Returns
Pointer to the current write position

Definition at line 201 of file tlv.hpp.

Referenced by ndn::Data::encode(), ndn::Interest::encode(), and ndn::Link::toData().

◆ position()

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

Get current position.

Returns
Current position offset

Definition at line 207 of file tlv.hpp.

Referenced by ndn::Data::encode(), ndn::Interest::encode(), and ndn::Link::toData().

◆ remaining()

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

Remaining writable bytes.

Returns
Number of remaining bytes

Definition at line 195 of file tlv.hpp.

Referenced by ndn::Data::encode(), ndn::Interest::encode(), ndn::Link::toData(), writeBytes(), writeNonNegativeInteger(), and writeVarNumber().

◆ setPosition()

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

Set current position.

Parameters
posNew position

Definition at line 213 of file tlv.hpp.

Referenced by ndn::Data::encode(), ndn::Interest::encode(), and ndn::Link::toData().

◆ size()

size_t ndn::TlvEncoder::size ( ) const
inline

Current write position (= number of bytes written)

Returns
Number of bytes written

Definition at line 189 of file tlv.hpp.

Referenced by ndn::ValidityPeriod::encode(), ndn::Certificate::encode(), ndn::Data::encode(), ndn::Interest::encode(), ndn::Name::encode(), and ndn::Link::toData().

◆ writeBytes()

Error ndn::TlvEncoder::writeBytes ( const uint8_t data,
size_t  len 
)

Write a byte sequence.

Parameters
dataPointer to data
lenData length
Returns
Error::Success on success

Definition at line 95 of file tlv.cpp.

References remaining().

Referenced by ndn::Certificate::encode(), ndn::Data::encode(), ndn::Interest::encode(), ndn::Name::encode(), and writeTlv().

◆ writeLength()

Error ndn::TlvEncoder::writeLength ( size_t  length)

Write a TLV Length.

Parameters
lengthLength value
Returns
Error::Success on success

Definition at line 91 of file tlv.cpp.

References writeVarNumber().

Referenced by ndn::Certificate::encode(), ndn::Data::encode(), ndn::Interest::encode(), ndn::Name::encode(), writeTlv(), and writeTlvNonNegativeInteger().

◆ writeNonNegativeInteger()

Error ndn::TlvEncoder::writeNonNegativeInteger ( uint64_t  value)

Write a non-negative integer (big-endian, minimum bytes)

Parameters
valueValue to write
Returns
Error::Success on success

Definition at line 51 of file tlv.cpp.

References remaining().

Referenced by writeTlvNonNegativeInteger().

◆ writeTlv()

Error ndn::TlvEncoder::writeTlv ( uint32_t  type,
const uint8_t value,
size_t  valueLen 
)

Write a complete TLV structure.

Parameters
typeType number
valuePointer to the Value data
valueLenLength of the Value
Returns
Error::Success on success

Definition at line 104 of file tlv.cpp.

References writeBytes(), writeLength(), and writeType().

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

◆ writeTlvNonNegativeInteger()

Error ndn::TlvEncoder::writeTlvNonNegativeInteger ( uint32_t  type,
uint64_t  value 
)

Write a non-negative integer as a TLV.

Parameters
typeType number
valueValue
Returns
Error::Success on success

Definition at line 125 of file tlv.cpp.

References ndn::nonNegativeIntegerSize(), writeLength(), writeNonNegativeInteger(), and writeType().

Referenced by ndn::Interest::encode().

◆ writeType()

Error ndn::TlvEncoder::writeType ( uint32_t  type)

Write a TLV Type.

Parameters
typeType number
Returns
Error::Success on success

Definition at line 87 of file tlv.cpp.

References writeVarNumber().

Referenced by ndn::Certificate::encode(), ndn::Data::encode(), ndn::Interest::encode(), ndn::Name::encode(), writeTlv(), and writeTlvNonNegativeInteger().

◆ writeVarNumber()

Error ndn::TlvEncoder::writeVarNumber ( uint64_t  value)

Write a value in VAR-NUMBER format.

Encodes in NDN specification VAR-NUMBER format:

  • 0-252: 1 byte
  • 253-65535: 0xFD + 2 bytes (big-endian)
  • 65536-4294967295: 0xFE + 4 bytes (big-endian)
  • Larger: 0xFF + 8 bytes (big-endian)
Parameters
valueValue to write
Returns
Error::Success on success, Error::BufferTooSmall if buffer is insufficient

Definition at line 12 of file tlv.cpp.

References remaining().

Referenced by writeLength(), and writeType().


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