copyTo method
Implementation
Object copyTo(Object dst) {
int size = tfliteBinding.TfLiteTensorByteSize(_tensor);
final ptr = calloc<Uint8>(size);
checkState(isNotNull(ptr), message: 'unallocated');
final externalTypedData = ptr.asTypedList(size);
checkState(
tfliteBinding.TfLiteTensorCopyToBuffer(_tensor, ptr.cast(), size) ==
TfLiteStatus.kTfLiteOk);
// Clone the data, because once `free(ptr)`, `externalTypedData` will be
// volatile
final bytes = externalTypedData.sublist(0);
data = bytes;
late Object obj;
if (dst is Uint8List) {
obj = bytes;
} else if (dst is ByteBuffer) {
ByteData bdata = dst.asByteData();
for (int i = 0; i < bdata.lengthInBytes; i++) {
bdata.setUint8(i, bytes[i]);
}
obj = bdata.buffer;
} else {
obj = _convertBytesToObject(bytes);
}
calloc.free(ptr);
if (obj is List && dst is List) {
_duplicateList(obj, dst);
} else {
dst = obj;
}
return obj;
}