ffi_utils 0.2.0
ffi_utils: ^0.2.0 copied to clipboard

FFI Utils

example/example.dart

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];});
}
0
likes
60
pub points
25%
popularity

Publisher

Unknown

FFI Utils

Repository (GitLab)
View/report issues

Documentation

API reference

License

Apache 2.0 (LICENSE)

Dependencies

ffi

More

Packages that depend on ffi_utils