24 #include <boost/endian/conversion.hpp> 29 namespace endian = boost::endian;
37 size_t length = encoder.prependNonNegativeInteger(value);
38 length += encoder.prependVarNumber(length);
39 length += encoder.prependVarNumber(type);
59 return encoder.
block();
75 size_t length = encoder.prependVarNumber(0);
76 length += encoder.prependVarNumber(type);
96 return encoder.
block();
105 return prependBinaryBlock(encoder, type, {
reinterpret_cast<const uint8_t*
>(value.data()), value.size()});
123 return std::string(reinterpret_cast<const char*>(block.
value()), block.
value_size());
128 static_assert(std::numeric_limits<double>::is_iec559,
"This code requires IEEE-754 doubles");
135 std::memcpy(&temp, &value, 8);
136 endian::native_to_big_inplace(temp);
137 return prependBinaryBlock(encoder, type, {
reinterpret_cast<const uint8_t*
>(&temp), 8});
155 return encoder.
block();
165 #if BOOST_VERSION >= 107100 166 return endian::endian_load<double, 8, endian::order::big>(block.
value());
169 std::memcpy(&temp, block.
value(), 8);
170 endian::big_to_native_inplace(temp);
172 std::memcpy(&d, &temp, 8);
183 size_t length = encoder.prependBytes(value);
184 length += encoder.prependVarNumber(length);
185 length += encoder.prependVarNumber(type);
205 return encoder.
block();
215 return encoder.prependBytes(block);
Copyright (c) 2011-2015 Regents of the University of California.
EncodingImpl specialization for actual TLV encoding.
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
Block makeEmptyBlock(uint32_t type)
Create an empty TLV block.
template size_t prependBinaryBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t, span< const uint8_t >)
Block makeDoubleBlock(uint32_t type, double value)
Create a TLV element containing an IEEE 754 double-precision floating-point number.
template size_t prependEmptyBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t)
template size_t prependNonNegativeIntegerBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t, uint64_t)
template size_t prependNonNegativeIntegerBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t, uint64_t)
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.
Represents a TLV element of the NDN packet format.
uint64_t readNonNegativeInteger(size_t size, Iterator &begin, Iterator end)
Read a NonNegativeInteger in NDN-TLV encoding.
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, const std::string &value)
Prepend a TLV element containing a string.
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
std::string readString(const Block &block)
Read TLV-VALUE of a TLV element as a string.
Block makeNonNegativeIntegerBlock(uint32_t type, uint64_t value)
Create a TLV block containing a non-negative integer.
template size_t prependBlock< EncoderTag >(EncodingImpl< EncoderTag > &, const Block &)
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
EncodingImpl specialization for TLV size estimation.
template size_t prependEmptyBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t)
template size_t prependStringBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t, const std::string &)
Block block(bool verifyLength=true) const
Create Block from the underlying buffer.
size_t prependEmptyBlock(EncodingImpl< TAG > &encoder, uint32_t type)
Prepend an empty TLV element.
template size_t prependBinaryBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t, span< const uint8_t >)
Block makeStringBlock(uint32_t type, const std::string &value)
Create a TLV block containing a string.
double readDouble(const Block &block)
Read TLV-VALUE of a TLV element as an IEEE 754 double-precision floating-point number.
size_t prependBinaryBlock(EncodingImpl< TAG > &encoder, uint32_t type, span< const uint8_t > value)
Prepend a TLV element containing a sequence of raw bytes.
template size_t prependStringBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t, const std::string &)
template size_t prependDoubleBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t, double)
Block makeBinaryBlock(uint32_t type, span< const uint8_t > value)
Create a TLV block copying the TLV-VALUE from a byte range.
template size_t prependDoubleBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t, double)
const uint8_t * value() const noexcept
Return a raw pointer to the beginning of TLV-VALUE.
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.
size_t prependDoubleBlock(EncodingImpl< TAG > &encoder, uint32_t type, double value)
Prepend a TLV element containing an IEEE 754 double-precision floating-point number.
size_t prependBlock(EncodingImpl< TAG > &encoder, const Block &block)
Prepend a TLV element.
template size_t prependBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, const Block &)
const_iterator value_end() const noexcept
Get end iterator of TLV-VALUE.
represents an error in TLV encoding or decoding