From aeb2235875c615e80280ca474d7e3cfdeb5e0692 Mon Sep 17 00:00:00 2001 From: laurenspriem Date: Tue, 5 Nov 2024 11:02:04 +0530 Subject: [PATCH] [mob][photos] Time rust processing --- .../face_detection_service.dart | 24 +- mobile/lib/src/rust/api/image_processing.dart | 2 +- mobile/lib/src/rust/frb_generated.dart | 75 +++++-- mobile/lib/src/rust/frb_generated.io.dart | 173 ++++++++++++++- mobile/rust/src/api/image_processing.rs | 21 +- mobile/rust/src/frb_generated.rs | 206 ++++++++++-------- 6 files changed, 383 insertions(+), 118 deletions(-) diff --git a/mobile/lib/services/machine_learning/face_ml/face_detection/face_detection_service.dart b/mobile/lib/services/machine_learning/face_ml/face_detection/face_detection_service.dart index 0f80766421..3883801773 100644 --- a/mobile/lib/services/machine_learning/face_ml/face_detection/face_detection_service.dart +++ b/mobile/lib/services/machine_learning/face_ml/face_detection/face_detection_service.dart @@ -58,17 +58,26 @@ class FaceDetectionService extends MlModel { final startTime = DateTime.now(); - final result = await processYoloFace(imagePath: imagePath); + final (result, timing) = await processYoloFace(imagePath: imagePath); + _logger.info("Face detection preprocessing: \n $timing"); const scaledSize = Dimensions(width: 640, height: 640); + final preprocessingTime = DateTime.now(); + final preprocessingMs = + preprocessingTime.difference(startTime).inMilliseconds; + + final tempTime = DateTime.now(); final inputImageList = await resizedToPreprocessed(result); + _logger.info( + 'Face detection remaining dart processing: ${DateTime.now().difference(tempTime).inMilliseconds} ms', + ); // final (inputImageList, scaledSize) = await preprocessImageYoloFace( // image, // rawRgbaBytes, // ); - final preprocessingTime = DateTime.now(); - final preprocessingMs = - preprocessingTime.difference(startTime).inMilliseconds; + // final preprocessingTime = DateTime.now(); + // final preprocessingMs = + // preprocessingTime.difference(startTime).inMilliseconds; // Run inference List>>? nestedResults = []; @@ -89,9 +98,10 @@ class FaceDetectionService extends MlModel { ); } catch (e, s) { _logger.severe( - 'Error while running inference (PlatformPlugin: ${MlModel.usePlatformPlugin})', - e, - s,); + 'Error while running inference (PlatformPlugin: ${MlModel.usePlatformPlugin})', + e, + s, + ); throw YOLOFaceInterpreterRunException(); } try { diff --git a/mobile/lib/src/rust/api/image_processing.dart b/mobile/lib/src/rust/api/image_processing.dart index 879c21a255..17052fb0ab 100644 --- a/mobile/lib/src/rust/api/image_processing.dart +++ b/mobile/lib/src/rust/api/image_processing.dart @@ -8,6 +8,6 @@ import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; import 'package:photos/src/rust/frb_generated.dart'; -Future processYoloFace({required String imagePath}) => +Future<(Uint8List, String)> processYoloFace({required String imagePath}) => RustLib.instance.api .crateApiImageProcessingProcessYoloFace(imagePath: imagePath); diff --git a/mobile/lib/src/rust/frb_generated.dart b/mobile/lib/src/rust/frb_generated.dart index aa843fc00c..69b208898f 100644 --- a/mobile/lib/src/rust/frb_generated.dart +++ b/mobile/lib/src/rust/frb_generated.dart @@ -83,7 +83,7 @@ class RustLib extends BaseEntrypoint { } abstract class RustLibApi extends BaseApi { - Future crateApiImageProcessingProcessYoloFace( + Future<(Uint8List, String)> crateApiImageProcessingProcessYoloFace( {required String imagePath}); String crateApiSimpleGreet({required String name}); @@ -100,17 +100,16 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { }); @override - Future crateApiImageProcessingProcessYoloFace( + Future<(Uint8List, String)> crateApiImageProcessingProcessYoloFace( {required String imagePath}) { return handler.executeNormal(NormalTask( callFfi: (port_) { - final serializer = SseSerializer(generalizedFrbRustBinding); - sse_encode_String(imagePath, serializer); - pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 1, port: port_); + final arg0 = cst_encode_String(imagePath); + return wire.wire__crate__api__image_processing__process_yolo_face( + port_, arg0); }, - codec: SseCodec( - decodeSuccessData: sse_decode_list_prim_u_8_strict, + codec: DcoCodec( + decodeSuccessData: dco_decode_record_list_prim_u_8_strict_string, decodeErrorData: null, ), constMeta: kCrateApiImageProcessingProcessYoloFaceConstMeta, @@ -129,12 +128,11 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { String crateApiSimpleGreet({required String name}) { return handler.executeSync(SyncTask( callFfi: () { - final serializer = SseSerializer(generalizedFrbRustBinding); - sse_encode_String(name, serializer); - return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 2)!; + final arg0 = cst_encode_String(name); + return wire.wire__crate__api__simple__greet(arg0); }, - codec: SseCodec( - decodeSuccessData: sse_decode_String, + codec: DcoCodec( + decodeSuccessData: dco_decode_String, decodeErrorData: null, ), constMeta: kCrateApiSimpleGreetConstMeta, @@ -152,12 +150,10 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { Future crateApiSimpleInitApp() { return handler.executeNormal(NormalTask( callFfi: (port_) { - final serializer = SseSerializer(generalizedFrbRustBinding); - pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 3, port: port_); + return wire.wire__crate__api__simple__init_app(port_); }, - codec: SseCodec( - decodeSuccessData: sse_decode_unit, + codec: DcoCodec( + decodeSuccessData: dco_decode_unit, decodeErrorData: null, ), constMeta: kCrateApiSimpleInitAppConstMeta, @@ -183,6 +179,20 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return raw as Uint8List; } + @protected + (Uint8List, String) dco_decode_record_list_prim_u_8_strict_string( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + final arr = raw as List; + if (arr.length != 2) { + throw Exception('Expected 2 elements, got ${arr.length}'); + } + return ( + dco_decode_list_prim_u_8_strict(arr[0]), + dco_decode_String(arr[1]), + ); + } + @protected int dco_decode_u_8(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs @@ -209,6 +219,15 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return deserializer.buffer.getUint8List(len_); } + @protected + (Uint8List, String) sse_decode_record_list_prim_u_8_strict_string( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + final var_field0 = sse_decode_list_prim_u_8_strict(deserializer); + final var_field1 = sse_decode_String(deserializer); + return (var_field0, var_field1); + } + @protected int sse_decode_u_8(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -232,6 +251,18 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { return deserializer.buffer.getUint8() != 0; } + @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_String(String self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -246,6 +277,14 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { serializer.buffer.putUint8List(self); } + @protected + void sse_encode_record_list_prim_u_8_strict_string( + (Uint8List, String) self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_list_prim_u_8_strict(self.$1, serializer); + sse_encode_String(self.$2, serializer); + } + @protected void sse_encode_u_8(int self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs diff --git a/mobile/lib/src/rust/frb_generated.io.dart b/mobile/lib/src/rust/frb_generated.io.dart index e992bd1e4b..5b34397716 100644 --- a/mobile/lib/src/rust/frb_generated.io.dart +++ b/mobile/lib/src/rust/frb_generated.io.dart @@ -5,14 +5,13 @@ // 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/image_processing.dart'; +import 'api/simple.dart'; import 'dart:async'; import 'dart:convert'; import 'dart:ffi' as ffi; - +import 'frb_generated.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_io.dart'; -import 'package:photos/src/rust/api/image_processing.dart'; -import 'package:photos/src/rust/api/simple.dart'; -import 'package:photos/src/rust/frb_generated.dart'; abstract class RustLibApiImplPlatform extends BaseApiImpl { RustLibApiImplPlatform({ @@ -28,6 +27,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected Uint8List dco_decode_list_prim_u_8_strict(dynamic raw); + @protected + (Uint8List, String) dco_decode_record_list_prim_u_8_strict_string( + dynamic raw); + @protected int dco_decode_u_8(dynamic raw); @@ -40,6 +43,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer); + @protected + (Uint8List, String) sse_decode_record_list_prim_u_8_strict_string( + SseDeserializer deserializer); + @protected int sse_decode_u_8(SseDeserializer deserializer); @@ -52,6 +59,35 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { @protected bool sse_decode_bool(SseDeserializer deserializer); + @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_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 + void cst_api_fill_to_wire_record_list_prim_u_8_strict_string( + (Uint8List, String) apiObj, + wire_cst_record_list_prim_u_8_strict_string wireObj) { + wireObj.field0 = cst_encode_list_prim_u_8_strict(apiObj.$1); + wireObj.field1 = cst_encode_String(apiObj.$2); + } + + @protected + int cst_encode_u_8(int raw); + + @protected + void cst_encode_unit(void raw); + @protected void sse_encode_String(String self, SseSerializer serializer); @@ -59,6 +95,10 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { void sse_encode_list_prim_u_8_strict( Uint8List self, SseSerializer serializer); + @protected + void sse_encode_record_list_prim_u_8_strict_string( + (Uint8List, String) self, SseSerializer serializer); + @protected void sse_encode_u_8(int self, SseSerializer serializer); @@ -74,6 +114,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); @@ -85,4 +132,122 @@ 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__crate__api__image_processing__process_yolo_face( + int port_, + ffi.Pointer image_path, + ) { + return _wire__crate__api__image_processing__process_yolo_face( + port_, + image_path, + ); + } + + late final _wire__crate__api__image_processing__process_yolo_facePtr = _lookup< + ffi.NativeFunction< + ffi.Void Function( + ffi.Int64, ffi.Pointer)>>( + 'frbgen_photos_wire__crate__api__image_processing__process_yolo_face'); + late final _wire__crate__api__image_processing__process_yolo_face = + _wire__crate__api__image_processing__process_yolo_facePtr.asFunction< + void Function(int, ffi.Pointer)>(); + + WireSyncRust2DartDco wire__crate__api__simple__greet( + ffi.Pointer name, + ) { + return _wire__crate__api__simple__greet( + name, + ); + } + + late final _wire__crate__api__simple__greetPtr = _lookup< + ffi.NativeFunction< + WireSyncRust2DartDco Function( + ffi.Pointer)>>( + 'frbgen_photos_wire__crate__api__simple__greet'); + late final _wire__crate__api__simple__greet = + _wire__crate__api__simple__greetPtr.asFunction< + WireSyncRust2DartDco Function( + ffi.Pointer)>(); + + void wire__crate__api__simple__init_app( + int port_, + ) { + return _wire__crate__api__simple__init_app( + port_, + ); + } + + late final _wire__crate__api__simple__init_appPtr = + _lookup>( + 'frbgen_photos_wire__crate__api__simple__init_app'); + late final _wire__crate__api__simple__init_app = + _wire__crate__api__simple__init_appPtr.asFunction(); + + 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_photos_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)>(); + + 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_list_prim_u_8_strict_string extends ffi.Struct { + external ffi.Pointer field0; + + external ffi.Pointer field1; } diff --git a/mobile/rust/src/api/image_processing.rs b/mobile/rust/src/api/image_processing.rs index da6d984ed3..70b912fbca 100644 --- a/mobile/rust/src/api/image_processing.rs +++ b/mobile/rust/src/api/image_processing.rs @@ -1,26 +1,41 @@ use resize::{px::RGB, Pixel::RGB8, Type::Lanczos3}; use rgb::FromSlice; -pub fn process_yolo_face(image_path: &str) -> Vec { +pub fn process_yolo_face(image_path: &str) -> (Vec, String) { + let mut timing = String::new(); + let start = std::time::Instant::now(); + // Load the image let img = image::open(image_path).expect("Failed to open image"); + let load_time = start.elapsed().as_millis(); + timing.push_str(&format!("Load time: {}ms\n", load_time)); // Get dimensions let (width, height) = (img.width() as usize, img.height() as usize); let (new_width, new_height) = (640, 640); + let dimensions_time = start.elapsed().as_millis() - load_time; + timing.push_str(&format!("Dimensions time: {}ms\n", dimensions_time)); // Convert image to RGB8 let rgb_img = img.to_rgb8(); + let convert_time = start.elapsed().as_millis() - dimensions_time; + timing.push_str(&format!("Convert time: {}ms\n", convert_time)); let rgb_vec = rgb_img.to_vec(); + let rgb_vec_time = start.elapsed().as_millis() - convert_time; + timing.push_str(&format!("RGB Vec time: {}ms\n", rgb_vec_time)); // Create resizer let mut resizer = resize::new(width, height, new_width, new_height, RGB8, Lanczos3).unwrap(); // Create buffer for resized image let mut dst = vec![RGB::new(0, 0, 0); new_width * new_height]; + let buffer_time = start.elapsed().as_millis() - rgb_vec_time; + timing.push_str(&format!("Buffer time: {}ms\n", buffer_time)); // Create ImageBuffer from resized data resizer.resize(rgb_vec.as_rgb(), &mut dst).unwrap(); + let resize_time = start.elapsed().as_millis() - buffer_time; + timing.push_str(&format!("Resize time: {}ms\n", resize_time)); // Return dst as a Vec let mut result = Vec::new(); @@ -29,5 +44,7 @@ pub fn process_yolo_face(image_path: &str) -> Vec { result.push(pixel.g); result.push(pixel.b); } - result + let result_time = start.elapsed().as_millis() - resize_time; + timing.push_str(&format!("Result time: {}ms\n", result_time)); + (result, timing) } diff --git a/mobile/rust/src/frb_generated.rs b/mobile/rust/src/frb_generated.rs index cf8da2a203..773fe34a0d 100644 --- a/mobile/rust/src/frb_generated.rs +++ b/mobile/rust/src/frb_generated.rs @@ -32,9 +32,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, ); pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.5.1"; pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 1774582320; @@ -47,30 +47,18 @@ flutter_rust_bridge::frb_generated_default_handler!(); fn wire__crate__api__image_processing__process_yolo_face_impl( port_: flutter_rust_bridge::for_generated::MessagePort, - ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, - rust_vec_len_: i32, - data_len_: i32, + image_path: impl CstDecode, ) { - FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( flutter_rust_bridge::for_generated::TaskInfo { debug_name: "process_yolo_face", 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_image_path = ::sse_decode(&mut deserializer); - deserializer.end(); + let api_image_path = image_path.cst_decode(); move |context| { - transform_result_sse::<_, ()>((move || { + transform_result_dco::<_, _, ()>((move || { let output_ok = Result::<_, ()>::Ok( crate::api::image_processing::process_yolo_face(&api_image_path), )?; @@ -81,60 +69,33 @@ fn wire__crate__api__image_processing__process_yolo_face_impl( ) } fn wire__crate__api__simple__greet_impl( - ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, - rust_vec_len_: i32, - data_len_: i32, -) -> flutter_rust_bridge::for_generated::WireSyncRust2DartSse { - FLUTTER_RUST_BRIDGE_HANDLER.wrap_sync::( + name: impl CstDecode, +) -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_sync::( flutter_rust_bridge::for_generated::TaskInfo { debug_name: "greet", port: None, mode: flutter_rust_bridge::for_generated::FfiCallMode::Sync, }, 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_name = ::sse_decode(&mut deserializer); - deserializer.end(); - transform_result_sse::<_, ()>((move || { + let api_name = name.cst_decode(); + transform_result_dco::<_, _, ()>((move || { let output_ok = Result::<_, ()>::Ok(crate::api::simple::greet(api_name))?; Ok(output_ok) })()) }, ) } -fn wire__crate__api__simple__init_app_impl( - port_: flutter_rust_bridge::for_generated::MessagePort, - ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, - rust_vec_len_: i32, - data_len_: i32, -) { - FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( +fn wire__crate__api__simple__init_app_impl(port_: flutter_rust_bridge::for_generated::MessagePort) { + FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( flutter_rust_bridge::for_generated::TaskInfo { debug_name: "init_app", 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); - deserializer.end(); move |context| { - transform_result_sse::<_, ()>((move || { + transform_result_dco::<_, _, ()>((move || { let output_ok = Result::<_, ()>::Ok({ crate::api::simple::init_app(); })?; @@ -147,6 +108,12 @@ fn wire__crate__api__simple__init_app_impl( // Section: dart2rust +impl CstDecode for u8 { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> u8 { + self + } +} impl SseDecode for String { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -167,6 +134,15 @@ impl SseDecode for Vec { } } +impl SseDecode for (Vec, String) { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut var_field0 = >::sse_decode(deserializer); + let mut var_field1 = ::sse_decode(deserializer); + return (var_field0, var_field1); + } +} + impl SseDecode for u8 { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -202,13 +178,6 @@ fn pde_ffi_dispatcher_primary_impl( ) { // Codec=Pde (Serialization + dispatch), see doc to use other codecs match func_id { - 1 => wire__crate__api__image_processing__process_yolo_face_impl( - port, - ptr, - rust_vec_len, - data_len, - ), - 3 => wire__crate__api__simple__init_app_impl(port, ptr, rust_vec_len, data_len), _ => unreachable!(), } } @@ -221,7 +190,6 @@ fn pde_ffi_dispatcher_sync_impl( ) -> flutter_rust_bridge::for_generated::WireSyncRust2DartSse { // Codec=Pde (Serialization + dispatch), see doc to use other codecs match func_id { - 2 => wire__crate__api__simple__greet_impl(ptr, rust_vec_len, data_len), _ => unreachable!(), } } @@ -245,6 +213,14 @@ impl SseEncode for Vec { } } +impl SseEncode for (Vec, String) { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + >::sse_encode(self.0, serializer); + ::sse_encode(self.1, serializer); + } +} + impl SseEncode for u8 { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { @@ -288,30 +264,88 @@ mod io { // 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) -> String { + let vec: Vec = self.cst_decode(); + String::from_utf8(vec).unwrap() + } + } + 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<(Vec, String)> for wire_cst_record_list_prim_u_8_strict_string { + // Codec=Cst (C-struct based), see doc to use other codecs + fn cst_decode(self) -> (Vec, String) { + (self.field0.cst_decode(), self.field1.cst_decode()) + } + } + impl NewWithNullPtr for wire_cst_record_list_prim_u_8_strict_string { + fn new_with_null_ptr() -> Self { + Self { + field0: core::ptr::null_mut(), + field1: core::ptr::null_mut(), + } + } + } + impl Default for wire_cst_record_list_prim_u_8_strict_string { + fn default() -> Self { + Self::new_with_null_ptr() + } + } + + #[no_mangle] + pub extern "C" fn frbgen_photos_wire__crate__api__image_processing__process_yolo_face( + port_: i64, + image_path: *mut wire_cst_list_prim_u_8_strict, + ) { + wire__crate__api__image_processing__process_yolo_face_impl(port_, image_path) + } + + #[no_mangle] + pub extern "C" fn frbgen_photos_wire__crate__api__simple__greet( + name: *mut wire_cst_list_prim_u_8_strict, + ) -> flutter_rust_bridge::for_generated::WireSyncRust2DartDco { + wire__crate__api__simple__greet_impl(name) + } + + #[no_mangle] + pub extern "C" fn frbgen_photos_wire__crate__api__simple__init_app(port_: i64) { + wire__crate__api__simple__init_app_impl(port_) + } + + #[no_mangle] + pub extern "C" fn frbgen_photos_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) + } + + #[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_record_list_prim_u_8_strict_string { + field0: *mut wire_cst_list_prim_u_8_strict, + field1: *mut wire_cst_list_prim_u_8_strict, + } } #[cfg(not(target_family = "wasm"))] pub use io::*; - -/// cbindgen:ignore -#[cfg(target_family = "wasm")] -mod web { - // This file is automatically generated, so please do not edit it. - // @generated by `flutter_rust_bridge`@ 2.5.1. - - // Section: imports - - use super::*; - use flutter_rust_bridge::for_generated::byteorder::{ - NativeEndian, ReadBytesExt, WriteBytesExt, - }; - use flutter_rust_bridge::for_generated::wasm_bindgen; - use flutter_rust_bridge::for_generated::wasm_bindgen::prelude::*; - use flutter_rust_bridge::for_generated::{transform_result_dco, Lifetimeable, Lockable}; - use flutter_rust_bridge::{Handler, IntoIntoDart}; - - // Section: boilerplate - - flutter_rust_bridge::frb_generated_boilerplate_web!(); -} -#[cfg(target_family = "wasm")] -pub use web::*;