22 #ifndef NDN_CXX_ENCODING_BLOCK_HELPERS_HPP
23 #define NDN_CXX_ENCODING_BLOCK_HELPERS_HPP
42 extern template size_t
45 extern template size_t
71 std::enable_if_t<std::is_integral<R>::value, R>
75 if (value > std::numeric_limits<R>::max()) {
78 return static_cast<R
>(value);
90 std::enable_if_t<std::is_enum<R>::value, R>
93 return static_cast<R
>(readNonNegativeIntegerAs<std::underlying_type_t<R>>(block));
106 extern template size_t
109 extern template size_t
130 extern template size_t
133 extern template size_t
162 extern template size_t
165 extern template size_t
195 extern template size_t
198 extern template size_t
216 [[deprecated(
"use the overload that takes a span<>")]]
232 return makeBinaryBlock(type, {
reinterpret_cast<const uint8_t*
>(value), length});
240 template<
class Iterator>
244 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<Iterator>));
250 size_t valueLength = last - first;
251 size_t totalLength = valueLength;
260 return encoder.
block();
267 template<
class Iterator>
271 BOOST_CONCEPT_ASSERT((boost::InputIterator<Iterator>));
279 size_t valueLength = encoder.
appendRange(first, last);
283 return encoder.
block();
297 template<
class Iterator>
301 using BinaryBlockHelper = std::conditional_t<
302 std::is_base_of<std::random_access_iterator_tag,
303 typename std::iterator_traits<Iterator>::iterator_category>::value,
307 return BinaryBlockHelper::makeBlock(type, first, last);
319 extern template size_t
322 extern template size_t
332 template<Tag TAG,
class U>
338 size_t length = value.wireEncode(encoder);
339 length += encoder.prependVarNumber(length);
340 length += encoder.prependVarNumber(type);
359 return encoder.
block();
370 template<Tag TAG,
class I>
376 auto rfirst = std::make_reverse_iterator(last);
377 auto rlast = std::make_reverse_iterator(first);
380 for (
auto i = rfirst; i != rlast; ++i) {
381 length += i->wireEncode(encoder);
384 length += encoder.prependVarNumber(length);
385 length += encoder.prependVarNumber(type);
405 return encoder.
block();
Represents a TLV element of the NDN packet format.
uint32_t type() const
Return the TLV-TYPE of the Block.
a concept check for TLV abstraction with .wireEncode method
Block block(bool verifyLength=true) const
Create Block from the underlying buffer.
size_t prependRange(Iterator first, Iterator last)
Prepend range of bytes from the range [first, last)
size_t prependVarNumber(uint64_t number)
Prepend number encoded as a VAR-NUMBER in NDN-TLV format.
size_t appendRange(Iterator first, Iterator last)
Append range of bytes from the range [first, last)
EncodingImpl specialization for actual TLV encoding.
EncodingImpl specialization for TLV size estimation.
constexpr size_t prependVarNumber(uint64_t n) const noexcept
Prepend n in VarNumber encoding.
Create a binary block copying from RandomAccessIterator.
static Block makeBlock(uint32_t type, Iterator first, Iterator last)
Create a binary block copying from generic InputIterator.
static Block makeBlock(uint32_t type, Iterator first, Iterator last)
represents an error in TLV encoding or decoding
template size_t prependEmptyBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t)
template size_t prependDoubleBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t, double)
template size_t prependBinaryBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t, span< const uint8_t >)
size_t prependNestedBlock(EncodingImpl< TAG > &encoder, uint32_t type, const U &value)
Prepend a TLV element containing a nested TLV element.
std::enable_if_t< std::is_integral< R >::value, R > readNonNegativeIntegerAs(const Block &block)
Read a non-negative integer from a TLV element and cast to the specified type.
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
template size_t prependStringBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t, const std::string &)
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, const std::string &value)
Prepend a TLV element containing a string.
template size_t prependBlock< EncoderTag >(EncodingImpl< EncoderTag > &, const Block &)
template size_t prependBinaryBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t, span< const uint8_t >)
template size_t prependDoubleBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t, double)
Block makeNonNegativeIntegerBlock(uint32_t type, uint64_t value)
Create a TLV block containing a non-negative integer.
Block makeEmptyBlock(uint32_t type)
Create an empty TLV block.
template size_t prependBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, const Block &)
template size_t prependNonNegativeIntegerBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t, uint64_t)
size_t prependEmptyBlock(EncodingImpl< TAG > &encoder, uint32_t type)
Prepend an empty TLV element.
template size_t prependNonNegativeIntegerBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t, uint64_t)
double readDouble(const Block &block)
Read TLV-VALUE of a TLV element as an IEEE 754 double-precision floating-point number.
template size_t prependEmptyBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t)
template size_t prependStringBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t, const std::string &)
Block makeBinaryBlock(uint32_t type, span< const uint8_t > value)
Create a TLV block copying the TLV-VALUE from a byte range.
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 readString(const Block &block)
Read TLV-VALUE of a TLV element as a string.
size_t prependBlock(EncodingImpl< TAG > &encoder, const Block &block)
Prepend a TLV element.
Block makeNestedBlock(uint32_t type, const U &value)
Create a TLV block containing a nested TLV element.
Block makeStringBlock(uint32_t type, const std::string &value)
Create a TLV block containing a string.
Block makeDoubleBlock(uint32_t type, double value)
Create a TLV element containing an IEEE 754 double-precision floating-point number.
size_t prependDoubleBlock(EncodingImpl< TAG > &encoder, uint32_t type, double value)
Prepend a TLV element containing an IEEE 754 double-precision floating-point number.
std::string to_string(const errinfo_stacktrace &x)