22 #ifndef NDN_CXX_LP_FIELD_DECL_HPP 23 #define NDN_CXX_LP_FIELD_DECL_HPP 32 #include <boost/concept/requires.hpp> 33 #include <boost/endian/conversion.hpp> 40 struct NonNegativeIntegerTag;
42 template<
typename TlvType,
typename T>
50 type.wireDecode(wire);
55 template<
typename TlvType>
70 template<
typename TlvType>
80 template<
typename TlvType>
88 " should contain a 64-bit integer"));
91 std::memcpy(&n, wire.
value(),
sizeof(n));
92 return boost::endian::big_to_native(n);
96 template<
typename TlvType>
97 struct DecodeHelper<TlvType, std::pair<Buffer::const_iterator, Buffer::const_iterator>>
99 static std::pair<Buffer::const_iterator, Buffer::const_iterator>
104 " cannot be empty"));
111 template<
typename encoding::Tag TAG,
typename TlvType,
typename T>
118 return value.wireEncode(encoder);
122 template<
typename encoding::Tag TAG,
typename TlvType>
129 length += encoder.prependVarNumber(0);
130 length += encoder.prependVarNumber(TlvType::value);
135 template<
typename encoding::Tag TAG,
typename TlvType>
145 template<
typename encoding::Tag TAG,
typename TlvType>
151 boost::endian::native_to_big_inplace(value);
152 return encoder.prependByteArrayBlock(TlvType::value,
153 reinterpret_cast<const uint8_t*>(&value),
sizeof(value));
157 template<
typename encoding::Tag TAG,
typename TlvType>
158 struct EncodeHelper<TAG, TlvType, std::pair<Buffer::const_iterator, Buffer::const_iterator>>
164 length += encoder.prependRange(value.first, value.second);
165 length += encoder.prependVarNumber(length);
166 length += encoder.prependVarNumber(TlvType::value);
179 template<
typename LOCATION,
typename VALUE, uint64_t TYPE,
bool REPEATABLE =
false,
180 typename DECODER_TAG = VALUE,
typename ENCODER_TAG = VALUE>
186 typedef std::integral_constant<uint64_t, TYPE>
TlvType;
197 if (wire.
type() != TlvType::value) {
208 template<
typename encoding::Tag TAG>
219 #endif // NDN_CXX_LP_FIELD_DECL_HPP static ValueType decode(const Block &wire)
Decode a field.
Copyright (c) 2011-2015 Regents of the University of California.
static T decode(const Block &wire)
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
std::integral_constant< bool, REPEATABLE > IsRepeatable
size_t value_size() const
Get size of TLV-VALUE aka TLV-LENGTH.
static size_t encode(EncodingImpl< TAG > &encoder, uint64_t value)
Represents a TLV element of NDN packet format.
static size_t encode(EncodingImpl< TAG > &encoder, const EmptyValue value)
const uint8_t * value() const
Get pointer to TLV-VALUE.
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
static size_t encode(EncodingImpl< TAG > &encoder, const T &value)
Buffer::const_iterator value_begin() const
Get begin iterator of TLV-VALUE.
a concept check for TLV abstraction with .wireEncode method
static size_t encode(EncodingImpl< TAG > &encoder, uint64_t value)
Buffer::const_iterator value_end() const
Get end iterator of TLV-VALUE.
represents a zero-length TLV-VALUE
static size_t encode(EncodingImpl< TAG > &encoder, const ValueType &value)
Encode a field and prepend to encoder.
static size_t encode(EncodingImpl< TAG > &encoder, const std::pair< Buffer::const_iterator, Buffer::const_iterator > &value)
static std::pair< Buffer::const_iterator, Buffer::const_iterator > decode(const Block &wire)
static uint64_t decode(const Block &wire)
std::string to_string(const V &v)
a concept check for TLV abstraction with .wireDecode method and constructible from Block
static uint64_t decode(const Block &wire)
std::integral_constant< uint64_t, TYPE > TlvType
uint32_t type() const
Get TLV-TYPE.
represents an error in TLV encoding or decoding
static EmptyValue decode(const Block &wire)