Debugging and resolving problems with interest serialization/deserialization
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.cc
index 8548598..d562695 100644
--- a/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.cc
+++ b/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.cc
@@ -35,13 +35,13 @@
// We don't really care about any other fields
void
-ContentObjectVisitor::visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader&*/)
+ContentObjectVisitor::visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader* */)
{
// uint32_t n.m_dtag;
// std::list<Ptr<Block> > n.m_nestedBlocks;
static NameComponentsVisitor nameComponentsVisitor;
- CcnxContentObjectHeader &contentObject = boost::any_cast<CcnxContentObjectHeader&> (param);
+ CcnxContentObjectHeader &contentObject = *(boost::any_cast<CcnxContentObjectHeader*> (param));
switch (n.m_dtag)
{
@@ -59,7 +59,7 @@
BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
{
- block->accept (nameComponentsVisitor, *name);
+ block->accept (nameComponentsVisitor, &(*name));
}
contentObject.SetName (name);
break;
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.h
index e15e290..ae6fe9b 100644
--- a/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.h
+++ b/helper/ccnb-parser/visitors/ccnb-parser-content-object-visitor.h
@@ -41,7 +41,7 @@
class ContentObjectVisitor : public VoidDepthFirstVisitor
{
public:
- virtual void visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader&*/);
+ virtual void visit (Dtag &n, boost::any param/*should be CcnxContentObjectHeader* */);
};
}
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.cc
index 052cb8c..0bd0e46 100644
--- a/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.cc
+++ b/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.cc
@@ -39,7 +39,7 @@
// We don't care about any other fields
void
-InterestVisitor::visit (Dtag &n, boost::any param/*should be CcnxInterestHeader&*/)
+InterestVisitor::visit (Dtag &n, boost::any param/*should be CcnxInterestHeader* */)
{
// uint32_t n.m_dtag;
// std::list<Ptr<Block> > n.m_nestedBlocks;
@@ -49,7 +49,7 @@
static TimestampVisitor timestampVisitor;
static NonceVisitor nonceVisitor;
- CcnxInterestHeader &interest = boost::any_cast<CcnxInterestHeader&> (param);
+ CcnxInterestHeader &interest = *(boost::any_cast<CcnxInterestHeader*> (param));
switch (n.m_dtag)
{
@@ -67,7 +67,7 @@
BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
{
- block->accept (nameComponentsVisitor, *name);
+ block->accept (nameComponentsVisitor, &(*name));
}
interest.SetName (name);
break;
@@ -97,7 +97,7 @@
BOOST_FOREACH (Ptr<Block> block, n.m_nestedTags)
{
- block->accept (nameComponentsVisitor, *exclude);
+ block->accept (nameComponentsVisitor, &(*exclude));
}
interest.SetExclude (exclude);
break;
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.h
index 136b173..35a1e13 100644
--- a/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.h
+++ b/helper/ccnb-parser/visitors/ccnb-parser-interest-visitor.h
@@ -41,7 +41,7 @@
class InterestVisitor : public VoidDepthFirstVisitor
{
public:
- virtual void visit (Dtag &n, boost::any param/*should be CcnxInterestHeader&*/);
+ virtual void visit (Dtag &n, boost::any param/*should be CcnxInterestHeader* */);
};
}
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.cc
index 08bfe2e..314cb68 100644
--- a/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.cc
+++ b/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.cc
@@ -28,13 +28,13 @@
namespace CcnbParser {
void
-NameComponentsVisitor::visit (Dtag &n, boost::any param/*should be CcnxNameComponents&*/)
+NameComponentsVisitor::visit (Dtag &n, boost::any param/*should be CcnxNameComponents* */)
{
// uint32_t n.m_dtag;
// std::list<Ptr<Block> > n.m_nestedBlocks;
static StringVisitor stringVisitor;
- CcnxNameComponents &components = boost::any_cast<CcnxNameComponents&> (param);
+ CcnxNameComponents &components = *(boost::any_cast<CcnxNameComponents*> (param));
switch (n.m_dtag)
{
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.h
index e4b92cf..70257c5 100644
--- a/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.h
+++ b/helper/ccnb-parser/visitors/ccnb-parser-name-components-visitor.h
@@ -33,7 +33,7 @@
class NameComponentsVisitor : public VoidDepthFirstVisitor
{
public:
- virtual void visit (Dtag &n, boost::any param/*should be CcnxNameComponents&*/);
+ virtual void visit (Dtag &n, boost::any param/*should be CcnxNameComponents* */);
};
}
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.cc
index 7492adf..931f2fa 100644
--- a/helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.cc
+++ b/helper/ccnb-parser/visitors/ccnb-parser-nonce-visitor.cc
@@ -28,10 +28,10 @@
NonceVisitor::visit (Blob &n)
{
// Buffer n.m_blob;
- if (n.m_blob.GetSize ()<4)
+ if (n.m_blobSize < 4)
throw CcnbDecodingException ();
- return boost::any (n.m_blob.Begin ().ReadU32 ());
+ return boost::any (*(reinterpret_cast<uint32_t*> (n.m_blob)));
}
boost::any
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-string-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-string-visitor.cc
index 33c9465..dfc61ed 100644
--- a/helper/ccnb-parser/visitors/ccnb-parser-string-visitor.cc
+++ b/helper/ccnb-parser/visitors/ccnb-parser-string-visitor.cc
@@ -20,6 +20,7 @@
#include "ccnb-parser-string-visitor.h"
#include "ns3/ccnb-parser-udata.h"
+#include "ns3/ccnb-parser-blob.h"
namespace ns3 {
namespace CcnbParser {
@@ -28,7 +29,7 @@
StringVisitor::visit (Blob &n)
{
// Buffer n.m_blob;
- throw CcnbDecodingException ();
+ return std::string (n.m_blob, n.m_blobSize);
}
boost::any
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-string-visitor.h b/helper/ccnb-parser/visitors/ccnb-parser-string-visitor.h
index b2a2a29..2a1e8ed 100644
--- a/helper/ccnb-parser/visitors/ccnb-parser-string-visitor.h
+++ b/helper/ccnb-parser/visitors/ccnb-parser-string-visitor.h
@@ -35,7 +35,7 @@
class StringVisitor : public NoArguDepthFirstVisitor
{
public:
- virtual boost::any visit (Blob &n); ///< Throws parsing error if BLOB object is encountered
+ virtual boost::any visit (Blob &n);
virtual boost::any visit (Udata &n);
};
diff --git a/helper/ccnb-parser/visitors/ccnb-parser-timestamp-visitor.cc b/helper/ccnb-parser/visitors/ccnb-parser-timestamp-visitor.cc
index 4724bb4..22965aa 100644
--- a/helper/ccnb-parser/visitors/ccnb-parser-timestamp-visitor.cc
+++ b/helper/ccnb-parser/visitors/ccnb-parser-timestamp-visitor.cc
@@ -30,26 +30,27 @@
TimestampVisitor::visit (Blob &n)
{
// Buffer n.m_blob;
- if (n.m_blob.GetSize ()<2)
+ if (n.m_blobSize < 2)
throw CcnbDecodingException ();
- Buffer::Iterator start = n.m_blob.Begin ();
+ const char *start = n.m_blob;
intmax_t seconds = 0;
intmax_t nanoseconds = 0;
- for (uint32_t i=0; i < n.m_blob.GetSize ()-2; i++)
+ for (uint32_t i=0; i < n.m_blobSize-2; i++)
{
- seconds = (seconds << 8) | start.ReadU8 ();
+ seconds = (seconds << 8) | (uint8_t)start[i];
}
- uint8_t combo = start.ReadU8 (); // 4 most significant bits hold 4 least significant bits of number of seconds
- seconds = (seconds << 8) | (combo >> 4);
+ uint8_t combo = start[n.m_blobSize-2]; // 4 most significant bits hold 4 least significant bits of number of seconds
+ seconds = (seconds << 4) | (combo >> 4);
+ std::cout << std::hex << (int) start[n.m_blobSize-2] << "\n";
nanoseconds = combo & 0x0F; /*00001111*/ // 4 least significant bits hold 4 most significant bits of number of
- nanoseconds = (nanoseconds << 8) | start.ReadU8 ();
- nanoseconds = (intmax_t) ((nanoseconds / 4096.0/*2^12*/) * 1000000000 /*up-convert nanoseconds*/);
+ nanoseconds = (nanoseconds << 8) | start[n.m_blobSize-1];
+ nanoseconds = (intmax_t) ((nanoseconds / 4096.0/*2^12*/) * 1000000 /*up-convert useconds*/);
- return boost::any (Time::FromInteger (seconds, Time::S) + Time::FromInteger (nanoseconds, Time::NS));
+ return boost::any (Time::FromInteger (seconds, Time::S) + Time::FromInteger (nanoseconds, Time::US));
}
boost::any