addByteData method
Adds all the sourceData
to the internal buffer. The data must conform
to the internal format, i.e. the number of bytes must be sufficient to
represent completely a certain number of elements, otherwise an exception
will be thrown.
Implementation
void addByteData(ByteData sourceData) {
// Make sure that the data we receive is well formed.
if (sourceData.lengthInBytes % elementSizeInBytes != 0) {
throw Exception(
'Provided number of bytes ${sourceData.lengthInBytes} not divisible by bytes per element $elementSizeInBytes.');
}
// Allocate sufficient space for the new elements.
final newElements = sourceData.lengthInBytes ~/ elementSizeInBytes;
capacity = max(capacity, length + newElements);
// Copy the data over.
final targetByte = _elementNrToByteOffset(length);
final sourceBytes = sourceData.buffer
.asUint8List(sourceData.offsetInBytes, sourceData.lengthInBytes);
_rawData.buffer.asUint8List().setRange(
targetByte, targetByte + sourceData.lengthInBytes, sourceBytes);
// Update the number of elements.
_elementsCount += newElements;
}