management: change ForwarderStatus.NfdVersion to string
refs #2003
Breaks: nfd:commit:afbd74d9f18f73863927c503c0024c7e5b32ec9f
Change-Id: I195efa5633b643708165a4b1b2e60e56b8a6f17e
diff --git a/src/management/nfd-forwarder-status.cpp b/src/management/nfd-forwarder-status.cpp
index 457c673..c4e736a 100644
--- a/src/management/nfd-forwarder-status.cpp
+++ b/src/management/nfd-forwarder-status.cpp
@@ -34,8 +34,7 @@
"ForwarderStatus::Error must inherit from tlv::Error");
ForwarderStatus::ForwarderStatus()
- : m_nfdVersion(0)
- , m_startTimestamp(time::system_clock::TimePoint::min())
+ : m_startTimestamp(time::system_clock::TimePoint::min())
, m_currentTimestamp(time::system_clock::TimePoint::min())
, m_nNameTreeEntries(0)
, m_nFibEntries(0)
@@ -82,8 +81,9 @@
time::toUnixTimestamp(m_currentTimestamp).count());
totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::StartTimestamp,
time::toUnixTimestamp(m_startTimestamp).count());
- totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::NfdVersion,
- m_nfdVersion);
+ totalLength += prependByteArrayBlock(encoder,tlv::nfd::NfdVersion,
+ reinterpret_cast<const uint8_t*>(m_nfdVersion.c_str()),
+ m_nfdVersion.size());
totalLength += encoder.prependVarNumber(totalLength);
totalLength += encoder.prependVarNumber(tlv::Content);
@@ -123,7 +123,7 @@
Block::element_const_iterator val = m_wire.elements_begin();
if (val != m_wire.elements_end() && val->type() == tlv::nfd::NfdVersion) {
- m_nfdVersion = static_cast<int>(readNonNegativeInteger(*val));
+ m_nfdVersion.assign(reinterpret_cast<const char*>(val->value()), val->value_size());
++val;
}
else {
@@ -220,7 +220,7 @@
}
ForwarderStatus&
-ForwarderStatus::setNfdVersion(int nfdVersion)
+ForwarderStatus::setNfdVersion(const std::string& nfdVersion)
{
m_wire.reset();
m_nfdVersion = nfdVersion;
diff --git a/src/management/nfd-forwarder-status.hpp b/src/management/nfd-forwarder-status.hpp
index 90ec7a5..c45d403 100644
--- a/src/management/nfd-forwarder-status.hpp
+++ b/src/management/nfd-forwarder-status.hpp
@@ -74,14 +74,14 @@
wireDecode(const Block& wire);
public: // getters & setters
- int
+ const std::string&
getNfdVersion() const
{
return m_nfdVersion;
}
ForwarderStatus&
- setNfdVersion(int nfdVersion);
+ setNfdVersion(const std::string& nfdVersion);
const time::system_clock::TimePoint&
getStartTimestamp() const
@@ -183,7 +183,7 @@
setNOutDatas(uint64_t nOutDatas);
private:
- int m_nfdVersion;
+ std::string m_nfdVersion;
time::system_clock::TimePoint m_startTimestamp;
time::system_clock::TimePoint m_currentTimestamp;
size_t m_nNameTreeEntries;
diff --git a/tests/unit-tests/management/test-nfd-forwarder-status.cpp b/tests/unit-tests/management/test-nfd-forwarder-status.cpp
index fa8de01..0255f3c 100644
--- a/tests/unit-tests/management/test-nfd-forwarder-status.cpp
+++ b/tests/unit-tests/management/test-nfd-forwarder-status.cpp
@@ -32,7 +32,7 @@
BOOST_AUTO_TEST_CASE(Encode)
{
ForwarderStatus status1;
- status1.setNfdVersion(1014210635);
+ status1.setNfdVersion("0.2.0-65-g75ab6b7");
status1.setStartTimestamp(time::fromUnixTimestamp(time::milliseconds(375193249325LL)));
status1.setCurrentTimestamp(time::fromUnixTimestamp(time::milliseconds(886109034272LL)));
status1.setNNameTreeEntries(1849943160);
@@ -54,13 +54,14 @@
// printf("0x%02x, ", *it);
//}
static const uint8_t expected[] = {
- 0x15, 0x50, 0x80, 0x04, 0x3c, 0x73, 0xa0, 0x4b, 0x81, 0x08, 0x00, 0x00,
- 0x00, 0x57, 0x5b, 0x42, 0xa6, 0x2d, 0x82, 0x08, 0x00, 0x00, 0x00, 0xce,
- 0x50, 0x36, 0xd7, 0x20, 0x83, 0x04, 0x6e, 0x43, 0xe4, 0x78, 0x84, 0x04,
- 0x25, 0x0e, 0xfe, 0xe4, 0x85, 0x04, 0x1c, 0xbc, 0xb7, 0x4d, 0x86, 0x04,
- 0x69, 0x9a, 0x61, 0xf2, 0x87, 0x04, 0x4b, 0x65, 0xe3, 0xf0, 0x90, 0x04,
- 0x24, 0x86, 0xc3, 0x5f, 0x91, 0x04, 0x6d, 0xe2, 0xbc, 0xf2, 0x92, 0x04,
- 0x38, 0xc0, 0x92, 0x3d, 0x93, 0x04, 0x08, 0x3c, 0xbf, 0x2a
+ 0x15, 0x5d, 0x80, 0x11, 0x30, 0x2e, 0x32, 0x2e, 0x30, 0x2d, 0x36, 0x35,
+ 0x2d, 0x67, 0x37, 0x35, 0x61, 0x62, 0x36, 0x62, 0x37, 0x81, 0x08, 0x00,
+ 0x00, 0x00, 0x57, 0x5b, 0x42, 0xa6, 0x2d, 0x82, 0x08, 0x00, 0x00, 0x00,
+ 0xce, 0x50, 0x36, 0xd7, 0x20, 0x83, 0x04, 0x6e, 0x43, 0xe4, 0x78, 0x84,
+ 0x04, 0x25, 0x0e, 0xfe, 0xe4, 0x85, 0x04, 0x1c, 0xbc, 0xb7, 0x4d, 0x86,
+ 0x04, 0x69, 0x9a, 0x61, 0xf2, 0x87, 0x04, 0x4b, 0x65, 0xe3, 0xf0, 0x90,
+ 0x04, 0x24, 0x86, 0xc3, 0x5f, 0x91, 0x04, 0x6d, 0xe2, 0xbc, 0xf2, 0x92,
+ 0x04, 0x38, 0xc0, 0x92, 0x3d, 0x93, 0x04, 0x08, 0x3c, 0xbf, 0x2a
};
BOOST_REQUIRE_EQUAL_COLLECTIONS(expected, expected + sizeof(expected),
wire.begin(), wire.end());