call method

Future<Uint8List> call(
  1. String name,
  2. Uint8List payload
)

Implementation

Future<Uint8List> call(String name, Uint8List payload) async {
  final callable = _library
      .lookup<ffi.NativeFunction<call_func>>(_callFuncName)
      .asFunction<Call>();

  final pointer = malloc<ffi.Uint8>(payload.length);

  // https://github.com/dart-lang/ffi/issues/27
  // https://github.com/objectbox/objectbox-dart/issues/69
  for (var i = 0; i < payload.length; i++) {
    pointer[i] = payload[i];
  }
  final payloadPointer = pointer.cast<ffi.Void>();
  final namePointer = toUtf8(name);

  final result = callable(namePointer, payloadPointer, payload.length);

  malloc.free(namePointer);
  malloc.free(pointer);

  handleError(result.ref.error, result);

  final output =
      result.ref.message.cast<ffi.Uint8>().asTypedList(result.ref.size);
  freeResult(result);
  return output;
}