In BinaryXMLElementReader, add a DynamicUCharArray to handle partial data
diff --git a/ndn-cpp/c/encoding/BinaryXMLElementReader.c b/ndn-cpp/c/encoding/BinaryXMLElementReader.c
index 9561026..169db20 100644
--- a/ndn-cpp/c/encoding/BinaryXMLElementReader.c
+++ b/ndn-cpp/c/encoding/BinaryXMLElementReader.c
@@ -21,9 +21,20 @@
#if 0 // TODO: implement saving data parts.
this.dataParts.push(data.subarray(0, this.structureDecoder.offset));
var element = DataUtils.concatArrays(this.dataParts);
- this.dataParts = [];
#endif
- (*self->elementListener->onReceivedElement)(self->elementListener, data, self->structureDecoder.offset);
+ if (self->usePartialData) {
+ // We have partial data from a previous call, so append this data and point to partialData.
+ if (error = ndn_DynamicUCharArray_set(&self->partialData, data, self->structureDecoder.offset, self->partialDataLength))
+ return error;
+ self->partialDataLength += dataLength;
+
+ (*self->elementListener->onReceivedElement)(self->elementListener, self->partialData.array, self->partialDataLength);
+ // Assume we don't need to use partialData anymore until needed.
+ self->usePartialData = 0;
+ }
+ else
+ // We are not using partialData, so just point to the input data buffer.
+ (*self->elementListener->onReceivedElement)(self->elementListener, data, self->structureDecoder.offset);
// Need to read a new object.
data += self->structureDecoder.offset;
@@ -36,12 +47,16 @@
// else loop back to decode.
}
else {
-#if 0 // TODO: implement saving data parts.
- // Save for a later call to concatArrays so that we only copy data once.
- this.dataParts.push(data);
-#else
- return -1; // TODO: implement saving data parts.
-#endif
+ // Save remaining data for a later call.
+ if (!self->usePartialData) {
+ self->usePartialData = 1;
+ self->partialDataLength = 0;
+ }
+
+ if (error = ndn_DynamicUCharArray_set(&self->partialData, data, dataLength, self->partialDataLength))
+ return error;
+ self->partialDataLength += dataLength;
+
return 0;
}
}