bytesListToByteBuffer function
- Uint8List? bytesList
Converts a list of bytes to a NativeByteBuffer
.
Takes an optional Uint8List bytesList
and returns a Pointer to a NativeByteBuffer
.
Implementation
Pointer<NativeByteBuffer> bytesListToByteBuffer(Uint8List? bytesList) {
if (bytesList == null) {
return calloc<NativeByteBuffer>();
}
Pointer<Uint8> dataPointer = calloc<Uint8>(bytesList.length);
for (int i = 0; i < bytesList.length; i++) {
dataPointer[i] = bytesList[i];
}
Pointer<NativeByteBuffer> byteBufferPointer = calloc<NativeByteBuffer>();
byteBufferPointer.ref.len = bytesList.length;
byteBufferPointer.ref.data = dataPointer;
return byteBufferPointer;
}