ffi_utils 0.1.1 ffi_utils: ^0.1.1 copied to clipboard
FFI Utils
import 'dart:ffi';
import 'package:ffi_utils/ffi_utils.dart';
void main() {
var nativeString = NativeString.fromString('test');
assert(nativeString.ref.toString() == 'test', nativeString.toString());
var bytes = nativeString.cast<Uint8>().asTypedList(5).toList();
assert(_eq(bytes, [116, 101, 115, 116, 0]));
var buffer = NativeBuffer.fromBytes([116, 101, 115, 116, 0]);
bytes = buffer.cast<Uint8>().asTypedList(5).toList();
assert(_eq(bytes, [116, 101, 115, 116, 0]));
var string = NativeString.fromPointer(buffer);
assert(string == 'test');
}
bool _eq(List a, List b){
int i = -1;
return a != null && b != null && a.length == b.length &&
a.every((e) { i++; return e == b[i];});
}