Added bigEndianToUnsignedInt
diff --git a/ndn-cpp/c/encoding/BinaryXMLDecoder.c b/ndn-cpp/c/encoding/BinaryXMLDecoder.c
index 8f74ced..556fcfd 100644
--- a/ndn-cpp/c/encoding/BinaryXMLDecoder.c
+++ b/ndn-cpp/c/encoding/BinaryXMLDecoder.c
@@ -216,7 +216,7 @@
return error;
if (!gotExpectedTag) {
- value = -1;
+ *value = -1;
return 0;
}
@@ -227,3 +227,16 @@
*value = (int)unsignedValue;
return 0;
}
+
+// TODO: This could be in a more central source file.
+unsigned int ndn_BinaryXMLDecoder_bigEndianToUnsignedInt(unsigned char *bytes, unsigned int bytesLength)
+{
+ unsigned int result = 0;
+ unsigned int i;
+ for (i = 0; i < bytesLength; ++i) {
+ result <<= 8;
+ result += (unsigned int)bytes[i];
+ }
+
+ return result;
+}
diff --git a/ndn-cpp/c/encoding/BinaryXMLDecoder.h b/ndn-cpp/c/encoding/BinaryXMLDecoder.h
index 0c70c0b..120613c 100644
--- a/ndn-cpp/c/encoding/BinaryXMLDecoder.h
+++ b/ndn-cpp/c/encoding/BinaryXMLDecoder.h
@@ -116,6 +116,14 @@
(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag, int *value);
/**
+ * Convert the big endian bytes to an unsigned int. Don't check for overflow.
+ * @param bytes pointer to the array of bytes
+ * @param bytesLength the length of bytes
+ * @return the result unsigned int
+ */
+unsigned int ndn_BinaryXMLDecoder_bigEndianToUnsignedInt(unsigned char *bytes, unsigned int bytesLength);
+
+/**
* Set the offset into the input, used for the next read.
* @param self pointer to the ndn_BinaryXMLDecoder struct
* @param offset the new offset