BicronetEngine constructor

BicronetEngine(
  1. ChannelOptions _options,
  2. List<int>? _trustedCertificate
)

Implementation

BicronetEngine(this._options, this._trustedCertificate) {
  final dynamicLibraryCronet = openDynamicLibrary('cronet.104.0.5108.0');
  ffilibGrpcSupport = grpc_support.GrpcSupport(dynamicLibraryCronet);
  ffilibGrpcCronetBindings =
      GrpcCronetBindings(openDynamicLibrary('grpc_cronet'));
  ffilibGrpcCronetBindings.InitDartApiDL(ffi.NativeApi.initializeApiDLData);

  final certificateBufferLength =
      _trustedCertificate == null ? 0 : _trustedCertificate!.length;
  ffi.Pointer<ffi.UnsignedChar> certificateBuffer =
      calloc(certificateBufferLength);
  log('certificateBuffer: $certificateBuffer, ${calloc<ffi.UnsignedChar>(0)}');
  try {
    if (certificateBufferLength > 0) {
      certificateBuffer
          .cast<ffi.Int8>()
          .asTypedList(_trustedCertificate!.length)
          .setAll(0, _trustedCertificate!);
    }
    streamEngine = ffilibGrpcSupport.bidirectional_stream_engine_create(
        /*enable_quic=*/ true,
        /*quic_user_agent_id=*/ "my_quic_user_agent_id"
            .toNativeUtf8()
            .cast<ffi.Char>(),
        /*enable_spdy=*/ true,
        /*enable_brotli=*/ true,
        /*accept_language=*/ "en-us".toNativeUtf8().cast<ffi.Char>(),
        _options.userAgent.toNativeUtf8().cast<ffi.Char>(),
        certificateBuffer,
        certificateBufferLength);
  } finally {
    calloc.free(certificateBuffer);
  }
}