Added support for ContentObject
diff --git a/ndn-cpp/encoding/BinaryXMLWireFormat.cpp b/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
index f3af9c8..83261de 100644
--- a/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
+++ b/ndn-cpp/encoding/BinaryXMLWireFormat.cpp
@@ -6,7 +6,9 @@
#include <stdexcept>
#include "../c/encoding/BinaryXMLName.h"
#include "../c/encoding/BinaryXMLInterest.h"
+#include "../c/encoding/BinaryXMLContentObject.h"
#include "../Interest.hpp"
+#include "../ContentObject.hpp"
#include "BinaryXMLEncoder.hpp"
#include "../c/encoding/BinaryXMLDecoder.h"
#include "BinaryXMLWireFormat.hpp"
@@ -81,4 +83,35 @@
interest.set(interestStruct);
}
+void BinaryXMLWireFormat::encodeContentObject(const ContentObject &contentObject, vector<unsigned char> &output)
+{
+ struct ndn_NameComponent nameComponents[100];
+ struct ndn_ContentObject contentObjectStruct;
+ ndn_ContentObject_init
+ (&contentObjectStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]));
+ contentObject.get(contentObjectStruct);
+
+ BinaryXMLEncoder encoder;
+ ndn_encodeBinaryXMLContentObject(&contentObjectStruct, encoder.getEncoder());
+
+ encoder.appendTo(output);
+}
+
+void BinaryXMLWireFormat::decodeContentObject(ContentObject &contentObject, const unsigned char *input, unsigned int inputLength)
+{
+ struct ndn_NameComponent nameComponents[100];
+ struct ndn_ContentObject contentObjectStruct;
+ ndn_ContentObject_init
+ (&contentObjectStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]));
+
+ struct ndn_BinaryXMLDecoder decoder;
+ ndn_BinaryXMLDecoder_init(&decoder, (unsigned char *)input, inputLength);
+
+ ndn_Error error;
+ if (error = ndn_decodeBinaryXMLContentObject(&contentObjectStruct, &decoder))
+ throw std::runtime_error(ndn_getErrorString(error));
+
+ contentObject.set(contentObjectStruct);
+}
+
}
diff --git a/ndn-cpp/encoding/BinaryXMLWireFormat.hpp b/ndn-cpp/encoding/BinaryXMLWireFormat.hpp
index ad3a88c..a1a5e6a 100644
--- a/ndn-cpp/encoding/BinaryXMLWireFormat.hpp
+++ b/ndn-cpp/encoding/BinaryXMLWireFormat.hpp
@@ -17,6 +17,9 @@
virtual void encodeInterest(const Interest &interest, std::vector<unsigned char> &output);
virtual void decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength);
+
+ virtual void encodeContentObject(const ContentObject &contentObject, std::vector<unsigned char> &output);
+ virtual void decodeContentObject(ContentObject &contentObject, const unsigned char *input, unsigned int inputLength);
static BinaryXMLWireFormat &instance() { return instance_; }
diff --git a/ndn-cpp/encoding/WireFormat.cpp b/ndn-cpp/encoding/WireFormat.cpp
index 3217fe1..7e784a3 100644
--- a/ndn-cpp/encoding/WireFormat.cpp
+++ b/ndn-cpp/encoding/WireFormat.cpp
@@ -28,4 +28,13 @@
throw logic_error("unimplemented");
}
+void WireFormat::encodeContentObject(const ContentObject &contentObject, vector<unsigned char> &output)
+{
+ throw logic_error("unimplemented");
+}
+void WireFormat::decodeContentObject(ContentObject &contentObject, const unsigned char *input, unsigned int inputLength)
+{
+ throw logic_error("unimplemented");
+}
+
}
diff --git a/ndn-cpp/encoding/WireFormat.hpp b/ndn-cpp/encoding/WireFormat.hpp
index f09ae22..8458f94 100644
--- a/ndn-cpp/encoding/WireFormat.hpp
+++ b/ndn-cpp/encoding/WireFormat.hpp
@@ -12,6 +12,7 @@
class Name;
class Interest;
+class ContentObject;
class WireFormat {
public:
@@ -21,7 +22,8 @@
virtual void encodeInterest(const Interest &interest, std::vector<unsigned char> &output);
virtual void decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength);
- // etc. for each type of object.
+ virtual void encodeContentObject(const ContentObject &contentObject, std::vector<unsigned char> &output);
+ virtual void decodeContentObject(ContentObject &contentObject, const unsigned char *input, unsigned int inputLength);
};
}