callGoFunc<TResponse extends GeneratedMessage> function
Future<TResponse>
callGoFunc<TResponse extends GeneratedMessage>({
- required GeneratedMessage request,
- required void goFunc(
- int port,
- Pointer<
UnsignedChar> buffer, - int size
- required TResponse responseToFill,
- 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();
}
}