ffi_utils 0.1.1 copy "ffi_utils: ^0.1.1" to clipboard
ffi_utils: ^0.1.1 copied to clipboard

outdated

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

Publisher

unverified uploader

FFI Utils

Repository (GitLab)
View/report issues

License

unknown (LICENSE)

Dependencies

ffi

More

Packages that depend on ffi_utils