2024-03-11 18:42:48 +01:00
|
|
|
import 'dart:collection';
|
|
|
|
import 'dart:ffi';
|
|
|
|
import 'dart:io';
|
2024-03-12 19:53:16 +01:00
|
|
|
import 'dart:typed_data';
|
2024-03-11 18:42:48 +01:00
|
|
|
import "package:ffi/ffi.dart";
|
|
|
|
|
2024-03-12 19:53:16 +01:00
|
|
|
class LengthPointer<T extends NativeType> {
|
|
|
|
final Pointer<T> ptr;
|
|
|
|
final int length;
|
|
|
|
LengthPointer(this.ptr, this.length);
|
|
|
|
}
|
2024-03-11 18:42:48 +01:00
|
|
|
|
2024-03-12 19:53:16 +01:00
|
|
|
Pointer<Uint8> uint8ListToPointer(Uint8List data) {
|
|
|
|
final Pointer<Uint8> ptr = malloc<Uint8>(data.length);
|
|
|
|
for (int i = 0; i < data.length; ++i) {
|
|
|
|
ptr[i] = data[i];
|
2024-03-11 18:42:48 +01:00
|
|
|
}
|
2024-03-12 19:53:16 +01:00
|
|
|
return ptr;
|
2024-03-11 18:42:48 +01:00
|
|
|
}
|
|
|
|
|
2024-03-12 19:53:16 +01:00
|
|
|
LengthPointer<Uint8> readUint8Ptr(File file) {
|
|
|
|
final fileData = file.readAsBytesSync();
|
|
|
|
final data = uint8ListToPointer(fileData);
|
|
|
|
return LengthPointer<Uint8>(data, fileData.length);
|
2024-03-11 18:42:48 +01:00
|
|
|
}
|