24 #include <boost/endian/conversion.hpp>
34 size_t length = encoder.prependVarNumber(0);
35 length += encoder.prependVarNumber(type);
55 return encoder.
block();
64 size_t length = encoder.prependNonNegativeInteger(value);
65 length += encoder.prependVarNumber(length);
66 length += encoder.prependVarNumber(type);
86 return encoder.
block();
98 static_assert(std::numeric_limits<double>::is_iec559,
"This code requires IEEE-754 doubles");
105 std::memcpy(&temp, &value, 8);
106 boost::endian::native_to_big_inplace(temp);
107 return prependBinaryBlock(encoder, type, {
reinterpret_cast<const uint8_t*
>(&temp), 8});
125 return encoder.
block();
134 return boost::endian::endian_load<double, 8, boost::endian::order::big>(block.
value());
143 size_t length = encoder.prependBytes(value);
144 length += encoder.prependVarNumber(length);
145 length += encoder.prependVarNumber(type);
165 return encoder.
block();
174 return prependBinaryBlock(encoder, type, {
reinterpret_cast<const uint8_t*
>(value.data()), value.size()});
186 return std::string(
reinterpret_cast<const char*
>(block.
value()), block.
value_size());
196 return encoder.prependBytes(block);
Represents a TLV element of the NDN packet format.
const_iterator value_end() const noexcept
Get end iterator of TLV-VALUE.
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
span< const uint8_t > value_bytes() const noexcept
Return a read-only view of TLV-VALUE as a contiguous range of bytes.
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.
Block block(bool verifyLength=true) const
Create Block from the underlying buffer.
EncodingImpl specialization for actual TLV encoding.
EncodingImpl specialization for TLV size estimation.
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 >)
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.
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.
template size_t prependStringBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t, std::string_view)
Block makeEmptyBlock(uint32_t type)
Create an empty TLV block.
template size_t prependBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, const Block &)
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, std::string_view value)
Prepend a TLV element containing a string.
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)
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 the TLV-VALUE of a TLV element as a string.
size_t prependBlock(EncodingImpl< TAG > &encoder, const Block &block)
Prepend a TLV element.
template size_t prependStringBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t, std::string_view)
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.
constexpr uint64_t readNonNegativeInteger(size_t size, Iterator &begin, Iterator end)
Read a NonNegativeInteger in NDN-TLV encoding.