ffi_utils 0.4.0+1 copy "ffi_utils: ^0.4.0+1" to clipboard
ffi_utils: ^0.4.0+1 copied to clipboard

FFI Utils

example/example.dart

import 'dart:ffi';
import 'dart:typed_data';
import 'package:ffi_utils/ffi_utils.dart';

void main() {
  var nativeString = NativeString.fromString('test');
  assert(nativeString.toDartString() == '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]));

  buffer = NativeBuffer.fromTyped(Uint8List.fromList([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.length == b.length &&
      a.every((e) {
        i++;
        return e == b[i];
      });
}
1
likes
90
pub points
50%
popularity

Publisher

unverified uploader

FFI Utils

Repository (GitLab)
View/report issues

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

ffi

More

Packages that depend on ffi_utils