Added support for ForwardingEntry.
diff --git a/ndn-cpp/encoding/binary-xml-wire-format.cpp b/ndn-cpp/encoding/binary-xml-wire-format.cpp
index 8cb5643..950d653 100644
--- a/ndn-cpp/encoding/binary-xml-wire-format.cpp
+++ b/ndn-cpp/encoding/binary-xml-wire-format.cpp
@@ -6,8 +6,10 @@
#include <stdexcept>
#include "../c/encoding/binary-xml-interest.h"
#include "../c/encoding/binary-xml-data.h"
+#include "../c/encoding/binary-xml-forwarding-entry.h"
#include "../interest.hpp"
#include "../data.hpp"
+#include "../forwarding-entry.hpp"
#include "binary-xml-encoder.hpp"
#include "binary-xml-decoder.hpp"
#include "binary-xml-wire-format.hpp"
@@ -94,4 +96,35 @@
data.set(dataStruct);
}
+ptr_lib::shared_ptr<vector<unsigned char> > BinaryXmlWireFormat::encodeForwardingEntry(const ForwardingEntry &forwardingEntry)
+{
+ struct ndn_NameComponent prefixNameComponents[100];
+ struct ndn_ForwardingEntry forwardingEntryStruct;
+ ndn_ForwardingEntry_init
+ (&forwardingEntryStruct, prefixNameComponents, sizeof(prefixNameComponents) / sizeof(prefixNameComponents[0]));
+ forwardingEntry.get(forwardingEntryStruct);
+
+ BinaryXmlEncoder encoder;
+ ndn_Error error;
+ if ((error = ndn_encodeBinaryXmlForwardingEntry(&forwardingEntryStruct, &encoder)))
+ throw std::runtime_error(ndn_getErrorString(error));
+
+ return encoder.getOutput();
+}
+
+void BinaryXmlWireFormat::decodeForwardingEntry(ForwardingEntry &forwardingEntry, const unsigned char *input, unsigned int inputLength)
+{
+ struct ndn_NameComponent prefixNameComponents[100];
+ struct ndn_ForwardingEntry forwardingEntryStruct;
+ ndn_ForwardingEntry_init
+ (&forwardingEntryStruct, prefixNameComponents, sizeof(prefixNameComponents) / sizeof(prefixNameComponents[0]));
+
+ BinaryXmlDecoder decoder(input, inputLength);
+ ndn_Error error;
+ if ((error = ndn_decodeBinaryXmlForwardingEntry(&forwardingEntryStruct, &decoder)))
+ throw std::runtime_error(ndn_getErrorString(error));
+
+ forwardingEntry.set(forwardingEntryStruct);
+}
+
}
diff --git a/ndn-cpp/encoding/binary-xml-wire-format.hpp b/ndn-cpp/encoding/binary-xml-wire-format.hpp
index 7266957..68be550 100644
--- a/ndn-cpp/encoding/binary-xml-wire-format.hpp
+++ b/ndn-cpp/encoding/binary-xml-wire-format.hpp
@@ -16,7 +16,19 @@
*/
class BinaryXmlWireFormat : public WireFormat {
public:
+ /**
+ * Encode interest in binary XML and return the encoding.
+ * @param interest The Interest object to encode.
+ * @return A shared_ptr with the vector<unsigned char> containing the encoding.
+ */
virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeInterest(const Interest &interest);
+
+ /**
+ * Decode input as an interest in binary XML and set the fields of the interest object.
+ * @param interest The Interest object whose fields are updated.
+ * @param input A pointer to the input buffer to decode.
+ * @param inputLength The number of bytes in input.
+ */
virtual void decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength);
/**
@@ -45,6 +57,21 @@
*/
virtual void decodeData
(Data &data, const unsigned char *input, unsigned int inputLength, unsigned int *signedFieldsBeginOffset, unsigned int *signedFieldsEndOffset);
+
+ /**
+ * Encode forwardingEntry in binary XML and return the encoding.
+ * @param forwardingEntry The ForwardingEntry object to encode.
+ * @return A shared_ptr with the vector<unsigned char> containing the encoding.
+ */
+ virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeForwardingEntry(const ForwardingEntry &forwardingEntry);
+
+ /**
+ * Decode input as a forwarding entry in binary XML and set the fields of the forwardingEntry object.
+ * @param forwardingEntry The ForwardingEntry object whose fields are updated.
+ * @param input A pointer to the input buffer to decode.
+ * @param inputLength The number of bytes in input.
+ */
+ virtual void decodeForwardingEntry(ForwardingEntry &forwardingEntry, const unsigned char *input, unsigned int inputLength);
};
}
diff --git a/ndn-cpp/encoding/wire-format.cpp b/ndn-cpp/encoding/wire-format.cpp
index 703795a..036262d 100644
--- a/ndn-cpp/encoding/wire-format.cpp
+++ b/ndn-cpp/encoding/wire-format.cpp
@@ -46,4 +46,13 @@
throw logic_error("unimplemented");
}
+ptr_lib::shared_ptr<vector<unsigned char> > WireFormat::encodeForwardingEntry(const ForwardingEntry &forwardingEntry)
+{
+ throw logic_error("unimplemented");
+}
+void WireFormat::decodeForwardingEntry(ForwardingEntry &forwardingEntry, const unsigned char *input, unsigned int inputLength)
+{
+ throw logic_error("unimplemented");
+}
+
}
diff --git a/ndn-cpp/encoding/wire-format.hpp b/ndn-cpp/encoding/wire-format.hpp
index 939c00c..bfd1a1d 100644
--- a/ndn-cpp/encoding/wire-format.hpp
+++ b/ndn-cpp/encoding/wire-format.hpp
@@ -13,10 +13,25 @@
class Interest;
class Data;
+class ForwardingEntry;
class WireFormat {
public:
+ /**
+ * Encode interest and return the encoding. Your derived class should override.
+ * @param interest The Interest object to encode.
+ * @return A shared_ptr with the vector<unsigned char> containing the encoding.
+ * @throw logic_error for unimplemented if the derived class does not override.
+ */
virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeInterest(const Interest &interest);
+
+ /**
+ * Decode input as an interest and set the fields of the interest object. Your derived class should override.
+ * @param interest The Interest object whose fields are updated.
+ * @param input A pointer to the input buffer to decode.
+ * @param inputLength The number of bytes in input.
+ * @throw logic_error for unimplemented if the derived class does not override.
+ */
virtual void decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength);
/**
@@ -67,6 +82,23 @@
}
/**
+ * Encode forwardingEntry and return the encoding. Your derived class should override.
+ * @param forwardingEntry The ForwardingEntry object to encode.
+ * @return A shared_ptr with the vector<unsigned char> containing the encoding.
+ * @throw logic_error for unimplemented if the derived class does not override.
+ */
+ virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeForwardingEntry(const ForwardingEntry &forwardingEntry);
+
+ /**
+ * Decode input as a forwarding entry and set the fields of the forwardingEntry object. Your derived class should override.
+ * @param forwardingEntry The ForwardingEntry object whose fields are updated.
+ * @param input A pointer to the input buffer to decode.
+ * @param inputLength The number of bytes in input.
+ * @throw logic_error for unimplemented if the derived class does not override.
+ */
+ virtual void decodeForwardingEntry(ForwardingEntry &forwardingEntry, const unsigned char *input, unsigned int inputLength);
+
+ /**
* Set the static default WireFormat used by default encoding and decoding methods.
* @param wireFormat A Pointer to an object of a subclass of WireFormat. This does not make a copy and
* the caller must ensure that the object remains allocated.