tlv-nlsr.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NLSR_TLV_NLSR_HPP
23 #define NLSR_TLV_NLSR_HPP
24 
25 #include <ndn-cxx/encoding/tlv.hpp>
26 #include <ndn-cxx/encoding/block-helpers.hpp>
27 
28 namespace ndn {
29 namespace tlv {
30 namespace nlsr {
31 
37 enum {
38  LsaInfo = 128,
39  OriginRouter = 129,
41  AdjacencyLsa = 131,
42  Adjacency = 132,
44  Double = 134,
47  NameLsa = 137,
48  LsdbStatus = 138,
50  Cost = 140,
51  Uri = 141,
52  Destination = 142,
53  NextHop = 143,
54  RoutingTable = 144,
56 };
57 
63 inline double
64 readDouble(const ndn::Block& block)
65 {
66  block.parse();
67  auto it = block.elements_begin();
68 
69  double doubleFromBlock = 0.0;
70  if (it == it->elements_end() || it->type() != ndn::tlv::nlsr::Double ||
71  it->value_size() != sizeof(doubleFromBlock)) {
72  BOOST_THROW_EXCEPTION(ndn::tlv::Error("Block does not contain a double"));
73  }
74  memcpy(&doubleFromBlock, it->value(), sizeof(doubleFromBlock));
75  return doubleFromBlock;
76 }
77 
83 template<ndn::encoding::Tag TAG>
84 inline size_t
85 prependDouble(ndn::EncodingImpl<TAG>& encoder, uint32_t type, double value)
86 {
87  size_t totalLength = 0;
88 
89  const uint8_t* doubleBytes = reinterpret_cast<const uint8_t*>(&value);
90  totalLength = encoder.prependByteArrayBlock(ndn::tlv::nlsr::Double, doubleBytes, 8);
91  totalLength += encoder.prependVarNumber(totalLength);
92  totalLength += encoder.prependVarNumber(type);
93 
94  return totalLength;
95 }
96 
97 } // namespace nlsr
98 } // namespace tlv
99 } // namespace ndn
100 
101 #endif // NLSR_TLV_NLSR_HPP
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.
Definition: tlv-nlsr.hpp:28
double readDouble(const ndn::Block &block)
Read a double from a TLV element.
Definition: tlv-nlsr.hpp:64
size_t prependDouble(ndn::EncodingImpl< TAG > &encoder, uint32_t type, double value)
Prepend a TLV element containing a double.
Definition: tlv-nlsr.hpp:85
Copyright (c) 2014-2018, The University of Memphis, Regents of the University of California, Arizona Board of Regents.