22#ifndef NDN_CXX_LP_FIELD_DECL_HPP
23#define NDN_CXX_LP_FIELD_DECL_HPP
29#include <boost/concept/requires.hpp>
30#include <boost/endian/conversion.hpp>
37struct NonNegativeIntegerTag;
39template<
typename TlvType,
typename T>
47 type.wireDecode(wire);
52template<
typename TlvType>
66template<
typename TlvType>
72 return readNonNegativeInteger(wire);
76template<
typename TlvType>
84 " must contain a 64-bit integer"));
87 std::memcpy(&n, wire.
value(),
sizeof(n));
88 return boost::endian::big_to_native(n);
92template<
typename TlvType>
93struct DecodeHelper<TlvType,
std::pair<Buffer::const_iterator, Buffer::const_iterator>>
95 static std::pair<Buffer::const_iterator, Buffer::const_iterator>
100 " cannot be empty"));
106template<
typename encoding::Tag TAG,
typename TlvType,
typename T>
113 return value.wireEncode(encoder);
117template<
typename encoding::Tag TAG,
typename TlvType>
123 return prependEmptyBlock(encoder, TlvType::value);
127template<
typename encoding::Tag TAG,
typename TlvType>
133 return prependNonNegativeIntegerBlock(encoder, TlvType::value, value);
137template<
typename encoding::Tag TAG,
typename TlvType>
143 boost::endian::native_to_big_inplace(value);
144 return prependBinaryBlock(encoder, TlvType::value,
145 {
reinterpret_cast<const uint8_t*
>(&value),
sizeof(value)});
149template<
typename encoding::Tag TAG,
typename TlvType>
150struct EncodeHelper<TAG, TlvType,
std::pair<Buffer::const_iterator, Buffer::const_iterator>>
156 length += encoder.prependRange(value.first, value.second);
157 length += encoder.prependVarNumber(length);
158 length += encoder.prependVarNumber(TlvType::value);
171template<
typename LOCATION,
typename VALUE, uint32_t TYPE,
bool REPEATABLE =
false,
172 typename DECODER_TAG = VALUE,
typename ENCODER_TAG = VALUE>
178 using TlvType = std::integral_constant<uint32_t, TYPE>;
189 if (wire.
type() != TlvType::value) {
200 template<
typename encoding::Tag TAG>
Represents a TLV element of the NDN packet format.
const_iterator value_end() const noexcept
Get end iterator of TLV-VALUE.
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
const_iterator value_begin() const noexcept
Get begin iterator of TLV-VALUE.
size_t value_size() const noexcept
Return the size of TLV-VALUE, i.e., the TLV-LENGTH.
const uint8_t * value() const noexcept
Return a raw pointer to the beginning of TLV-VALUE.
A concept check for TLV abstraction with a wireDecode(Block) method and constructible from Block.
A concept check for TLV abstraction with a wireEncode(EncodingBuffer) method.
std::integral_constant< uint32_t, TYPE > TlvType
std::bool_constant< REPEATABLE > IsRepeatable
static size_t encode(EncodingImpl< TAG > &encoder, const ValueType &value)
Encode a field and prepend to encoder.
static ValueType decode(const Block &wire)
Decode a field.
Represents an error in TLV encoding or decoding.
Contains classes and functions related to NDNLPv2.
static EmptyValue decode(const Block &wire)
static uint64_t decode(const Block &wire)
static std::pair< Buffer::const_iterator, Buffer::const_iterator > decode(const Block &wire)
static uint64_t decode(const Block &wire)
static T decode(const Block &wire)
Represents a zero-length TLV-VALUE.
static size_t encode(EncodingImpl< TAG > &encoder, EmptyValue)
static size_t encode(EncodingImpl< TAG > &encoder, uint64_t value)
static size_t encode(EncodingImpl< TAG > &encoder, const std::pair< Buffer::const_iterator, Buffer::const_iterator > &value)
static size_t encode(EncodingImpl< TAG > &encoder, uint64_t value)
static size_t encode(EncodingImpl< TAG > &encoder, const T &value)