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>
37 struct NonNegativeIntegerTag;
39 template<
typename TlvType,
typename T>
47 type.wireDecode(wire);
52 template<
typename TlvType>
66 template<
typename TlvType>
76 template<
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);
92 template<
typename TlvType>
93 struct DecodeHelper<TlvType, std::pair<Buffer::const_iterator, Buffer::const_iterator>>
95 static std::pair<Buffer::const_iterator, Buffer::const_iterator>
100 " cannot be empty"));
106 template<
typename encoding::Tag TAG,
typename TlvType,
typename T>
113 return value.wireEncode(encoder);
117 template<
typename encoding::Tag TAG,
typename TlvType>
127 template<
typename encoding::Tag TAG,
typename TlvType>
137 template<
typename encoding::Tag TAG,
typename TlvType>
143 boost::endian::native_to_big_inplace(value);
145 {
reinterpret_cast<const uint8_t*
>(&value),
sizeof(value)});
149 template<
typename encoding::Tag TAG,
typename TlvType>
150 struct 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);
171 template<
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.
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
size_t prependEmptyBlock(EncodingImpl< TAG > &encoder, uint32_t type)
Prepend an empty TLV element.
size_t prependBinaryBlock(EncodingImpl< TAG > &encoder, uint32_t type, span< const uint8_t > value)
Prepend a TLV element containing a sequence of raw bytes.
std::string to_string(const errinfo_stacktrace &x)
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)