outgoingHandler method

void outgoingHandler(
  1. List<int> data
)

Implementation

void outgoingHandler(List<int> data) async {
  outgoingSubscription.pause();
  log('bicronet_grpc: outgoingStream waiting for isWriteStreamReady: ${isWriteStreamReady.isCompleted}');
  await isWriteStreamReady.future;
  log('bicronet_grpc: got isWriteStreamReady');
  isWriteStreamReady = Completer<bool>();
  outgoingSubscription.resume();
  final framedData = grpc.frame(data, _compressionCodec);
  log('bicronet_grpc: data: $data -> framedData: $framedData');

  ffi.Pointer<ffi.Char> buffer = calloc(framedData.length);
  log('bicronet_grpc: sending buffer: $buffer');
  try {
    buffer
        .cast<ffi.Int8>()
        .asTypedList(framedData.length)
        .setAll(0, framedData);

    ffilibGrpcSupport.bidirectional_stream_write(
        stream.cast<grpc_support.bidirectional_stream>(),
        buffer,
        framedData.length,
        /*end_of_stream=*/ false);
  } catch (e) {
    // on a success, buffer will be freed in on_write_completed
    calloc.free(buffer);
    rethrow;
  }
}