import 'dart:ffi'; import 'package:ffi/ffi.dart'; import '../dylib.dart'; class Error implements Exception { final String message; Error(this.message); @override String toString() => 'Error: ${message}'; } class Result extends Struct { Pointer message; Pointer payload; Pointer unpack() { if (message.address != 0) { // TODO: the message leaks here throw Error(Utf8.fromUtf8(message)); } return Pointer.fromAddress(payload.address); } } final void Function(Pointer) freeResult = dylib.lookup< NativeFunction)> >('free_result').asFunction();