model: Slight modification with wire format processing
Now it is possible to convert Name from/to wire format via ndn::Face
helper method (since Face is getting configured with specific wire
format)
Refs #1008 (http://redmine.named-data.net/issues/1008)
diff --git a/model/wire/ccnb/wire-ccnb.cc b/model/wire/ccnb/wire-ccnb.cc
index 4f4f695..9033d3f 100644
--- a/model/wire/ccnb/wire-ccnb.cc
+++ b/model/wire/ccnb/wire-ccnb.cc
@@ -23,6 +23,8 @@
#include <sstream>
#include <boost/foreach.hpp>
#include "ccnb-parser/common.h"
+#include "ccnb-parser/visitors/name-visitor.h"
+#include "ccnb-parser/syntax-tree/block.h"
NDN_NAMESPACE_BEGIN
@@ -99,29 +101,6 @@
}
size_t
-Ccnb::AppendName (Buffer::Iterator &start, const Name &name)
-{
- size_t written = 0;
- BOOST_FOREACH (const std::string &component, name.GetComponents())
- {
- written += AppendTaggedBlob (start, CcnbParser::CCN_DTAG_Component,
- reinterpret_cast<const uint8_t*>(component.c_str()), component.size());
- }
- return written;
-}
-
-size_t
-Ccnb::EstimateName (const Name &name)
-{
- size_t written = 0;
- BOOST_FOREACH (const std::string &component, name.GetComponents())
- {
- written += EstimateTaggedBlob (CcnbParser::CCN_DTAG_Component, component.size());
- }
- return written;
-}
-
-size_t
Ccnb::AppendTimestampBlob (Buffer::Iterator &start, const Time &time)
{
// the original function implements Markers... thought not sure what are these markers for...
@@ -208,6 +187,41 @@
return EstimateBlockHeader (dtag) + EstimateBlockHeader (string.size ()) + string.size () + 1;
}
+size_t
+Ccnb::SerializeName (Buffer::Iterator &start, const Name &name)
+{
+ size_t written = 0;
+ BOOST_FOREACH (const std::string &component, name.GetComponents())
+ {
+ written += AppendTaggedBlob (start, CcnbParser::CCN_DTAG_Component,
+ reinterpret_cast<const uint8_t*>(component.c_str()), component.size());
+ }
+ return written;
+}
+
+size_t
+Ccnb::SerializedSizeName (const Name &name)
+{
+ size_t written = 0;
+ BOOST_FOREACH (const std::string &component, name.GetComponents())
+ {
+ written += EstimateTaggedBlob (CcnbParser::CCN_DTAG_Component, component.size());
+ }
+ return written;
+}
+
+Ptr<Name>
+Ccnb::DeserializeName (Buffer::Iterator &i)
+{
+ Ptr<Name> name = Create<Name> ();
+ CcnbParser::NameVisitor nameVisitor;
+
+ Ptr<CcnbParser::Block> root = CcnbParser::Block::ParseBlock (i);
+ root->accept (nameVisitor, GetPointer (name));
+
+ return name;
+}
+
} // wire
NDN_NAMESPACE_END