1#ifndef NDNPH_TLV_DECODER_HPP
2#define NDNPH_TLV_DECODER_HPP
4#include "../core/operators.hpp"
16 explicit operator bool()
const {
29 return *
this && target.decodeFrom(*
this);
42 const uint8_t*
tlv =
nullptr;
55 const uint8_t* posL = input + sizeofT;
62 d.
value = posL + sizeofL;
64 d.
size = sizeofT + sizeofL + length;
65 return end - d.
value >=
static_cast<ssize_t
>(length);
87 return m_pos ==
nullptr;
121 return (lhs.m_end - lhs.m_pos) == (rhs.m_end - rhs.m_pos);
128 if (
readTlv(m_tlv, m_pos, m_end)) {
132 m_pos = m_end =
nullptr;
136 const uint8_t* m_pos =
nullptr;
137 const uint8_t* m_end =
nullptr;
141 explicit Decoder(
const uint8_t* input,
size_t count)
143 , m_end(input + count) {}
163 const uint8_t* m_begin;
164 const uint8_t* m_end;
Iterator over TLV elements.
Definition decoder.hpp:69
friend bool operator==(const Iterator &lhs, const Iterator &rhs)
Definition decoder.hpp:120
std::ptrdiff_t difference_type
Definition decoder.hpp:73
bool hasError() const
Whether a decoding error has occurred.
Definition decoder.hpp:86
pointer operator->()
Definition decoder.hpp:116
reference operator*()
Obtain Decoder::Tlv.
Definition decoder.hpp:112
Iterator operator++(int)
Definition decoder.hpp:101
Iterator & operator++()
Increment to next TLV element.
Definition decoder.hpp:95
Iterator(const uint8_t *pos, const uint8_t *end)
Definition decoder.hpp:79
std::forward_iterator_tag iterator_category
Definition decoder.hpp:71
Decoded TLV.
Definition decoder.hpp:13
const uint8_t * tlv
Definition decoder.hpp:42
Decoder vd() const
Create Decoder over TLV-VALUE.
Definition decoder.hpp:33
uint32_t type
Definition decoder.hpp:38
size_t length
Definition decoder.hpp:39
size_t size
Definition decoder.hpp:43
bool decode(T &target) const
Decode into target object.
Definition decoder.hpp:28
const uint8_t * value
Definition decoder.hpp:40
TLV decoder.
Definition decoder.hpp:10
Iterator begin() const
Definition decoder.hpp:145
Decoder(const uint8_t *input, size_t count)
Definition decoder.hpp:141
static bool readTlv(Tlv &d, const uint8_t *input, const uint8_t *end)
Definition decoder.hpp:46
bool decode(T &target) const
Decode first TLV into target object.
Definition decoder.hpp:158
Iterator end() const
Definition decoder.hpp:149
int readVarNum(const uint8_t *input, size_t size, uint32_t &n)
Read VAR-NUMBER.
Definition varnum.hpp:38
#define NDNPH_DECLARE_NE(T, specifier)
Declare operator!= in terms of operator==.
Definition operators.hpp:7