lp: consistently use uint32_t for TLV types
Change-Id: I880043b634476eaaafa35b49f6b3f93210ae5ecf
diff --git a/ndn-cxx/encoding/tlv-nfd.hpp b/ndn-cxx/encoding/tlv-nfd.hpp
index 0cf13b0..100dd93 100644
--- a/ndn-cxx/encoding/tlv-nfd.hpp
+++ b/ndn-cxx/encoding/tlv-nfd.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -22,15 +22,17 @@
#ifndef NDN_CXX_ENCODING_TLV_NFD_HPP
#define NDN_CXX_ENCODING_TLV_NFD_HPP
-#include "ndn-cxx/encoding/tlv.hpp"
-#include "ndn-cxx/encoding/nfd-constants.hpp"
+#include <cstdint>
namespace ndn {
namespace tlv {
namespace nfd {
-// NFD Management protocol
-enum {
+/**
+ * @brief TLV-TYPE numbers defined by the NFD Management protocol.
+ * @sa https://redmine.named-data.net/projects/nfd/wiki/Management
+ */
+enum : uint32_t {
// ControlParameters
ControlParameters = 104,
FaceId = 105,
@@ -100,7 +102,7 @@
// RIB Management
RibEntry = 128,
- Route = 129
+ Route = 129,
};
} // namespace nfd
diff --git a/ndn-cxx/encoding/tlv-security.hpp b/ndn-cxx/encoding/tlv-security.hpp
index 3446bd6..be13371 100644
--- a/ndn-cxx/encoding/tlv-security.hpp
+++ b/ndn-cxx/encoding/tlv-security.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2021 Regents of the University of California.
+ * Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -22,14 +22,14 @@
#ifndef NDN_CXX_ENCODING_TLV_SECURITY_HPP
#define NDN_CXX_ENCODING_TLV_SECURITY_HPP
-#include "ndn-cxx/encoding/tlv.hpp"
+#include <cstdint>
namespace ndn {
namespace tlv {
namespace security {
/**
- * @brief TLV-TYPE numbers for SafeBag and related elements
+ * @brief TLV-TYPE numbers for SafeBag and related elements.
* @sa <a href="../specs/safe-bag.html">SafeBag Format</a>
*/
enum : uint32_t {
diff --git a/ndn-cxx/lp/field-decl.hpp b/ndn-cxx/lp/field-decl.hpp
index de264b7..1cb1916 100644
--- a/ndn-cxx/lp/field-decl.hpp
+++ b/ndn-cxx/lp/field-decl.hpp
@@ -169,14 +169,14 @@
* \tparam DECODER_TAG selects a specialization of DecodeHelper.
* \tparam ENCODER_TAG selects a specialization of EncodeHelper.
*/
-template<typename LOCATION, typename VALUE, uint64_t TYPE, bool REPEATABLE = false,
+template<typename LOCATION, typename VALUE, uint32_t TYPE, bool REPEATABLE = false,
typename DECODER_TAG = VALUE, typename ENCODER_TAG = VALUE>
class FieldDecl
{
public:
using FieldLocation = LOCATION;
using ValueType = VALUE;
- using TlvType = std::integral_constant<uint64_t, TYPE>;
+ using TlvType = std::integral_constant<uint32_t, TYPE>;
using IsRepeatable = std::bool_constant<REPEATABLE>;
/** \brief Decode a field.
diff --git a/ndn-cxx/lp/field.hpp b/ndn-cxx/lp/field.hpp
index 4ba87fa..cae13f7 100644
--- a/ndn-cxx/lp/field.hpp
+++ b/ndn-cxx/lp/field.hpp
@@ -55,13 +55,13 @@
} // namespace field_location_tags
/**
- * \brief Concept check for fields.
+ * \brief Concept check for NDNLPv2 fields.
*/
template<class X>
struct Field
{
static_assert(std::is_base_of_v<field_location_tags::Base, typename X::FieldLocation>, "");
- static_assert(std::is_same_v<typename X::TlvType::value_type, uint64_t>, "");
+ static_assert(std::is_same_v<typename X::TlvType::value_type, uint32_t>, "");
static_assert(std::is_same_v<typename X::IsRepeatable::value_type, bool>, "");
static_assert(std::is_default_constructible_v<typename X::ValueType>, "");
static_assert(std::is_copy_constructible_v<typename X::ValueType>, "");
diff --git a/ndn-cxx/lp/packet.cpp b/ndn-cxx/lp/packet.cpp
index d6fb3e8..7097384 100644
--- a/ndn-cxx/lp/packet.cpp
+++ b/ndn-cxx/lp/packet.cpp
@@ -55,10 +55,10 @@
FieldInfo() noexcept = default;
explicit
- FieldInfo(uint64_t tlv) noexcept;
+ FieldInfo(uint32_t type) noexcept;
public:
- uint64_t tlvType = 0; ///< TLV-TYPE of the field; 0 if field does not exist
+ uint32_t tlvType = 0; ///< TLV-TYPE of the field; 0 if field does not exist
bool isRecognized = false; ///< is this field known
bool canIgnore = false; ///< can this unknown field be ignored
bool isRepeatable = false; ///< is the field repeatable
@@ -84,8 +84,8 @@
}
};
-FieldInfo::FieldInfo(uint64_t tlv) noexcept
- : tlvType(tlv)
+FieldInfo::FieldInfo(uint32_t type) noexcept
+ : tlvType(type)
{
boost::mpl::for_each<FieldSet>(boost::bind(ExtractFieldInfo(), this, _1));
if (!isRecognized) {
@@ -104,10 +104,7 @@
} // namespace
-Packet::Packet()
- : m_wire(Block(tlv::LpPacket))
-{
-}
+Packet::Packet() = default;
Packet::Packet(const Block& wire)
{
@@ -170,7 +167,7 @@
}
bool
-Packet::comparePos(uint64_t first, const Block& second) noexcept
+Packet::comparePos(uint32_t first, const Block& second) noexcept
{
FieldInfo firstInfo(first);
FieldInfo secondInfo(second.type());
diff --git a/ndn-cxx/lp/packet.hpp b/ndn-cxx/lp/packet.hpp
index 5b90549..ba38ebd 100644
--- a/ndn-cxx/lp/packet.hpp
+++ b/ndn-cxx/lp/packet.hpp
@@ -202,10 +202,10 @@
private:
static bool
- comparePos(uint64_t first, const Block& second) noexcept;
+ comparePos(uint32_t first, const Block& second) noexcept;
private:
- mutable Block m_wire;
+ mutable Block m_wire{tlv::LpPacket};
};
} // namespace lp
diff --git a/ndn-cxx/lp/tlv.hpp b/ndn-cxx/lp/tlv.hpp
index 3678dbd..fe99f34 100644
--- a/ndn-cxx/lp/tlv.hpp
+++ b/ndn-cxx/lp/tlv.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
- * Copyright (c) 2013-2022 Regents of the University of California.
+ * Copyright (c) 2013-2023 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -22,6 +22,8 @@
#ifndef NDN_CXX_LP_TLV_HPP
#define NDN_CXX_LP_TLV_HPP
+#include <cstdint>
+
namespace ndn {
namespace lp {
/**
@@ -30,9 +32,10 @@
namespace tlv {
/**
- * \brief TLV-TYPE numbers for NDNLPv2.
+ * @brief TLV-TYPE numbers for NDNLPv2.
+ * @sa https://redmine.named-data.net/projects/nfd/wiki/NDNLPv2#TLV-TYPE-Number-Assignments
*/
-enum {
+enum : uint32_t {
LpPacket = 100,
Fragment = 80,
Sequence = 81,
@@ -50,28 +53,23 @@
TxSequence = 840,
NonDiscovery = 844,
PrefixAnnouncement = 848,
-};
-enum {
/**
* \brief Lower bound of 1-octet header field.
*/
HEADER1_MIN = 81,
-
/**
* \brief Upper bound of 1-octet header field.
*/
HEADER1_MAX = 99,
-
/**
* \brief Lower bound of 3-octet header field.
*/
HEADER3_MIN = 800,
-
/**
* \brief Upper bound of 3-octet header field.
*/
- HEADER3_MAX = 959
+ HEADER3_MAX = 959,
};
} // namespace tlv