1 #ifndef NDNPH_TLV_NNI_HPP
2 #define NDNPH_TLV_NNI_HPP
15 if (d.
length !=
sizeof(T)) {
26 uint8_t* room = encoder.
prependRoom(
sizeof(m_number));
27 if (room !=
nullptr) {
55 return (
static_cast<uint16_t
>(
input[0]) << 8) |
static_cast<uint16_t
>(
input[1]);
68 return (
static_cast<uint32_t
>(
input[0]) << 24) | (
static_cast<uint32_t
>(
input[1]) << 16) |
69 (
static_cast<uint32_t
>(
input[2]) << 8) |
static_cast<uint32_t
>(
input[3]);
84 return (
static_cast<uint64_t
>(
input[0]) << 56) | (
static_cast<uint64_t
>(
input[1]) << 48) |
85 (
static_cast<uint64_t
>(
input[2]) << 40) | (
static_cast<uint64_t
>(
input[3]) << 32) |
86 (
static_cast<uint64_t
>(
input[4]) << 24) | (
static_cast<uint64_t
>(
input[5]) << 16) |
87 (
static_cast<uint64_t
>(
input[6]) << 8) |
static_cast<uint64_t
>(
input[7]);
125 template<typename I, typename Limit = typename std::enable_if<std::is_integral<I>::value,
126 std::numeric_limits<I>>::type>
149 explicit NNI(uint64_t number)
150 : m_number(number) {}
153 if (m_number <= std::numeric_limits<uint8_t>::max()) {
154 NNI1(m_number).encodeTo(encoder);
155 }
else if (m_number <= std::numeric_limits<uint16_t>::max()) {
156 NNI2(m_number).encodeTo(encoder);
157 }
else if (m_number <= std::numeric_limits<uint32_t>::max()) {
158 NNI4(m_number).encodeTo(encoder);
160 NNI8(m_number).encodeTo(encoder);
165 uint64_t m_number = 0;
169 template<
typename N = NNI>
Decoded TLV.
Definition: decoder.hpp:13
size_t length
Definition: decoder.hpp:39
const uint8_t * value
Definition: decoder.hpp:40
TLV encoder that accepts items in reverse order.
Definition: encoder.hpp:10
uint8_t * prependRoom(size_t size)
Make room to prepend an object.
Definition: encoder.hpp:90
bool prependTlv(uint32_t type, OmitEmptyTag omitEmpty, const Arg &... arg)
Prepend TLV, measuring TLV-LENGTH automatically.
Definition: encoder.hpp:143
NonNegativeInteger encoding.
Definition: nni.hpp:118
void encodeTo(Encoder &encoder) const
Definition: nni.hpp:152
static bool decode(const Decoder::Tlv &d, I &value, uint64_t max=Limit::max())
Decode NonNegativeInteger.
Definition: nni.hpp:127
NNI(uint64_t number)
Definition: nni.hpp:149
Encode to a TLV element where TLV-VALUE is a NonNegativeInteger.
Definition: nni.hpp:170
void encodeTo(Encoder &encoder) const
Definition: nni.hpp:177
NniElement(uint32_t type, I value)
Definition: nni.hpp:173
static bool decode(const Decoder::Tlv &d, T &value)
Definition: nni.hpp:14
void encodeTo(Encoder &encoder) const
Definition: nni.hpp:25
static void writeValue(uint8_t *room, T n)
NNIValue(T number)
Definition: nni.hpp:22
static T readValue(const uint8_t *input)
bool input(Region ®ion, T &target, std::istream &is=std::cin)
Read and decode from input stream.
Definition: io.hpp:15
detail::NNIValue< uint32_t > NNI4
4-byte number encoding.
Definition: nni.hpp:112
detail::NNIValue< uint16_t > NNI2
2-byte number encoding.
Definition: nni.hpp:109
detail::NNIValue< uint64_t > NNI8
8-byte number encoding.
Definition: nni.hpp:115
detail::NNIValue< uint8_t > NNI1
1-byte number encoding.
Definition: nni.hpp:106