name: More changes related to TLV encoding/decoding implementation
Change-Id: Ib1d7b2e7fdc57ac96b0193858f13e6b3297013d5
diff --git a/src/name.cpp b/src/name.cpp
index 3d9b395..44e6039 100644
--- a/src/name.cpp
+++ b/src/name.cpp
@@ -49,7 +49,7 @@
return Component(value);
}
-Name::Component
+Name::Component
Name::Component::fromNumberWithMarker(uint64_t number, uint8_t marker)
{
ptr_lib::shared_ptr<Buffer> value(new Buffer);
@@ -332,4 +332,39 @@
return os;
}
+const Block &
+Name::wireEncode() const
+{
+ if (wire_.hasWire())
+ return wire_;
+
+ wire_ = Block(Tlv::Name);
+ for (Name::const_iterator i = begin(); i != end(); i++) {
+ OBufferStream os;
+ Tlv::writeVarNumber(os, Tlv::NameComponent);
+ Tlv::writeVarNumber(os, i->getValue().size());
+ os.write(reinterpret_cast<const char*>(i->getValue().buf()), i->getValue().size());
+
+ wire_.push_back(Block(os.buf()));
+ }
+
+ wire_.encode();
+ return wire_;
+}
+
+void
+Name::wireDecode(const Block &wire)
+{
+ wire_ = wire;
+ wire_.parse();
+
+ for (Block::element_const_iterator i = wire_.getAll().begin();
+ i != wire_.getAll().end();
+ ++i)
+ {
+ append(i->value(), i->value_size());
+ }
+}
+
+
}