test lib at c level.

This commit is contained in:
Jordan
2024-03-11 18:09:11 -07:00
parent 29483913d6
commit 330c72acbb
12 changed files with 236 additions and 23 deletions

View File

@ -15,14 +15,23 @@ class Uint8FlexList extends ListBase<Uint8> {
set list(List<Uint8> l) {
_list.removeWhere((element) => true);
_list.addAll(l);
Pointer<Uint8> p = pointer;
pointer = calloc<Uint8>(l.length);
_list.forEach((element) {
pointer[_list.indexOf(element)] = element as int;
});
for (int i = 0; i < _list.length; ++i) {
pointer[i] = _list[i] as int;
}
calloc.free(p);
}
@override
void operator []=(int index, Uint8 value) {
if (index > _list.length) {
// resize the pointer
pointer = calloc<Uint8>(index - 1);
for (int i = 0; i < _list.length; ++i) {
pointer[i] = _list[i] as int;
}
}
_list[index] = value;
pointer[index] = value as int;
}
@ -37,14 +46,11 @@ class Uint8FlexList extends ListBase<Uint8> {
static fromList(List<Uint8> l) {
final l2 = Uint8FlexList();
l2.list = l;
return l2;
}
}
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;
Uint8FlexList readUint8Ptr(File file) {
return Uint8FlexList.fromList(file.readAsBytesSync().cast());
}