33 size_t valueLength = encoder.prependNonNegativeInteger(value);
34 size_t totalLength = valueLength;
35 totalLength += encoder.prependVarNumber(valueLength);
36 totalLength += encoder.prependVarNumber(type);
56 return encoder.
block();
72 size_t totalLength = encoder.prependVarNumber(0);
73 totalLength += encoder.prependVarNumber(type);
93 return encoder.
block();
102 return encoder.prependByteArrayBlock(type, reinterpret_cast<const uint8_t*>(value.data()), value.size());
120 return std::string(reinterpret_cast<const char*>(block.
value()), block.
value_size());
125 static_assert(std::numeric_limits<double>::is_iec559,
"This code requires IEEE-754 doubles");
132 std::memcpy(&temp, &value, 8);
133 boost::endian::native_to_big_inplace(temp);
134 return encoder.prependByteArrayBlock(type, reinterpret_cast<const uint8_t*>(&temp), 8);
152 return encoder.
block();
159 BOOST_THROW_EXCEPTION(
tlv::Error(
"Invalid length for double (must be 8)"));
163 std::memcpy(&temp, block.
value(), 8);
164 boost::endian::big_to_native_inplace(temp);
166 std::memcpy(&d, &temp, 8);
181 return encoder.
block();
187 return makeBinaryBlock(type, reinterpret_cast<const uint8_t*>(value), length);
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.
size_t prependByteArrayBlock(uint32_t type, const uint8_t *array, size_t arraySize) const noexcept
Prepend TLV block of type type and value from buffer array of size arraySize.
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)
size_t value_size() const
Get size of TLV-VALUE aka TLV-LENGTH.
template size_t prependNonNegativeIntegerBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t, uint64_t)
Represents a TLV element of NDN packet format.
uint64_t readNonNegativeInteger(size_t size, Iterator &begin, Iterator end)
Read 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.
std::string readString(const Block &block)
Read TLV-VALUE of a TLV element as a string.
const uint8_t * value() const
Get pointer to TLV-VALUE.
Block makeNonNegativeIntegerBlock(uint32_t type, uint64_t value)
Create a TLV block containing a non-negative integer.
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
EncodingImpl specialization for TLV size estimation.
Buffer::const_iterator value_begin() const
Get begin iterator of TLV-VALUE.
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.
Block makeBinaryBlock(uint32_t type, const uint8_t *value, size_t length)
Create a TLV block copying TLV-VALUE from raw buffer.
Block makeStringBlock(uint32_t type, const std::string &value)
Create a TLV block containing a string.
Buffer::const_iterator value_end() const
Get end iterator of TLV-VALUE.
size_t prependByteArrayBlock(uint32_t type, const uint8_t *array, size_t arraySize)
Prepend TLV block of type type and value from buffer array of size arraySize.
double readDouble(const Block &block)
Read TLV-VALUE of a TLV element as an IEEE 754 double-precision floating-point number.
template size_t prependStringBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t, const std::string &)
template size_t prependDoubleBlock< EncoderTag >(EncodingImpl< EncoderTag > &, uint32_t, double)
template size_t prependDoubleBlock< EstimatorTag >(EncodingImpl< EstimatorTag > &, uint32_t, double)
size_t prependDoubleBlock(EncodingImpl< TAG > &encoder, uint32_t type, double value)
Prepend a TLV element containing an IEEE 754 double-precision floating-point number.
represents an error in TLV encoding or decoding