callGoFunc<TResponse extends GeneratedMessage> function

Future<TResponse> callGoFunc<TResponse extends GeneratedMessage>({
  1. required GeneratedMessage request,
  2. required void goFunc(
    1. int port,
    2. Pointer<UnsignedChar> buffer,
    3. int size
    ),
  3. required TResponse responseToFill,
  4. List<GeneratedMessage>? errorsToThrow,
})

Implementation

Future<TResponse> callGoFunc<TResponse extends GeneratedMessage>({
  required GeneratedMessage request,
  required void Function(int port, Pointer<UnsignedChar> buffer, int size)
      goFunc,
  required TResponse responseToFill,
  List<GeneratedMessage>? errorsToThrow,
}) async {
  final c = Completer<Uint8List>();
  final receivePort = createReceivePort(c);

  try {
    _doCall(request, goFunc, receivePort);
    final receivedBytes = await c.future;

    final msg = _getResponseMessage(receivedBytes);

    _throwOnError(errorsToThrow, msg);

    if (msg.canUnpackInto(responseToFill)) {
      msg.unpackInto(responseToFill);
      return responseToFill;
    }
    throw UnsupportedError('Type of response content not supported');
  } finally {
    receivePort.close();
  }
}