In WireFormat encodeData and decodeData, added args for signedFieldsBeginOffset and signedFieldsEndOffset.
diff --git a/ndn-cpp/c/encoding/binary-xml-data.h b/ndn-cpp/c/encoding/binary-xml-data.h
index 1cc6efb..3e4747e 100644
--- a/ndn-cpp/c/encoding/binary-xml-data.h
+++ b/ndn-cpp/c/encoding/binary-xml-data.h
@@ -17,7 +17,7 @@
/**
* Encode the data packet as binary XML.
- * @param data Pointer to the data object the encode.
+ * @param data Pointer to the data object to encode.
* @param signedFieldsBeginOffset Return the offset in the encoding of the beginning of the fields which are signed.
* If you are not encoding in order to sign, you can ignore this returned value.
* @param signedFieldsEndOffset Return the offset in the encoding of the end of the fields which are signed.
@@ -29,8 +29,8 @@
(struct ndn_Data *data, unsigned int *signedFieldsBeginOffset, unsigned int *signedFieldsEndOffset, struct ndn_BinaryXmlEncoder *encoder);
/**
- * Decode the data packet as binary XML.
- * @param data Pointer to the data object the decode.
+ * Decode the data packet as binary XML and set the fields in the data object.
+ * @param data Pointer to the data object whose fields are updated.
* @param signedFieldsBeginOffset Return the offset in the input buffer of the beginning of the fields which are signed.
* If you are not decoding in order to verify, you can ignore this returned value.
* @param signedFieldsEndOffset Return the offset in the input buffer of the end of the fields which are signed.
diff --git a/ndn-cpp/encoding/binary-xml-wire-format.cpp b/ndn-cpp/encoding/binary-xml-wire-format.cpp
index 43e09bc..574a374 100644
--- a/ndn-cpp/encoding/binary-xml-wire-format.cpp
+++ b/ndn-cpp/encoding/binary-xml-wire-format.cpp
@@ -57,7 +57,8 @@
interest.set(interestStruct);
}
-ptr_lib::shared_ptr<vector<unsigned char> > BinaryXmlWireFormat::encodeData(const Data &data)
+ptr_lib::shared_ptr<vector<unsigned char> > BinaryXmlWireFormat::encodeData
+ (const Data &data, unsigned int *signedFieldsBeginOffset, unsigned int *signedFieldsEndOffset)
{
struct ndn_NameComponent nameComponents[100];
struct ndn_Data dataStruct;
@@ -66,15 +67,15 @@
data.get(dataStruct);
BinaryXmlEncoder encoder;
- unsigned int dummyBeginOffset, dummyEndOffset;
ndn_Error error;
- if ((error = ndn_encodeBinaryXmlData(&dataStruct, &dummyBeginOffset, &dummyEndOffset, &encoder)))
+ if ((error = ndn_encodeBinaryXmlData(&dataStruct, signedFieldsBeginOffset, signedFieldsEndOffset, &encoder)))
throw std::runtime_error(ndn_getErrorString(error));
return encoder.getOutput();
}
-void BinaryXmlWireFormat::decodeData(Data &data, const unsigned char *input, unsigned int inputLength)
+void BinaryXmlWireFormat::decodeData
+ (Data &data, const unsigned char *input, unsigned int inputLength, unsigned int *signedFieldsBeginOffset, unsigned int *signedFieldsEndOffset)
{
struct ndn_NameComponent nameComponents[100];
struct ndn_Data dataStruct;
@@ -82,9 +83,8 @@
(&dataStruct, nameComponents, sizeof(nameComponents) / sizeof(nameComponents[0]));
BinaryXmlDecoder decoder(input, inputLength);
- unsigned int dummyBeginOffset, dummyEndOffset;
ndn_Error error;
- if ((error = ndn_decodeBinaryXmlData(&dataStruct, &dummyBeginOffset, &dummyEndOffset, &decoder)))
+ if ((error = ndn_decodeBinaryXmlData(&dataStruct, signedFieldsBeginOffset, signedFieldsEndOffset, &decoder)))
throw std::runtime_error(ndn_getErrorString(error));
data.set(dataStruct);
diff --git a/ndn-cpp/encoding/binary-xml-wire-format.hpp b/ndn-cpp/encoding/binary-xml-wire-format.hpp
index c327d17..7266957 100644
--- a/ndn-cpp/encoding/binary-xml-wire-format.hpp
+++ b/ndn-cpp/encoding/binary-xml-wire-format.hpp
@@ -10,13 +10,41 @@
namespace ndn {
+/**
+ * A BinaryXmlWireFormat extends WireFormat to override its virtual methods to implement encoding and decoding
+ * using binary XML.
+ */
class BinaryXmlWireFormat : public WireFormat {
public:
virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeInterest(const Interest &interest);
virtual void decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength);
- virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeData(const Data &data);
- virtual void decodeData(Data &data, const unsigned char *input, unsigned int inputLength);
+ /**
+ * Encode data with binary XML and return the encoding.
+ * @param data The Data object to encode.
+ * @param signedFieldsBeginOffset Return the offset in the encoding of the beginning of the fields which are signed.
+ * If you are not encoding in order to sign, you can call encodeData(const Data &data) to ignore this returned value.
+ * @param signedFieldsEndOffset Return the offset in the encoding of the end of the fields which are signed.
+ * If you are not encoding in order to sign, you can call encodeData(const Data &data) to ignore this returned value.
+ * @return A shared_ptr with the vector<unsigned char> containing the encoding.
+ */
+ virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeData
+ (const Data &data, unsigned int *signedFieldsBeginOffset, unsigned int *signedFieldsEndOffset);
+
+ /**
+ * Decode input as a data packet in binary XML and set the fields in the data object.
+ * @param data The Data object whose fields are updated.
+ * @param input A pointer to the input buffer to decode.
+ * @param inputLength The number of bytes in input.
+ * @param signedFieldsBeginOffset Return the offset in the input buffer of the beginning of the fields which are signed.
+ * If you are not decoding in order to verify, you can call
+ * decodeData(Data &data, const unsigned char *input, unsigned int inputLength) to ignore this returned value.
+ * @param signedFieldsEndOffset Return the offset in the input buffer of the end of the fields which are signed.
+ * If you are not decoding in order to verify, you can call
+ * decodeData(Data &data, const unsigned char *input, unsigned int inputLength) to ignore this returned value.
+ */
+ virtual void decodeData
+ (Data &data, const unsigned char *input, unsigned int inputLength, unsigned int *signedFieldsBeginOffset, unsigned int *signedFieldsEndOffset);
};
}
diff --git a/ndn-cpp/encoding/wire-format.cpp b/ndn-cpp/encoding/wire-format.cpp
index 60e3f19..703795a 100644
--- a/ndn-cpp/encoding/wire-format.cpp
+++ b/ndn-cpp/encoding/wire-format.cpp
@@ -35,11 +35,13 @@
throw logic_error("unimplemented");
}
-ptr_lib::shared_ptr<vector<unsigned char> > WireFormat::encodeData(const Data &data)
+ptr_lib::shared_ptr<vector<unsigned char> > WireFormat::encodeData
+ (const Data &data, unsigned int *signedFieldsBeginOffset, unsigned int *signedFieldsEndOffset)
{
throw logic_error("unimplemented");
}
-void WireFormat::decodeData(Data &data, const unsigned char *input, unsigned int inputLength)
+void WireFormat::decodeData
+ (Data &data, const unsigned char *input, unsigned int inputLength, unsigned int *signedFieldsBeginOffset, unsigned int *signedFieldsEndOffset)
{
throw logic_error("unimplemented");
}
diff --git a/ndn-cpp/encoding/wire-format.hpp b/ndn-cpp/encoding/wire-format.hpp
index c229131..e0ffdf0 100644
--- a/ndn-cpp/encoding/wire-format.hpp
+++ b/ndn-cpp/encoding/wire-format.hpp
@@ -19,8 +19,52 @@
virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeInterest(const Interest &interest);
virtual void decodeInterest(Interest &interest, const unsigned char *input, unsigned int inputLength);
- virtual ptr_lib::shared_ptr<std::vector<unsigned char> > encodeData(const Data &data);
- virtual void decodeData(Data &data, const unsigned char *input, unsigned int inputLength);
+ /**
+ * Encode data and return the encoding. Your derived class should override.
+ * @param data The Data object to encode.
+ * @param signedFieldsBeginOffset Return the offset in the encoding of the beginning of the fields which are signed.
+ * If you are not encoding in order to sign, you can call encodeData(const Data &data) to ignore this returned value.
+ * @param signedFieldsEndOffset Return the offset in the encoding of the end of the fields which are signed.
+ * If you are not encoding in order to sign, you can call encodeData(const Data &data) to ignore this returned value.
+ * @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> > encodeData
+ (const Data &data, unsigned int *signedFieldsBeginOffset, unsigned int *signedFieldsEndOffset);
+
+ /**
+ * Encode data and return the encoding.
+ * @param data The Data 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.
+ */
+ ptr_lib::shared_ptr<std::vector<unsigned char> > encodeData(const Data &data)
+ {
+ unsigned int dummyBeginOffset, dummyEndOffset;
+ return encodeData(data, &dummyBeginOffset, &dummyEndOffset);
+ }
+
+ /**
+ * Decode input as a data packet and set the fields in the data object. Your derived class should override.
+ * @param data The Data object whose fields are updated.
+ * @param input A pointer to the input buffer to decode.
+ * @param inputLength The number of bytes in input.
+ * @param signedFieldsBeginOffset Return the offset in the input buffer of the beginning of the fields which are signed.
+ * If you are not decoding in order to verify, you can call
+ * decodeData(Data &data, const unsigned char *input, unsigned int inputLength) to ignore this returned value.
+ * @param signedFieldsEndOffset Return the offset in the input buffer of the end of the fields which are signed.
+ * If you are not decoding in order to verify, you can call
+ * decodeData(Data &data, const unsigned char *input, unsigned int inputLength) to ignore this returned value.
+ * @throw logic_error for unimplemented if the derived class does not override.
+ */
+ virtual void decodeData
+ (Data &data, const unsigned char *input, unsigned int inputLength, unsigned int *signedFieldsBeginOffset, unsigned int *signedFieldsEndOffset);
+
+ void decodeData(Data &data, const unsigned char *input, unsigned int inputLength)
+ {
+ unsigned int dummyBeginOffset, dummyEndOffset;
+ decodeData(data, input, inputLength, &dummyBeginOffset, &dummyEndOffset);
+ }
/**
* Set the static default WireFormat used by default encoding and decoding methods.