51 lines
1.0 KiB
Dart
51 lines
1.0 KiB
Dart
import 'dart:collection';
|
|
import 'dart:ffi';
|
|
import 'dart:io';
|
|
import "package:ffi/ffi.dart";
|
|
|
|
class Uint8FlexList extends ListBase<Uint8> {
|
|
final List<Uint8> _list = [];
|
|
Uint8FlexList();
|
|
|
|
late Pointer<Uint8> pointer;
|
|
|
|
@override
|
|
Uint8 operator [](int index) => _list[index];
|
|
|
|
set list(List<Uint8> l) {
|
|
_list.removeWhere((element) => true);
|
|
_list.addAll(l);
|
|
pointer = calloc<Uint8>(l.length);
|
|
_list.forEach((element) {
|
|
pointer[_list.indexOf(element)] = element as int;
|
|
});
|
|
}
|
|
|
|
@override
|
|
void operator []=(int index, Uint8 value) {
|
|
_list[index] = value;
|
|
pointer[index] = value as int;
|
|
}
|
|
|
|
@override
|
|
int get length => _list.length;
|
|
|
|
@override
|
|
set length(int newLength) {
|
|
throw Error();
|
|
}
|
|
|
|
static fromList(List<Uint8> l) {
|
|
final l2 = Uint8FlexList();
|
|
}
|
|
}
|
|
|
|
Pointer<Uint8> readUint8Ptr(File file) {
|
|
final l = file.readAsBytesSync().cast();
|
|
final dataPointer = calloc<Uint8>(l.length);
|
|
for (int i = 0; i < l.length; ++i) {
|
|
dataPointer[i] = l[i];
|
|
}
|
|
return dataPointer;
|
|
}
|