Implement writeElementStartDTag, writeBlobDTagElement, etc.
diff --git a/ndn-cpp/c/encoding/BinaryXMLEncoder.c b/ndn-cpp/c/encoding/BinaryXMLEncoder.c
index c70a44a..c8a55f5 100644
--- a/ndn-cpp/c/encoding/BinaryXMLEncoder.c
+++ b/ndn-cpp/c/encoding/BinaryXMLEncoder.c
@@ -4,6 +4,7 @@
* BSD license, See the LICENSE file for more information.
*/
+#include "../util/ndn_memory.h"
#include "BinaryXML.h"
#include "BinaryXMLEncoder.h"
@@ -14,6 +15,26 @@
};
/**
+ * Call ndn_DynamicUCharArray_ensureLength to ensure that there is enough room in the output, and copy
+ * array to the output. This does not write a header.
+ * @param self pointer to the ndn_BinaryXMLEncoder struct
+ * @param array the array to copy
+ * @param arrayLength the length of the array
+ * @return 0 for success, else an error string
+ */
+static char *writeArray(struct ndn_BinaryXMLEncoder *self, unsigned char *array, unsigned int arrayLength)
+{
+ char *error;
+ if (error = ndn_DynamicUCharArray_ensureLength(&self->output, self->offset + arrayLength))
+ return error;
+
+ ndn_memcpy(self->output.array + self->offset, array, arrayLength);
+ self->offset += arrayLength;
+
+ return 0;
+}
+
+/**
* Return the number of bytes to encode a header of value x.
*/
static unsigned int getNEncodingBytes(unsigned int x)
@@ -72,3 +93,42 @@
return 0;
}
+
+char *ndn_BinaryXMLEncoder_writeElementClose(struct ndn_BinaryXMLEncoder *self)
+{
+ char *error;
+ if (error = ndn_DynamicUCharArray_ensureLength(&self->output, self->offset + 1))
+ return error;
+
+ self->output.array[self->offset] = ndn_BinaryXML_CLOSE;
+ self->offset += 1;
+
+ return 0;
+}
+
+char *ndn_BinaryXMLEncoder_writeBlob(struct ndn_BinaryXMLEncoder *self, unsigned char *value, unsigned int valueLength)
+{
+ char *error;
+ if (error = ndn_BinaryXMLEncoder_encodeTypeAndValue(self, ndn_BinaryXML_BLOB, valueLength))
+ return error;
+
+ if (error = writeArray(self, value, valueLength))
+ return error;
+
+ return 0;
+}
+
+char *ndn_BinaryXMLEncoder_writeBlobDTagElement(struct ndn_BinaryXMLEncoder *self, unsigned int tag, unsigned char *value, unsigned int valueLength)
+{
+ char *error;
+ if (error = ndn_BinaryXMLEncoder_writeElementStartDTag(self, tag))
+ return error;
+
+ if (error = ndn_BinaryXMLEncoder_writeBlob(self, value, valueLength))
+ return error;
+
+ if (error = ndn_BinaryXMLEncoder_writeElementClose(self))
+ return error;
+
+ return 0;
+}