diff --git a/flutter_rust_bridge.yaml b/flutter_rust_bridge.yaml index 782eba5..bf091fc 100644 --- a/flutter_rust_bridge.yaml +++ b/flutter_rust_bridge.yaml @@ -1,2 +1,4 @@ rust_input: rust/src/api/**/*.rs -dart_output: lib/common/rust/ \ No newline at end of file +dart_output: lib/common/rust/ +full_dep: true +web: false \ No newline at end of file diff --git a/lib/common/rust/frb_generated.dart b/lib/common/rust/frb_generated.dart index ea4a97f..2d75907 100644 --- a/lib/common/rust/frb_generated.dart +++ b/lib/common/rust/frb_generated.dart @@ -98,14 +98,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { Future> dnsLookupIps({required String host, dynamic hint}) { return handler.executeNormal(NormalTask( callFfi: (port_) { - final serializer = SseSerializer(generalizedFrbRustBinding); - sse_encode_String(host, serializer); - pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 4, port: port_); + var arg0 = cst_encode_String(host); + return wire.wire_dns_lookup_ips(port_, arg0); }, - codec: SseCodec( - decodeSuccessData: sse_decode_list_String, - decodeErrorData: sse_decode_AnyhowException, + codec: DcoCodec( + decodeSuccessData: dco_decode_list_String, + decodeErrorData: dco_decode_AnyhowException, ), constMeta: kDnsLookupIpsConstMeta, argValues: [host], @@ -123,14 +121,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { Future> dnsLookupTxt({required String host, dynamic hint}) { return handler.executeNormal(NormalTask( callFfi: (port_) { - final serializer = SseSerializer(generalizedFrbRustBinding); - sse_encode_String(host, serializer); - pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 3, port: port_); + var arg0 = cst_encode_String(host); + return wire.wire_dns_lookup_txt(port_, arg0); }, - codec: SseCodec( - decodeSuccessData: sse_decode_list_String, - decodeErrorData: sse_decode_AnyhowException, + codec: DcoCodec( + decodeSuccessData: dco_decode_list_String, + decodeErrorData: dco_decode_AnyhowException, ), constMeta: kDnsLookupTxtConstMeta, argValues: [host], @@ -154,18 +150,16 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { dynamic hint}) { return handler.executeNormal(NormalTask( callFfi: (port_) { - final serializer = SseSerializer(generalizedFrbRustBinding); - sse_encode_my_method(method, serializer); - sse_encode_String(url, serializer); - sse_encode_opt_Map_String_String(headers, serializer); - sse_encode_opt_list_prim_u_8_strict(inputData, serializer); - sse_encode_opt_String(withIpAddress, serializer); - pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 2, port: port_); + var arg0 = cst_encode_my_method(method); + var arg1 = cst_encode_String(url); + var arg2 = cst_encode_opt_Map_String_String(headers); + var arg3 = cst_encode_opt_list_prim_u_8_strict(inputData); + var arg4 = cst_encode_opt_String(withIpAddress); + return wire.wire_fetch(port_, arg0, arg1, arg2, arg3, arg4); }, - codec: SseCodec( - decodeSuccessData: sse_decode_rust_http_response, - decodeErrorData: sse_decode_AnyhowException, + codec: DcoCodec( + decodeSuccessData: dco_decode_rust_http_response, + decodeErrorData: dco_decode_AnyhowException, ), constMeta: kFetchConstMeta, argValues: [method, url, headers, inputData, withIpAddress], @@ -184,13 +178,11 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { {required Map headers, dynamic hint}) { return handler.executeNormal(NormalTask( callFfi: (port_) { - final serializer = SseSerializer(generalizedFrbRustBinding); - sse_encode_Map_String_String(headers, serializer); - pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 1, port: port_); + var arg0 = cst_encode_Map_String_String(headers); + return wire.wire_set_default_header(port_, arg0); }, - codec: SseCodec( - decodeSuccessData: sse_decode_unit, + codec: DcoCodec( + decodeSuccessData: dco_decode_unit, decodeErrorData: null, ), constMeta: kSetDefaultHeaderConstMeta, @@ -213,15 +205,13 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { dynamic hint}) { return handler.executeStream(StreamTask( callFfi: (port_) { - final serializer = SseSerializer(generalizedFrbRustBinding); - sse_encode_String(executable, serializer); - sse_encode_list_String(arguments, serializer); - sse_encode_String(workingDirectory, serializer); - pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 5, port: port_); + var arg0 = cst_encode_String(executable); + var arg1 = cst_encode_list_String(arguments); + var arg2 = cst_encode_String(workingDirectory); + return wire.wire_start_process(port_, arg0, arg1, arg2); }, - codec: SseCodec( - decodeSuccessData: sse_decode_String, + codec: DcoCodec( + decodeSuccessData: dco_decode_String, decodeErrorData: null, ), constMeta: kStartProcessConstMeta, @@ -558,6 +548,42 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return deserializer.buffer.getUint8() != 0; } + @protected + int cst_encode_i_32(int raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return raw; + } + + @protected + int cst_encode_my_http_version(MyHttpVersion raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return cst_encode_i_32(raw.index); + } + + @protected + int cst_encode_my_method(MyMethod raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return cst_encode_i_32(raw.index); + } + + @protected + int cst_encode_u_16(int raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return raw; + } + + @protected + int cst_encode_u_8(int raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return raw; + } + + @protected + void cst_encode_unit(void raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return raw; + } + @protected void sse_encode_AnyhowException( AnyhowException self, SseSerializer serializer) { diff --git a/lib/common/rust/frb_generated.io.dart b/lib/common/rust/frb_generated.io.dart index 2770ab1..fcc3bed 100644 --- a/lib/common/rust/frb_generated.io.dart +++ b/lib/common/rust/frb_generated.io.dart @@ -147,6 +147,134 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected bool sse_decode_bool(SseDeserializer deserializer); + @protected + ffi.Pointer cst_encode_AnyhowException( + AnyhowException raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + throw UnimplementedError(); + } + + @protected + ffi.Pointer cst_encode_Map_String_String( + Map raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return cst_encode_list_record_string_string( + raw.entries.map((e) => (e.key, e.value)).toList()); + } + + @protected + ffi.Pointer cst_encode_String(String raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return cst_encode_list_prim_u_8_strict(utf8.encoder.convert(raw)); + } + + @protected + ffi.Pointer cst_encode_box_autoadd_u_64(int raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return wire.cst_new_box_autoadd_u_64(cst_encode_u_64(raw)); + } + + @protected + ffi.Pointer cst_encode_list_String(List raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + final ans = wire.cst_new_list_String(raw.length); + for (var i = 0; i < raw.length; ++i) { + ans.ref.ptr[i] = cst_encode_String(raw[i]); + } + return ans; + } + + @protected + ffi.Pointer cst_encode_list_prim_u_8_strict( + Uint8List raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + final ans = wire.cst_new_list_prim_u_8_strict(raw.length); + ans.ref.ptr.asTypedList(raw.length).setAll(0, raw); + return ans; + } + + @protected + ffi.Pointer + cst_encode_list_record_string_string(List<(String, String)> raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + final ans = wire.cst_new_list_record_string_string(raw.length); + for (var i = 0; i < raw.length; ++i) { + cst_api_fill_to_wire_record_string_string(raw[i], ans.ref.ptr[i]); + } + return ans; + } + + @protected + ffi.Pointer + cst_encode_opt_Map_String_String(Map? raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return raw == null ? ffi.nullptr : cst_encode_Map_String_String(raw); + } + + @protected + ffi.Pointer cst_encode_opt_String( + String? raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return raw == null ? ffi.nullptr : cst_encode_String(raw); + } + + @protected + ffi.Pointer cst_encode_opt_box_autoadd_u_64(int? raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return raw == null ? ffi.nullptr : cst_encode_box_autoadd_u_64(raw); + } + + @protected + ffi.Pointer + cst_encode_opt_list_prim_u_8_strict(Uint8List? raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return raw == null ? ffi.nullptr : cst_encode_list_prim_u_8_strict(raw); + } + + @protected + int cst_encode_u_64(int raw) { + // Codec=Cst (C-struct based), see doc to use other codecs + return raw.toInt(); + } + + @protected + void cst_api_fill_to_wire_record_string_string( + (String, String) apiObj, wire_cst_record_string_string wireObj) { + wireObj.field0 = cst_encode_String(apiObj.$1); + wireObj.field1 = cst_encode_String(apiObj.$2); + } + + @protected + void cst_api_fill_to_wire_rust_http_response( + RustHttpResponse apiObj, wire_cst_rust_http_response wireObj) { + wireObj.status_code = cst_encode_u_16(apiObj.statusCode); + wireObj.headers = cst_encode_Map_String_String(apiObj.headers); + wireObj.url = cst_encode_String(apiObj.url); + wireObj.content_length = + cst_encode_opt_box_autoadd_u_64(apiObj.contentLength); + wireObj.version = cst_encode_my_http_version(apiObj.version); + wireObj.remote_addr = cst_encode_String(apiObj.remoteAddr); + wireObj.data = cst_encode_opt_list_prim_u_8_strict(apiObj.data); + } + + @protected + int cst_encode_i_32(int raw); + + @protected + int cst_encode_my_http_version(MyHttpVersion raw); + + @protected + int cst_encode_my_method(MyMethod raw); + + @protected + int cst_encode_u_16(int raw); + + @protected + int cst_encode_u_8(int raw); + + @protected + void cst_encode_unit(void raw); + @protected void sse_encode_AnyhowException( AnyhowException self, SseSerializer serializer); @@ -221,6 +349,13 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { // Section: wire_class +// ignore_for_file: camel_case_types, non_constant_identifier_names, avoid_positional_boolean_parameters, annotate_overrides, constant_identifier_names +// AUTO GENERATED FILE, DO NOT EDIT. +// +// Generated by `package:ffigen`. +// ignore_for_file: type=lint + +/// generated by flutter_rust_bridge class RustLibWire implements BaseWire { factory RustLibWire.fromExternalLibrary(ExternalLibrary lib) => RustLibWire(lib.ffiDynamicLibrary); @@ -232,4 +367,270 @@ class RustLibWire implements BaseWire { /// The symbols are looked up in [dynamicLibrary]. RustLibWire(ffi.DynamicLibrary dynamicLibrary) : _lookup = dynamicLibrary.lookup; + + /// The symbols are looked up with [lookup]. + RustLibWire.fromLookup( + ffi.Pointer Function(String symbolName) + lookup) + : _lookup = lookup; + + void store_dart_post_cobject( + DartPostCObjectFnType ptr, + ) { + return _store_dart_post_cobject( + ptr, + ); + } + + late final _store_dart_post_cobjectPtr = + _lookup>( + 'store_dart_post_cobject'); + late final _store_dart_post_cobject = _store_dart_post_cobjectPtr + .asFunction(); + + void wire_dns_lookup_ips( + int port_, + ffi.Pointer host, + ) { + return _wire_dns_lookup_ips( + port_, + host, + ); + } + + late final _wire_dns_lookup_ipsPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int64, ffi.Pointer)>>( + 'frbgen_starcitizen_doctor_wire_dns_lookup_ips'); + late final _wire_dns_lookup_ips = _wire_dns_lookup_ipsPtr.asFunction< + void Function(int, ffi.Pointer)>(); + + void wire_dns_lookup_txt( + int port_, + ffi.Pointer host, + ) { + return _wire_dns_lookup_txt( + port_, + host, + ); + } + + late final _wire_dns_lookup_txtPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int64, ffi.Pointer)>>( + 'frbgen_starcitizen_doctor_wire_dns_lookup_txt'); + late final _wire_dns_lookup_txt = _wire_dns_lookup_txtPtr.asFunction< + void Function(int, ffi.Pointer)>(); + + void wire_fetch( + int port_, + int method, + ffi.Pointer url, + ffi.Pointer headers, + ffi.Pointer input_data, + ffi.Pointer with_ip_address, + ) { + return _wire_fetch( + port_, + method, + url, + headers, + input_data, + with_ip_address, + ); + } + + late final _wire_fetchPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int64, + ffi.Int32, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>( + 'frbgen_starcitizen_doctor_wire_fetch'); + late final _wire_fetch = _wire_fetchPtr.asFunction< + void Function( + int, + int, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>(); + + void wire_set_default_header( + int port_, + ffi.Pointer headers, + ) { + return _wire_set_default_header( + port_, + headers, + ); + } + + late final _wire_set_default_headerPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int64, ffi.Pointer)>>( + 'frbgen_starcitizen_doctor_wire_set_default_header'); + late final _wire_set_default_header = _wire_set_default_headerPtr.asFunction< + void Function(int, ffi.Pointer)>(); + + void wire_start_process( + int port_, + ffi.Pointer executable, + ffi.Pointer arguments, + ffi.Pointer working_directory, + ) { + return _wire_start_process( + port_, + executable, + arguments, + working_directory, + ); + } + + late final _wire_start_processPtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int64, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>>( + 'frbgen_starcitizen_doctor_wire_start_process'); + late final _wire_start_process = _wire_start_processPtr.asFunction< + void Function( + int, + ffi.Pointer, + ffi.Pointer, + ffi.Pointer)>(); + + ffi.Pointer cst_new_box_autoadd_u_64( + int value, + ) { + return _cst_new_box_autoadd_u_64( + value, + ); + } + + late final _cst_new_box_autoadd_u_64Ptr = + _lookup Function(ffi.Uint64)>>( + 'frbgen_starcitizen_doctor_cst_new_box_autoadd_u_64'); + late final _cst_new_box_autoadd_u_64 = _cst_new_box_autoadd_u_64Ptr + .asFunction Function(int)>(); + + ffi.Pointer cst_new_list_String( + int len, + ) { + return _cst_new_list_String( + len, + ); + } + + late final _cst_new_list_StringPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Int32)>>('frbgen_starcitizen_doctor_cst_new_list_String'); + late final _cst_new_list_String = _cst_new_list_StringPtr + .asFunction Function(int)>(); + + ffi.Pointer cst_new_list_prim_u_8_strict( + int len, + ) { + return _cst_new_list_prim_u_8_strict( + len, + ); + } + + late final _cst_new_list_prim_u_8_strictPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function(ffi.Int32)>>( + 'frbgen_starcitizen_doctor_cst_new_list_prim_u_8_strict'); + late final _cst_new_list_prim_u_8_strict = _cst_new_list_prim_u_8_strictPtr + .asFunction Function(int)>(); + + ffi.Pointer + cst_new_list_record_string_string( + int len, + ) { + return _cst_new_list_record_string_string( + len, + ); + } + + late final _cst_new_list_record_string_stringPtr = _lookup< + ffi.NativeFunction< + ffi.Pointer Function( + ffi.Int32)>>( + 'frbgen_starcitizen_doctor_cst_new_list_record_string_string'); + late final _cst_new_list_record_string_string = + _cst_new_list_record_string_stringPtr.asFunction< + ffi.Pointer Function(int)>(); + + int dummy_method_to_enforce_bundling() { + return _dummy_method_to_enforce_bundling(); + } + + late final _dummy_method_to_enforce_bundlingPtr = + _lookup>( + 'dummy_method_to_enforce_bundling'); + late final _dummy_method_to_enforce_bundling = + _dummy_method_to_enforce_bundlingPtr.asFunction(); +} + +typedef DartPostCObjectFnType + = ffi.Pointer>; +typedef DartPostCObjectFnTypeFunction = ffi.Bool Function( + DartPort port_id, ffi.Pointer message); +typedef DartDartPostCObjectFnTypeFunction = bool Function( + DartDartPort port_id, ffi.Pointer message); +typedef DartPort = ffi.Int64; +typedef DartDartPort = int; + +final class wire_cst_list_prim_u_8_strict extends ffi.Struct { + external ffi.Pointer ptr; + + @ffi.Int32() + external int len; +} + +final class wire_cst_record_string_string extends ffi.Struct { + external ffi.Pointer field0; + + external ffi.Pointer field1; +} + +final class wire_cst_list_record_string_string extends ffi.Struct { + external ffi.Pointer ptr; + + @ffi.Int32() + external int len; +} + +final class wire_cst_list_String extends ffi.Struct { + external ffi.Pointer> ptr; + + @ffi.Int32() + external int len; +} + +final class wire_cst_rust_http_response extends ffi.Struct { + @ffi.Uint16() + external int status_code; + + external ffi.Pointer headers; + + external ffi.Pointer url; + + external ffi.Pointer content_length; + + @ffi.Int32() + external int version; + + external ffi.Pointer remote_addr; + + external ffi.Pointer data; } diff --git a/lib/common/rust/frb_generated.web.dart b/lib/common/rust/frb_generated.web.dart deleted file mode 100644 index 037444b..0000000 --- a/lib/common/rust/frb_generated.web.dart +++ /dev/null @@ -1,238 +0,0 @@ -// This file is automatically generated, so please do not edit it. -// Generated by `flutter_rust_bridge`@ 2.0.0-dev.28. - -// ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field - -import 'api/http_api.dart'; -import 'api/process_api.dart'; -import 'dart:async'; -import 'dart:convert'; -import 'frb_generated.dart'; -import 'http_package.dart'; -import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_web.dart'; - -abstract class RustLibApiImplPlatform extends BaseApiImpl { - RustLibApiImplPlatform({ - required super.handler, - required super.wire, - required super.generalizedFrbRustBinding, - required super.portManager, - }); - - @protected - AnyhowException dco_decode_AnyhowException(dynamic raw); - - @protected - Map dco_decode_Map_String_String(dynamic raw); - - @protected - String dco_decode_String(dynamic raw); - - @protected - int dco_decode_box_autoadd_u_64(dynamic raw); - - @protected - int dco_decode_i_32(dynamic raw); - - @protected - List dco_decode_list_String(dynamic raw); - - @protected - Uint8List dco_decode_list_prim_u_8_strict(dynamic raw); - - @protected - List<(String, String)> dco_decode_list_record_string_string(dynamic raw); - - @protected - MyHttpVersion dco_decode_my_http_version(dynamic raw); - - @protected - MyMethod dco_decode_my_method(dynamic raw); - - @protected - Map? dco_decode_opt_Map_String_String(dynamic raw); - - @protected - String? dco_decode_opt_String(dynamic raw); - - @protected - int? dco_decode_opt_box_autoadd_u_64(dynamic raw); - - @protected - Uint8List? dco_decode_opt_list_prim_u_8_strict(dynamic raw); - - @protected - (String, String) dco_decode_record_string_string(dynamic raw); - - @protected - RustHttpResponse dco_decode_rust_http_response(dynamic raw); - - @protected - int dco_decode_u_16(dynamic raw); - - @protected - int dco_decode_u_64(dynamic raw); - - @protected - int dco_decode_u_8(dynamic raw); - - @protected - void dco_decode_unit(dynamic raw); - - @protected - AnyhowException sse_decode_AnyhowException(SseDeserializer deserializer); - - @protected - Map sse_decode_Map_String_String( - SseDeserializer deserializer); - - @protected - String sse_decode_String(SseDeserializer deserializer); - - @protected - int sse_decode_box_autoadd_u_64(SseDeserializer deserializer); - - @protected - int sse_decode_i_32(SseDeserializer deserializer); - - @protected - List sse_decode_list_String(SseDeserializer deserializer); - - @protected - Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer); - - @protected - List<(String, String)> sse_decode_list_record_string_string( - SseDeserializer deserializer); - - @protected - MyHttpVersion sse_decode_my_http_version(SseDeserializer deserializer); - - @protected - MyMethod sse_decode_my_method(SseDeserializer deserializer); - - @protected - Map? sse_decode_opt_Map_String_String( - SseDeserializer deserializer); - - @protected - String? sse_decode_opt_String(SseDeserializer deserializer); - - @protected - int? sse_decode_opt_box_autoadd_u_64(SseDeserializer deserializer); - - @protected - Uint8List? sse_decode_opt_list_prim_u_8_strict(SseDeserializer deserializer); - - @protected - (String, String) sse_decode_record_string_string( - SseDeserializer deserializer); - - @protected - RustHttpResponse sse_decode_rust_http_response(SseDeserializer deserializer); - - @protected - int sse_decode_u_16(SseDeserializer deserializer); - - @protected - int sse_decode_u_64(SseDeserializer deserializer); - - @protected - int sse_decode_u_8(SseDeserializer deserializer); - - @protected - void sse_decode_unit(SseDeserializer deserializer); - - @protected - bool sse_decode_bool(SseDeserializer deserializer); - - @protected - void sse_encode_AnyhowException( - AnyhowException self, SseSerializer serializer); - - @protected - void sse_encode_Map_String_String( - Map self, SseSerializer serializer); - - @protected - void sse_encode_String(String self, SseSerializer serializer); - - @protected - void sse_encode_box_autoadd_u_64(int self, SseSerializer serializer); - - @protected - void sse_encode_i_32(int self, SseSerializer serializer); - - @protected - void sse_encode_list_String(List self, SseSerializer serializer); - - @protected - void sse_encode_list_prim_u_8_strict( - Uint8List self, SseSerializer serializer); - - @protected - void sse_encode_list_record_string_string( - List<(String, String)> self, SseSerializer serializer); - - @protected - void sse_encode_my_http_version(MyHttpVersion self, SseSerializer serializer); - - @protected - void sse_encode_my_method(MyMethod self, SseSerializer serializer); - - @protected - void sse_encode_opt_Map_String_String( - Map? self, SseSerializer serializer); - - @protected - void sse_encode_opt_String(String? self, SseSerializer serializer); - - @protected - void sse_encode_opt_box_autoadd_u_64(int? self, SseSerializer serializer); - - @protected - void sse_encode_opt_list_prim_u_8_strict( - Uint8List? self, SseSerializer serializer); - - @protected - void sse_encode_record_string_string( - (String, String) self, SseSerializer serializer); - - @protected - void sse_encode_rust_http_response( - RustHttpResponse self, SseSerializer serializer); - - @protected - void sse_encode_u_16(int self, SseSerializer serializer); - - @protected - void sse_encode_u_64(int self, SseSerializer serializer); - - @protected - void sse_encode_u_8(int self, SseSerializer serializer); - - @protected - void sse_encode_unit(void self, SseSerializer serializer); - - @protected - void sse_encode_bool(bool self, SseSerializer serializer); -} - -// Section: wire_class - -class RustLibWire implements BaseWire { - RustLibWire.fromExternalLibrary(ExternalLibrary lib); -} - -@JS('wasm_bindgen') -external RustLibWasmModule get wasmModule; - -@JS() -@anonymous -class RustLibWasmModule implements WasmModule { - @override - external Object /* Promise */ call([String? moduleName]); - - @override - external RustLibWasmModule bind(dynamic thisArg, String moduleName); -} diff --git a/pubspec.yaml b/pubspec.yaml index 65d2b19..1d2ad76 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -102,6 +102,7 @@ dev_dependencies: riverpod_generator: ^2.3.11 custom_lint: ^0.6.2 riverpod_lint: ^2.3.9 + ffigen: ^11.0.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 671b17b..7eb0232 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -14,7 +14,6 @@ crate-type = ["cdylib", "staticlib"] flutter_rust_bridge = "=2.0.0-dev.28" tokio = { version = "1", features = ["rt", "rt-multi-thread", "macros","process"] } url = "2.5.0" -uuid = { version = "1.7.0", features = ["v4", "fast-rng", "macro-diagnostics"] } async-std = "1.12.0" hyper = { version = "0.14.28"} once_cell = "1.19.0" diff --git a/rust/src/frb_generated.io.rs b/rust/src/frb_generated.io.rs index 0bfd71d..b716142 100644 --- a/rust/src/frb_generated.io.rs +++ b/rust/src/frb_generated.io.rs @@ -11,3 +11,242 @@ use flutter_rust_bridge::{Handler, IntoIntoDart}; // Section: boilerplate flutter_rust_bridge::frb_generated_boilerplate_io!(); + +// Section: dart2rust + +impl CstDecode + for *mut wire_cst_list_prim_u_8_strict +{ + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> flutter_rust_bridge::for_generated::anyhow::Error { + unimplemented!() + } +} +impl CstDecode> + for *mut wire_cst_list_record_string_string +{ + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> std::collections::HashMap { + let vec: Vec<(String, String)> = self.cst_decode(); + vec.into_iter().collect() + } +} +impl CstDecode for *mut wire_cst_list_prim_u_8_strict { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> String { + let vec: Vec = self.cst_decode(); + String::from_utf8(vec).unwrap() + } +} +impl CstDecode for *mut u64 { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> u64 { + unsafe { *flutter_rust_bridge::for_generated::box_from_leak_ptr(self) } + } +} +impl CstDecode> for *mut wire_cst_list_String { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> Vec { + let vec = unsafe { + let wrap = flutter_rust_bridge::for_generated::box_from_leak_ptr(self); + flutter_rust_bridge::for_generated::vec_from_leak_ptr(wrap.ptr, wrap.len) + }; + vec.into_iter().map(CstDecode::cst_decode).collect() + } +} +impl CstDecode> for *mut wire_cst_list_prim_u_8_strict { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> Vec { + unsafe { + let wrap = flutter_rust_bridge::for_generated::box_from_leak_ptr(self); + flutter_rust_bridge::for_generated::vec_from_leak_ptr(wrap.ptr, wrap.len) + } + } +} +impl CstDecode> for *mut wire_cst_list_record_string_string { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> Vec<(String, String)> { + let vec = unsafe { + let wrap = flutter_rust_bridge::for_generated::box_from_leak_ptr(self); + flutter_rust_bridge::for_generated::vec_from_leak_ptr(wrap.ptr, wrap.len) + }; + vec.into_iter().map(CstDecode::cst_decode).collect() + } +} +impl CstDecode<(String, String)> for wire_cst_record_string_string { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> (String, String) { + (self.field0.cst_decode(), self.field1.cst_decode()) + } +} +impl CstDecode for wire_cst_rust_http_response { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> crate::http_package::RustHttpResponse { + crate::http_package::RustHttpResponse { + status_code: self.status_code.cst_decode(), + headers: self.headers.cst_decode(), + url: self.url.cst_decode(), + content_length: self.content_length.cst_decode(), + version: self.version.cst_decode(), + remote_addr: self.remote_addr.cst_decode(), + data: self.data.cst_decode(), + } + } +} +impl NewWithNullPtr for wire_cst_record_string_string { + fn new_with_null_ptr() -> Self { + Self { + field0: core::ptr::null_mut(), + field1: core::ptr::null_mut(), + } + } +} +impl Default for wire_cst_record_string_string { + fn default() -> Self { + Self::new_with_null_ptr() + } +} +impl NewWithNullPtr for wire_cst_rust_http_response { + fn new_with_null_ptr() -> Self { + Self { + status_code: Default::default(), + headers: core::ptr::null_mut(), + url: core::ptr::null_mut(), + content_length: core::ptr::null_mut(), + version: Default::default(), + remote_addr: core::ptr::null_mut(), + data: core::ptr::null_mut(), + } + } +} +impl Default for wire_cst_rust_http_response { + fn default() -> Self { + Self::new_with_null_ptr() + } +} + +#[no_mangle] +pub extern "C" fn frbgen_starcitizen_doctor_wire_dns_lookup_ips( + port_: i64, + host: *mut wire_cst_list_prim_u_8_strict, +) { + wire_dns_lookup_ips_impl(port_, host) +} + +#[no_mangle] +pub extern "C" fn frbgen_starcitizen_doctor_wire_dns_lookup_txt( + port_: i64, + host: *mut wire_cst_list_prim_u_8_strict, +) { + wire_dns_lookup_txt_impl(port_, host) +} + +#[no_mangle] +pub extern "C" fn frbgen_starcitizen_doctor_wire_fetch( + port_: i64, + method: i32, + url: *mut wire_cst_list_prim_u_8_strict, + headers: *mut wire_cst_list_record_string_string, + input_data: *mut wire_cst_list_prim_u_8_strict, + with_ip_address: *mut wire_cst_list_prim_u_8_strict, +) { + wire_fetch_impl(port_, method, url, headers, input_data, with_ip_address) +} + +#[no_mangle] +pub extern "C" fn frbgen_starcitizen_doctor_wire_set_default_header( + port_: i64, + headers: *mut wire_cst_list_record_string_string, +) { + wire_set_default_header_impl(port_, headers) +} + +#[no_mangle] +pub extern "C" fn frbgen_starcitizen_doctor_wire_start_process( + port_: i64, + executable: *mut wire_cst_list_prim_u_8_strict, + arguments: *mut wire_cst_list_String, + working_directory: *mut wire_cst_list_prim_u_8_strict, +) { + wire_start_process_impl(port_, executable, arguments, working_directory) +} + +#[no_mangle] +pub extern "C" fn frbgen_starcitizen_doctor_cst_new_box_autoadd_u_64(value: u64) -> *mut u64 { + flutter_rust_bridge::for_generated::new_leak_box_ptr(value) +} + +#[no_mangle] +pub extern "C" fn frbgen_starcitizen_doctor_cst_new_list_String( + len: i32, +) -> *mut wire_cst_list_String { + let wrap = wire_cst_list_String { + ptr: flutter_rust_bridge::for_generated::new_leak_vec_ptr( + <*mut wire_cst_list_prim_u_8_strict>::new_with_null_ptr(), + len, + ), + len, + }; + flutter_rust_bridge::for_generated::new_leak_box_ptr(wrap) +} + +#[no_mangle] +pub extern "C" fn frbgen_starcitizen_doctor_cst_new_list_prim_u_8_strict( + len: i32, +) -> *mut wire_cst_list_prim_u_8_strict { + let ans = wire_cst_list_prim_u_8_strict { + ptr: flutter_rust_bridge::for_generated::new_leak_vec_ptr(Default::default(), len), + len, + }; + flutter_rust_bridge::for_generated::new_leak_box_ptr(ans) +} + +#[no_mangle] +pub extern "C" fn frbgen_starcitizen_doctor_cst_new_list_record_string_string( + len: i32, +) -> *mut wire_cst_list_record_string_string { + let wrap = wire_cst_list_record_string_string { + ptr: flutter_rust_bridge::for_generated::new_leak_vec_ptr( + ::new_with_null_ptr(), + len, + ), + len, + }; + flutter_rust_bridge::for_generated::new_leak_box_ptr(wrap) +} + +#[repr(C)] +#[derive(Clone, Copy)] +pub struct wire_cst_list_String { + ptr: *mut *mut wire_cst_list_prim_u_8_strict, + len: i32, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct wire_cst_list_prim_u_8_strict { + ptr: *mut u8, + len: i32, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct wire_cst_list_record_string_string { + ptr: *mut wire_cst_record_string_string, + len: i32, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct wire_cst_record_string_string { + field0: *mut wire_cst_list_prim_u_8_strict, + field1: *mut wire_cst_list_prim_u_8_strict, +} +#[repr(C)] +#[derive(Clone, Copy)] +pub struct wire_cst_rust_http_response { + status_code: u16, + headers: *mut wire_cst_list_record_string_string, + url: *mut wire_cst_list_prim_u_8_strict, + content_length: *mut u64, + version: i32, + remote_addr: *mut wire_cst_list_prim_u_8_strict, + data: *mut wire_cst_list_prim_u_8_strict, +} diff --git a/rust/src/frb_generated.rs b/rust/src/frb_generated.rs index d2944a0..c2957fe 100644 --- a/rust/src/frb_generated.rs +++ b/rust/src/frb_generated.rs @@ -26,9 +26,9 @@ use flutter_rust_bridge::{Handler, IntoIntoDart}; // Section: boilerplate flutter_rust_bridge::frb_generated_boilerplate!( - default_stream_sink_codec = SseCodec, - default_rust_opaque = RustOpaqueMoi, - default_rust_auto_opaque = RustAutoOpaqueMoi, + default_stream_sink_codec = DcoCodec, + default_rust_opaque = RustOpaqueNom, + default_rust_auto_opaque = RustAutoOpaqueNom, ); const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.0.0-dev.28"; @@ -40,30 +40,18 @@ flutter_rust_bridge::frb_generated_default_handler!(); fn wire_dns_lookup_ips_impl( port_: flutter_rust_bridge::for_generated::MessagePort, - ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, - rust_vec_len_: i32, - data_len_: i32, + host: impl CstDecode, ) { - FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::( + FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::( flutter_rust_bridge::for_generated::TaskInfo { debug_name: "dns_lookup_ips", port: Some(port_), mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, }, move || { - let message = unsafe { - flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( - ptr_, - rust_vec_len_, - data_len_, - ) - }; - let mut deserializer = - flutter_rust_bridge::for_generated::SseDeserializer::new(message); - let api_host = ::sse_decode(&mut deserializer); - deserializer.end(); + let api_host = host.cst_decode(); move |context| async move { - transform_result_sse( + transform_result_dco( (move || async move { crate::api::http_api::dns_lookup_ips(api_host).await })() .await, ) @@ -73,30 +61,18 @@ fn wire_dns_lookup_ips_impl( } fn wire_dns_lookup_txt_impl( port_: flutter_rust_bridge::for_generated::MessagePort, - ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, - rust_vec_len_: i32, - data_len_: i32, + host: impl CstDecode, ) { - FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::( + FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::( flutter_rust_bridge::for_generated::TaskInfo { debug_name: "dns_lookup_txt", port: Some(port_), mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, }, move || { - let message = unsafe { - flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( - ptr_, - rust_vec_len_, - data_len_, - ) - }; - let mut deserializer = - flutter_rust_bridge::for_generated::SseDeserializer::new(message); - let api_host = ::sse_decode(&mut deserializer); - deserializer.end(); + let api_host = host.cst_decode(); move |context| async move { - transform_result_sse( + transform_result_dco( (move || async move { crate::api::http_api::dns_lookup_txt(api_host).await })() .await, ) @@ -106,35 +82,26 @@ fn wire_dns_lookup_txt_impl( } fn wire_fetch_impl( port_: flutter_rust_bridge::for_generated::MessagePort, - ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, - rust_vec_len_: i32, - data_len_: i32, + method: impl CstDecode, + url: impl CstDecode, + headers: impl CstDecode>>, + input_data: impl CstDecode>>, + with_ip_address: impl CstDecode>, ) { - FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::( + FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::( flutter_rust_bridge::for_generated::TaskInfo { debug_name: "fetch", port: Some(port_), mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, }, move || { - let message = unsafe { - flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( - ptr_, - rust_vec_len_, - data_len_, - ) - }; - let mut deserializer = - flutter_rust_bridge::for_generated::SseDeserializer::new(message); - let api_method = ::sse_decode(&mut deserializer); - let api_url = ::sse_decode(&mut deserializer); - let api_headers = - >>::sse_decode(&mut deserializer); - let api_input_data = >>::sse_decode(&mut deserializer); - let api_with_ip_address = >::sse_decode(&mut deserializer); - deserializer.end(); + let api_method = method.cst_decode(); + let api_url = url.cst_decode(); + let api_headers = headers.cst_decode(); + let api_input_data = input_data.cst_decode(); + let api_with_ip_address = with_ip_address.cst_decode(); move |context| async move { - transform_result_sse( + transform_result_dco( (move || async move { crate::api::http_api::fetch( api_method, @@ -153,31 +120,18 @@ fn wire_fetch_impl( } fn wire_set_default_header_impl( port_: flutter_rust_bridge::for_generated::MessagePort, - ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, - rust_vec_len_: i32, - data_len_: i32, + headers: impl CstDecode>, ) { - FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( flutter_rust_bridge::for_generated::TaskInfo { debug_name: "set_default_header", port: Some(port_), mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, }, move || { - let message = unsafe { - flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( - ptr_, - rust_vec_len_, - data_len_, - ) - }; - let mut deserializer = - flutter_rust_bridge::for_generated::SseDeserializer::new(message); - let api_headers = - >::sse_decode(&mut deserializer); - deserializer.end(); + let api_headers = headers.cst_decode(); move |context| { - transform_result_sse((move || { + transform_result_dco((move || { Result::<_, ()>::Ok(crate::api::http_api::set_default_header(api_headers)) })()) } @@ -186,32 +140,22 @@ fn wire_set_default_header_impl( } fn wire_start_process_impl( port_: flutter_rust_bridge::for_generated::MessagePort, - ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, - rust_vec_len_: i32, - data_len_: i32, + executable: impl CstDecode, + arguments: impl CstDecode>, + working_directory: impl CstDecode, ) { - FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::( + FLUTTER_RUST_BRIDGE_HANDLER.wrap_async::( flutter_rust_bridge::for_generated::TaskInfo { debug_name: "start_process", port: Some(port_), mode: flutter_rust_bridge::for_generated::FfiCallMode::Stream, }, move || { - let message = unsafe { - flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( - ptr_, - rust_vec_len_, - data_len_, - ) - }; - let mut deserializer = - flutter_rust_bridge::for_generated::SseDeserializer::new(message); - let api_executable = ::sse_decode(&mut deserializer); - let api_arguments = >::sse_decode(&mut deserializer); - let api_working_directory = ::sse_decode(&mut deserializer); - deserializer.end(); + let api_executable = executable.cst_decode(); + let api_arguments = arguments.cst_decode(); + let api_working_directory = working_directory.cst_decode(); move |context| async move { - transform_result_sse( + transform_result_dco( (move || async move { Result::<_, ()>::Ok( crate::api::process_api::start_process( @@ -234,6 +178,61 @@ fn wire_start_process_impl( // Section: dart2rust +impl CstDecode for i32 { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> i32 { + self + } +} +impl CstDecode for i32 { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> crate::http_package::MyHttpVersion { + match self { + 0 => crate::http_package::MyHttpVersion::HTTP_09, + 1 => crate::http_package::MyHttpVersion::HTTP_10, + 2 => crate::http_package::MyHttpVersion::HTTP_11, + 3 => crate::http_package::MyHttpVersion::HTTP_2, + 4 => crate::http_package::MyHttpVersion::HTTP_3, + 5 => crate::http_package::MyHttpVersion::HTTP_UNKNOWN, + _ => unreachable!("Invalid variant for MyHttpVersion: {}", self), + } + } +} +impl CstDecode for i32 { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> crate::api::http_api::MyMethod { + match self { + 0 => crate::api::http_api::MyMethod::Options, + 1 => crate::api::http_api::MyMethod::Gets, + 2 => crate::api::http_api::MyMethod::Post, + 3 => crate::api::http_api::MyMethod::Put, + 4 => crate::api::http_api::MyMethod::Delete, + 5 => crate::api::http_api::MyMethod::Head, + 6 => crate::api::http_api::MyMethod::Trace, + 7 => crate::api::http_api::MyMethod::Connect, + 8 => crate::api::http_api::MyMethod::Patch, + _ => unreachable!("Invalid variant for MyMethod: {}", self), + } + } +} +impl CstDecode for u16 { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> u16 { + self + } +} +impl CstDecode for u64 { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> u64 { + self + } +} +impl CstDecode for u8 { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> u8 { + self + } +} impl SseDecode for flutter_rust_bridge::for_generated::anyhow::Error { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -454,11 +453,6 @@ fn pde_ffi_dispatcher_primary_impl( ) { // Codec=Pde (Serialization + dispatch), see doc to use other codecs match func_id { - 4 => wire_dns_lookup_ips_impl(port, ptr, rust_vec_len, data_len), - 3 => wire_dns_lookup_txt_impl(port, ptr, rust_vec_len, data_len), - 2 => wire_fetch_impl(port, ptr, rust_vec_len, data_len), - 1 => wire_set_default_header_impl(port, ptr, rust_vec_len, data_len), - 5 => wire_start_process_impl(port, ptr, rust_vec_len, data_len), _ => unreachable!(), } } @@ -755,10 +749,3 @@ impl SseEncode for bool { mod io; #[cfg(not(target_family = "wasm"))] pub use io::*; - -/// cbindgen:ignore -#[cfg(target_family = "wasm")] -#[path = "frb_generated.web.rs"] -mod web; -#[cfg(target_family = "wasm")] -pub use web::*; diff --git a/rust/src/frb_generated.web.rs b/rust/src/frb_generated.web.rs deleted file mode 100644 index 32db254..0000000 --- a/rust/src/frb_generated.web.rs +++ /dev/null @@ -1,15 +0,0 @@ -// This file is automatically generated, so please do not edit it. -// Generated by `flutter_rust_bridge`@ 2.0.0-dev.28. - -// Section: imports - -use super::*; -use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt}; -use flutter_rust_bridge::for_generated::transform_result_dco; -use flutter_rust_bridge::for_generated::wasm_bindgen; -use flutter_rust_bridge::for_generated::wasm_bindgen::prelude::*; -use flutter_rust_bridge::{Handler, IntoIntoDart}; - -// Section: boilerplate - -flutter_rust_bridge::frb_generated_boilerplate_web!();