d-markey / squadron_builder

Dart code generator for Squadron workers. Implement your worker service and let squadron_builder bridge the gap with Web Workers and Isolates!
https://pub.dev/packages/squadron_builder
MIT License
15 stars 3 forks source link

[VM] Type '_Uint8ArrayView' is not a subtype of type 'ByteBuffer?' in type cast #22

Closed sabin26 closed 1 day ago

sabin26 commented 4 days ago

Code:

@SquadronMethod()
FutureOr<Uint8List?> toExcel(
    final List<int> bytes, {
    final String? columns,
  }) async {
   ...
}

Then I did the following:

  1. dart run build_runner clean
  2. dart run build_runner build

The build_runner step completes successfully but I get an error on runtime when calling the method only on VM Environment: Desktop (Windows). The method completes without error on Web platform (both JS/WASM)

Error

Type '_Uint8ArrayView' is not a subtype of type 'ByteBuffer?' in type cast

Generated Code:

// GENERATED CODE - DO NOT MODIFY BY HAND

part of 'export_service.dart';

// **************************************************************************
// Generator: WorkerGenerator 6.1.1
// **************************************************************************

/// WorkerService class for ExportService
class _$ExportServiceWorkerService extends ExportService
    implements WorkerService {
  _$ExportServiceWorkerService() : super();

  @override
  late final Map<int, CommandHandler> operations =
      Map.unmodifiable(<int, CommandHandler>{
    _$toCSVId: ($) async =>
        _$X.$impl.$sr3(await toCSV(_$X.$impl.$dsr1($.args[0]))),
    _$toExcelId: ($) async => _$X.$impl.$sr3(await toExcel(
        _$X.$impl.$dsr1($.args[0]),
        columns: _$X.$impl.$dsr6($.args[1]))),
    _$toPDFId: ($) async => _$X.$impl.$sr3(await toPDF(
        _$X.$impl.$dsr1($.args[0]),
        title: _$X.$impl.$dsr7($.args[1]),
        isLandscape: _$X.$impl.$dsr8($.args[2]),
        columns: _$X.$impl.$dsr6($.args[3]),
        columnWidths: _$X.$impl.$dsr11($.args[4]),
        fontData: _$X.$impl.$dsr13($.args[5]),
        titleFonts: _$X.$impl.$dsr15($.args[6]),
        dataFonts: _$X.$impl.$dsr15($.args[7]))),
  });

  static const int _$toCSVId = 1;
  static const int _$toExcelId = 2;
  static const int _$toPDFId = 3;
}

/// Service initializer for ExportService
WorkerService $ExportServiceInitializer(WorkerRequest $$) =>
    _$ExportServiceWorkerService();

/// Worker for ExportService
base class ExportServiceWorker extends Worker implements ExportService {
  ExportServiceWorker(
      {PlatformThreadHook? threadHook, ExceptionManager? exceptionManager})
      : super($ExportServiceActivator(Squadron.platformType));

  ExportServiceWorker.vm(
      {PlatformThreadHook? threadHook, ExceptionManager? exceptionManager})
      : super($ExportServiceActivator(SquadronPlatformType.vm));

  ExportServiceWorker.js(
      {PlatformThreadHook? threadHook, ExceptionManager? exceptionManager})
      : super($ExportServiceActivator(SquadronPlatformType.js),
            threadHook: threadHook, exceptionManager: exceptionManager);

  ExportServiceWorker.wasm(
      {PlatformThreadHook? threadHook, ExceptionManager? exceptionManager})
      : super($ExportServiceActivator(SquadronPlatformType.wasm));

  @override
  Future<Uint8List?> toCSV(List<int> bytes) =>
      send(_$ExportServiceWorkerService._$toCSVId,
          args: [_$X.$impl.$sr16(bytes)]).then(_$X.$impl.$dsr18);

  @override
  Future<Uint8List?> toExcel(List<int> bytes, {List<String>? columns}) =>
      send(_$ExportServiceWorkerService._$toExcelId,
              args: [_$X.$impl.$sr16(bytes), _$X.$impl.$sr19(columns)])
          .then(_$X.$impl.$dsr18);

  @override
  Future<Uint8List?> toPDF(List<int> bytes,
          {String? title,
          bool isLandscape = true,
          List<String>? columns,
          Map<int, double>? columnWidths,
          ByteData? fontData,
          Map<int, ByteData>? titleFonts,
          Map<int, ByteData>? dataFonts}) =>
      send(_$ExportServiceWorkerService._$toPDFId, args: [
        _$X.$impl.$sr16(bytes),
        title,
        isLandscape,
        _$X.$impl.$sr19(columns),
        _$X.$impl.$sr21(columnWidths),
        _$X.$impl.$sr23(fontData),
        _$X.$impl.$sr25(titleFonts),
        _$X.$impl.$sr25(dataFonts)
      ]).then(_$X.$impl.$dsr18);
}

final class _$X {
  _$X._();

  static _$X? _impl;

  static _$X get $impl {
    if (_impl == null) {
      Squadron.onConverterChanged(() => _impl = _$X._());
      _impl = _$X._();
    }
    return _impl!;
  }

  late final $dsr0 = Squadron.converter.value<int>();
  late final $dsr1 = Squadron.converter.list<int>($dsr0);
  late final $sr2 = (($) => (const TypedDataMarshaler<Uint8List>()).marshal($));
  late final $sr3 = Squadron.converter.nullable($sr2);
  late final $dsr4 = Squadron.converter.value<String>();
  late final $dsr5 = Squadron.converter.list<String>($dsr4);
  late final $dsr6 = Squadron.converter.nullable($dsr5);
  late final $dsr7 = Squadron.converter.nullable($dsr4);
  late final $dsr8 = Squadron.converter.value<bool>();
  late final $dsr9 = Squadron.converter.value<double>();
  late final $dsr10 =
      Squadron.converter.map<int, double>(kcast: $dsr0, vcast: $dsr9);
  late final $dsr11 = Squadron.converter.nullable($dsr10);
  late final $dsr12 =
      (($) => (const TypedDataMarshaler<ByteData>()).unmarshal($));
  late final $dsr13 = Squadron.converter.nullable($dsr12);
  late final $dsr14 =
      Squadron.converter.map<int, ByteData>(kcast: $dsr0, vcast: $dsr12);
  late final $dsr15 = Squadron.converter.nullable($dsr14);
  late final $sr16 = Squadron.converter.list();
  late final $dsr17 =
      (($) => (const TypedDataMarshaler<Uint8List>()).unmarshal($));
  late final $dsr18 = Squadron.converter.nullable($dsr17);
  late final $sr19 = Squadron.converter.nullable($sr16);
  late final $sr20 = Squadron.converter.map();
  late final $sr21 = Squadron.converter.nullable($sr20);
  late final $sr22 = (($) => (const TypedDataMarshaler<ByteData>()).marshal($));
  late final $sr23 = Squadron.converter.nullable($sr22);
  late final $sr24 = Squadron.converter.map(vcast: $sr22);
  late final $sr25 = Squadron.converter.nullable($sr24);
}

Versions: squadron: ^6.1.1 squadron_builder: ^6.1.1

d-markey commented 1 day ago

Hello, this one should be fixed after upgrading Squadron to 6.1.2 (no update needed for squadron_builder).

sabin26 commented 1 day ago

I updated the method to return non-nullable Uint8List instead of nullable Uint8List? and it worked without updating squadron version.