From 39c01d17615b49d7a8b3cb2510477b7407e530fa Mon Sep 17 00:00:00 2001 From: Tien Do Nam Date: Fri, 23 Aug 2024 17:20:07 +0200 Subject: [PATCH] refactor: move stream to extra rust file --- lib/src/request.dart | 5 +- lib/src/rust/api/http.dart | 12 +- lib/src/rust/api/stream.dart | 20 +++ lib/src/rust/frb_generated.dart | 137 ++++++++--------- lib/src/rust/frb_generated.io.dart | 1 + lib/src/rust/frb_generated.web.dart | 1 + rust/src/api/http.rs | 39 +---- rust/src/api/mod.rs | 1 + rust/src/api/stream.rs | 28 ++++ rust/src/frb_generated.rs | 225 ++++++++++++++-------------- 10 files changed, 245 insertions(+), 224 deletions(-) create mode 100644 lib/src/rust/api/stream.dart create mode 100644 rust/src/api/stream.rs diff --git a/lib/src/request.dart b/lib/src/request.dart index bbd7f20..5719945 100644 --- a/lib/src/request.dart +++ b/lib/src/request.dart @@ -10,6 +10,7 @@ import 'package:rhttp/src/model/response.dart'; import 'package:rhttp/src/model/settings.dart'; import 'package:rhttp/src/rust/api/error.dart' as rust_error; import 'package:rhttp/src/rust/api/http.dart' as rust; +import 'package:rhttp/src/rust/api/stream.dart' as rust_stream; import 'package:rhttp/src/util/stream_listener.dart'; /// Non-Generated helper function that is used by @@ -41,10 +42,10 @@ Future requestInternalGeneric(HttpRequest request) async { body: request.body, ); - final rust.Dart2RustStreamReceiver? bodyStream; + final rust_stream.Dart2RustStreamReceiver? bodyStream; if (request.body is HttpBodyBytesStream) { final stream = (request.body as HttpBodyBytesStream).stream; - final (sender, receiver) = await rust.createStream(); + final (sender, receiver) = await rust_stream.createStream(); listenToStreamWithBackpressure( stream: stream, onData: (data) async => await sender.add(data: data), diff --git a/lib/src/rust/api/http.dart b/lib/src/rust/api/http.dart index b188038..eb0e56e 100644 --- a/lib/src/rust/api/http.dart +++ b/lib/src/rust/api/http.dart @@ -8,15 +8,13 @@ import 'client.dart'; import 'error.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; import 'package:freezed_annotation/freezed_annotation.dart' hide protected; +import 'stream.dart'; part 'http.freezed.dart'; // These functions are ignored because they are not marked as `pub`: `build_cancel_tokens`, `from_version`, `header_to_vec`, `make_http_request_helper`, `make_http_request_inner`, `make_http_request_receive_stream_inner`, `register_client_internal`, `to_method` // These types are ignored because they are not used by any `pub` functions: `RequestCancelTokens` // These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `clone`, `clone`, `fmt` -Future<(Dart2RustStreamSink, Dart2RustStreamReceiver)> createStream() => - RustLib.instance.api.crateApiHttpCreateStream(); - Future registerClient({required ClientSettings settings}) => RustLib.instance.api.crateApiHttpRegisterClient(settings: settings); @@ -84,14 +82,6 @@ Stream makeHttpRequestReceiveStream( Future cancelRequest({required PlatformInt64 address}) => RustLib.instance.api.crateApiHttpCancelRequest(address: address); -// Rust type: RustOpaqueMoi> -abstract class Dart2RustStreamReceiver implements RustOpaqueInterface {} - -// Rust type: RustOpaqueMoi> -abstract class Dart2RustStreamSink implements RustOpaqueInterface { - Future add({required int data}); -} - @freezed sealed class HttpBody with _$HttpBody { const HttpBody._(); diff --git a/lib/src/rust/api/stream.dart b/lib/src/rust/api/stream.dart new file mode 100644 index 0000000..73ac099 --- /dev/null +++ b/lib/src/rust/api/stream.dart @@ -0,0 +1,20 @@ +// This file is automatically generated, so please do not edit it. +// Generated by `flutter_rust_bridge`@ 2.3.0. + +// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import + +import '../frb_generated.dart'; +import 'error.dart'; +import 'http.dart'; +import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; + +Future<(Dart2RustStreamSink, Dart2RustStreamReceiver)> createStream() => + RustLib.instance.api.crateApiStreamCreateStream(); + +// Rust type: RustOpaqueMoi> +abstract class Dart2RustStreamReceiver implements RustOpaqueInterface {} + +// Rust type: RustOpaqueMoi> +abstract class Dart2RustStreamSink implements RustOpaqueInterface { + Future add({required int data}); +} diff --git a/lib/src/rust/frb_generated.dart b/lib/src/rust/frb_generated.dart index 71a4d22..ec3f194 100644 --- a/lib/src/rust/frb_generated.dart +++ b/lib/src/rust/frb_generated.dart @@ -6,6 +6,7 @@ import 'api/client.dart'; import 'api/error.dart'; import 'api/http.dart'; +import 'api/stream.dart'; import 'dart:async'; import 'dart:convert'; import 'frb_generated.dart'; @@ -70,7 +71,7 @@ class RustLib extends BaseEntrypoint { String get codegenVersion => '2.3.0'; @override - int get rustContentHash => 1538750230; + int get rustContentHash => -2112869887; static const kDefaultExternalLibraryLoaderConfig = ExternalLibraryLoaderConfig( @@ -83,14 +84,8 @@ class RustLib extends BaseEntrypoint { abstract class RustLibApi extends BaseApi { Future crateApiClientClientSettingsDefault(); - Future crateApiHttpDart2RustStreamSinkAdd( - {required Dart2RustStreamSink that, required int data}); - Future crateApiHttpCancelRequest({required PlatformInt64 address}); - Future<(Dart2RustStreamSink, Dart2RustStreamReceiver)> - crateApiHttpCreateStream(); - Future crateApiHttpMakeHttpRequest( {PlatformInt64? clientAddress, ClientSettings? settings, @@ -129,6 +124,12 @@ abstract class RustLibApi extends BaseApi { Future crateApiInitInitApp(); + Future crateApiStreamDart2RustStreamSinkAdd( + {required Dart2RustStreamSink that, required int data}); + + Future<(Dart2RustStreamSink, Dart2RustStreamReceiver)> + crateApiStreamCreateStream(); + RustArcIncrementStrongCountFnType get rust_arc_increment_strong_count_Dart2RustStreamReceiver; @@ -180,34 +181,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: [], ); - @override - Future crateApiHttpDart2RustStreamSinkAdd( - {required Dart2RustStreamSink that, required int data}) { - return handler.executeNormal(NormalTask( - callFfi: (port_) { - final serializer = SseSerializer(generalizedFrbRustBinding); - sse_encode_Auto_RefMut_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerDart2RustStreamSink( - that, serializer); - sse_encode_u_8(data, serializer); - pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 2, port: port_); - }, - codec: SseCodec( - decodeSuccessData: sse_decode_unit, - decodeErrorData: sse_decode_rhttp_error, - ), - constMeta: kCrateApiHttpDart2RustStreamSinkAddConstMeta, - argValues: [that, data], - apiImpl: this, - )); - } - - TaskConstMeta get kCrateApiHttpDart2RustStreamSinkAddConstMeta => - const TaskConstMeta( - debugName: "Dart2RustStreamSink_add", - argNames: ["that", "data"], - ); - @override Future crateApiHttpCancelRequest({required PlatformInt64 address}) { return handler.executeNormal(NormalTask( @@ -215,7 +188,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { final serializer = SseSerializer(generalizedFrbRustBinding); sse_encode_i_64(address, serializer); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 3, port: port_); + funcId: 2, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_bool, @@ -232,31 +205,6 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: ["address"], ); - @override - Future<(Dart2RustStreamSink, Dart2RustStreamReceiver)> - crateApiHttpCreateStream() { - return handler.executeNormal(NormalTask( - callFfi: (port_) { - final serializer = SseSerializer(generalizedFrbRustBinding); - pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 4, port: port_); - }, - codec: SseCodec( - decodeSuccessData: - sse_decode_record_auto_owned_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_dart_2_rust_stream_sink_auto_owned_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_dart_2_rust_stream_receiver, - decodeErrorData: null, - ), - constMeta: kCrateApiHttpCreateStreamConstMeta, - argValues: [], - apiImpl: this, - )); - } - - TaskConstMeta get kCrateApiHttpCreateStreamConstMeta => const TaskConstMeta( - debugName: "create_stream", - argNames: [], - ); - @override Future crateApiHttpMakeHttpRequest( {PlatformInt64? clientAddress, @@ -287,7 +235,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { onCancelToken, serializer); sse_encode_bool(cancelable, serializer); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 5, port: port_); + funcId: 3, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_http_response, @@ -365,7 +313,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { onCancelToken, serializer); sse_encode_bool(cancelable, serializer); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 6, port: port_); + funcId: 4, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -420,7 +368,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { final serializer = SseSerializer(generalizedFrbRustBinding); sse_encode_box_autoadd_client_settings(settings, serializer); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 7, port: port_); + funcId: 5, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_i_64, @@ -444,7 +392,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { callFfi: () { final serializer = SseSerializer(generalizedFrbRustBinding); sse_encode_box_autoadd_client_settings(settings, serializer); - return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 8)!; + return pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 6)!; }, codec: SseCodec( decodeSuccessData: sse_decode_i_64, @@ -471,7 +419,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { sse_encode_i_64(address, serializer); sse_encode_bool(cancelRunningRequests, serializer); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 9, port: port_); + funcId: 7, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -494,7 +442,7 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { callFfi: (port_) { final serializer = SseSerializer(generalizedFrbRustBinding); pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 10, port: port_); + funcId: 8, port: port_); }, codec: SseCodec( decodeSuccessData: sse_decode_unit, @@ -511,6 +459,59 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { argNames: [], ); + @override + Future crateApiStreamDart2RustStreamSinkAdd( + {required Dart2RustStreamSink that, required int data}) { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_Auto_RefMut_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerDart2RustStreamSink( + that, serializer); + sse_encode_u_8(data, serializer); + pdeCallFfi(generalizedFrbRustBinding, serializer, + funcId: 9, port: port_); + }, + codec: SseCodec( + decodeSuccessData: sse_decode_unit, + decodeErrorData: sse_decode_rhttp_error, + ), + constMeta: kCrateApiStreamDart2RustStreamSinkAddConstMeta, + argValues: [that, data], + apiImpl: this, + )); + } + + TaskConstMeta get kCrateApiStreamDart2RustStreamSinkAddConstMeta => + const TaskConstMeta( + debugName: "Dart2RustStreamSink_add", + argNames: ["that", "data"], + ); + + @override + Future<(Dart2RustStreamSink, Dart2RustStreamReceiver)> + crateApiStreamCreateStream() { + return handler.executeNormal(NormalTask( + callFfi: (port_) { + final serializer = SseSerializer(generalizedFrbRustBinding); + pdeCallFfi(generalizedFrbRustBinding, serializer, + funcId: 10, port: port_); + }, + codec: SseCodec( + decodeSuccessData: + sse_decode_record_auto_owned_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_dart_2_rust_stream_sink_auto_owned_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_dart_2_rust_stream_receiver, + decodeErrorData: null, + ), + constMeta: kCrateApiStreamCreateStreamConstMeta, + argValues: [], + apiImpl: this, + )); + } + + TaskConstMeta get kCrateApiStreamCreateStreamConstMeta => const TaskConstMeta( + debugName: "create_stream", + argNames: [], + ); + Future Function(int, dynamic) encode_DartFn_Inputs_http_response_Output_unit_AnyhowException( FutureOr Function(HttpResponse) raw) { @@ -2607,5 +2608,5 @@ class Dart2RustStreamSinkImpl extends RustOpaque ); Future add({required int data}) => RustLib.instance.api - .crateApiHttpDart2RustStreamSinkAdd(that: this, data: data); + .crateApiStreamDart2RustStreamSinkAdd(that: this, data: data); } diff --git a/lib/src/rust/frb_generated.io.dart b/lib/src/rust/frb_generated.io.dart index 55ef9a8..6cd9230 100644 --- a/lib/src/rust/frb_generated.io.dart +++ b/lib/src/rust/frb_generated.io.dart @@ -6,6 +6,7 @@ import 'api/client.dart'; import 'api/error.dart'; import 'api/http.dart'; +import 'api/stream.dart'; import 'dart:async'; import 'dart:convert'; import 'dart:ffi' as ffi; diff --git a/lib/src/rust/frb_generated.web.dart b/lib/src/rust/frb_generated.web.dart index fcb9262..a969d55 100644 --- a/lib/src/rust/frb_generated.web.dart +++ b/lib/src/rust/frb_generated.web.dart @@ -9,6 +9,7 @@ import 'api/client.dart'; import 'api/error.dart'; import 'api/http.dart'; +import 'api/stream.dart'; import 'dart:async'; import 'dart:convert'; import 'frb_generated.dart'; diff --git a/rust/src/api/http.rs b/rust/src/api/http.rs index 4937e06..3cc15b3 100644 --- a/rust/src/api/http.rs +++ b/rust/src/api/http.rs @@ -1,6 +1,5 @@ -use flutter_rust_bridge::for_generated::futures::channel::mpsc; use flutter_rust_bridge::{frb, DartFnFuture}; -use futures_util::{SinkExt, StreamExt}; +use futures_util::StreamExt; use reqwest::header::{HeaderName, HeaderValue}; use reqwest::{Method, Response, Url, Version}; use std::collections::HashMap; @@ -10,6 +9,7 @@ use tokio_util::sync::CancellationToken; use crate::api::client::{ClientSettings, RequestClient}; use crate::api::error::RhttpError; +use crate::api::stream; use crate::api::{client_pool, request_pool}; use crate::frb_generated::StreamSink; @@ -123,31 +123,6 @@ pub enum HttpResponseBody { Stream, } -pub struct Dart2RustStreamSink { - sender: mpsc::Sender>, -} - -pub struct Dart2RustStreamReceiver { - receiver: mpsc::Receiver>, -} - -pub fn create_stream() -> (Dart2RustStreamSink, Dart2RustStreamReceiver) { - let (sender, receiver) = mpsc::channel(16 * 1024); // 16KB buffer - ( - Dart2RustStreamSink { sender }, - Dart2RustStreamReceiver { receiver }, - ) -} - -impl Dart2RustStreamSink { - pub async fn add(&mut self, data: u8) -> Result<(), RhttpError> { - self.sender - .send(vec![data]) - .await - .map_err(|_| RhttpError::RhttpUnknownError("Failed to send data".to_string())) - } -} - // It must be async so that frb provides an async context. pub async fn register_client(settings: ClientSettings) -> Result { register_client_internal(settings) @@ -182,7 +157,7 @@ pub async fn make_http_request( query: Option>, headers: Option, body: Option, - body_stream: Option, + body_stream: Option, expect_body: HttpExpectBody, on_cancel_token: impl Fn(i64) -> DartFnFuture<()>, cancelable: bool, @@ -245,7 +220,7 @@ async fn make_http_request_inner( query: Option>, headers: Option, body: Option, - body_stream: Option, + body_stream: Option, expect_body: HttpExpectBody, ) -> Result { let response = make_http_request_helper( @@ -291,7 +266,7 @@ pub async fn make_http_request_receive_stream( query: Option>, headers: Option, body: Option, - body_stream: Option, + body_stream: Option, stream_sink: StreamSink>, on_response: impl Fn(HttpResponse) -> DartFnFuture<()>, on_error: impl Fn(RhttpError) -> DartFnFuture<()>, @@ -336,7 +311,7 @@ async fn make_http_request_receive_stream_inner( query: Option>, headers: Option, body: Option, - body_stream: Option, + body_stream: Option, stream_sink: StreamSink>, on_response: impl Fn(HttpResponse) -> DartFnFuture<()>, on_error: impl Fn(RhttpError) -> DartFnFuture<()>, @@ -397,7 +372,7 @@ async fn make_http_request_helper( query: Option>, headers: Option, body: Option, - body_stream: Option, + body_stream: Option, expect_body: Option, ) -> Result { let client: RequestClient = match client_address { diff --git a/rust/src/api/mod.rs b/rust/src/api/mod.rs index 838b6da..d09d689 100644 --- a/rust/src/api/mod.rs +++ b/rust/src/api/mod.rs @@ -4,3 +4,4 @@ pub mod error; pub mod http; pub mod init; pub mod request_pool; +pub mod stream; diff --git a/rust/src/api/stream.rs b/rust/src/api/stream.rs new file mode 100644 index 0000000..b777723 --- /dev/null +++ b/rust/src/api/stream.rs @@ -0,0 +1,28 @@ +use crate::api::error::RhttpError; +use flutter_rust_bridge::for_generated::futures::channel::mpsc; +use futures_util::SinkExt; + +pub struct Dart2RustStreamSink { + sender: mpsc::Sender>, +} + +pub struct Dart2RustStreamReceiver { + pub(crate) receiver: mpsc::Receiver>, +} + +pub fn create_stream() -> (Dart2RustStreamSink, Dart2RustStreamReceiver) { + let (sender, receiver) = mpsc::channel(16 * 1024); // 16KB buffer + ( + Dart2RustStreamSink { sender }, + Dart2RustStreamReceiver { receiver }, + ) +} + +impl Dart2RustStreamSink { + pub async fn add(&mut self, data: u8) -> Result<(), RhttpError> { + self.sender + .send(vec![data]) + .await + .map_err(|_| RhttpError::RhttpUnknownError("Failed to send data".to_string())) + } +} diff --git a/rust/src/frb_generated.rs b/rust/src/frb_generated.rs index 40c522e..7e50143 100644 --- a/rust/src/frb_generated.rs +++ b/rust/src/frb_generated.rs @@ -25,7 +25,7 @@ // Section: imports -use crate::api::http::*; +use crate::api::stream::*; use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt}; use flutter_rust_bridge::for_generated::{transform_result_dco, Lifetimeable, Lockable}; use flutter_rust_bridge::{Handler, IntoIntoDart}; @@ -38,7 +38,7 @@ flutter_rust_bridge::frb_generated_boilerplate!( default_rust_auto_opaque = RustAutoOpaqueMoi, ); pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.3.0"; -pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 1538750230; +pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = -2112869887; // Section: executor @@ -79,66 +79,6 @@ fn wire__crate__api__client__client_settings_default_impl( }, ) } -fn wire__crate__api__http__Dart2RustStreamSink_add_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_async::( - flutter_rust_bridge::for_generated::TaskInfo { - debug_name: "Dart2RustStreamSink_add", - 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_that = , - >>::sse_decode(&mut deserializer); - let api_data = ::sse_decode(&mut deserializer); - deserializer.end(); - move |context| async move { - transform_result_sse::<_, crate::api::error::RhttpError>( - (move || async move { - let mut api_that_guard = None; - let decode_indices_ = - flutter_rust_bridge::for_generated::lockable_compute_decode_order( - vec![flutter_rust_bridge::for_generated::LockableOrderInfo::new( - &api_that, 0, true, - )], - ); - for i in decode_indices_ { - match i { - 0 => { - api_that_guard = - Some(api_that.lockable_decode_async_ref_mut().await) - } - _ => unreachable!(), - } - } - let mut api_that_guard = api_that_guard.unwrap(); - let output_ok = crate::api::http::Dart2RustStreamSink::add( - &mut *api_that_guard, - api_data, - ) - .await?; - Ok(output_ok) - })() - .await, - ) - } - }, - ) -} fn wire__crate__api__http__cancel_request_impl( port_: flutter_rust_bridge::for_generated::MessagePort, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, @@ -173,38 +113,6 @@ fn wire__crate__api__http__cancel_request_impl( }, ) } -fn wire__crate__api__http__create_stream_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::( - flutter_rust_bridge::for_generated::TaskInfo { - debug_name: "create_stream", - 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 || { - let output_ok = Result::<_, ()>::Ok(crate::api::http::create_stream())?; - Ok(output_ok) - })()) - } - }, - ) -} fn wire__crate__api__http__make_http_request_impl( port_: flutter_rust_bridge::for_generated::MessagePort, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, @@ -478,6 +386,98 @@ fn wire__crate__api__init__init_app_impl( }, ) } +fn wire__crate__api__stream__Dart2RustStreamSink_add_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_async::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "Dart2RustStreamSink_add", + 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_that = , + >>::sse_decode(&mut deserializer); + let api_data = ::sse_decode(&mut deserializer); + deserializer.end(); + move |context| async move { + transform_result_sse::<_, crate::api::error::RhttpError>( + (move || async move { + let mut api_that_guard = None; + let decode_indices_ = + flutter_rust_bridge::for_generated::lockable_compute_decode_order( + vec![flutter_rust_bridge::for_generated::LockableOrderInfo::new( + &api_that, 0, true, + )], + ); + for i in decode_indices_ { + match i { + 0 => { + api_that_guard = + Some(api_that.lockable_decode_async_ref_mut().await) + } + _ => unreachable!(), + } + } + let mut api_that_guard = api_that_guard.unwrap(); + let output_ok = crate::api::stream::Dart2RustStreamSink::add( + &mut *api_that_guard, + api_data, + ) + .await?; + Ok(output_ok) + })() + .await, + ) + } + }, + ) +} +fn wire__crate__api__stream__create_stream_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::( + flutter_rust_bridge::for_generated::TaskInfo { + debug_name: "create_stream", + 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 || { + let output_ok = Result::<_, ()>::Ok(crate::api::stream::create_stream())?; + Ok(output_ok) + })()) + } + }, + ) +} // Section: related_funcs @@ -1281,21 +1281,24 @@ fn pde_ffi_dispatcher_primary_impl( rust_vec_len, data_len, ), - 2 => { - wire__crate__api__http__Dart2RustStreamSink_add_impl(port, ptr, rust_vec_len, data_len) - } - 3 => wire__crate__api__http__cancel_request_impl(port, ptr, rust_vec_len, data_len), - 4 => wire__crate__api__http__create_stream_impl(port, ptr, rust_vec_len, data_len), - 5 => wire__crate__api__http__make_http_request_impl(port, ptr, rust_vec_len, data_len), - 6 => wire__crate__api__http__make_http_request_receive_stream_impl( + 2 => wire__crate__api__http__cancel_request_impl(port, ptr, rust_vec_len, data_len), + 3 => wire__crate__api__http__make_http_request_impl(port, ptr, rust_vec_len, data_len), + 4 => wire__crate__api__http__make_http_request_receive_stream_impl( + port, + ptr, + rust_vec_len, + data_len, + ), + 5 => wire__crate__api__http__register_client_impl(port, ptr, rust_vec_len, data_len), + 7 => wire__crate__api__http__remove_client_impl(port, ptr, rust_vec_len, data_len), + 8 => wire__crate__api__init__init_app_impl(port, ptr, rust_vec_len, data_len), + 9 => wire__crate__api__stream__Dart2RustStreamSink_add_impl( port, ptr, rust_vec_len, data_len, ), - 7 => wire__crate__api__http__register_client_impl(port, ptr, rust_vec_len, data_len), - 9 => wire__crate__api__http__remove_client_impl(port, ptr, rust_vec_len, data_len), - 10 => wire__crate__api__init__init_app_impl(port, ptr, rust_vec_len, data_len), + 10 => wire__crate__api__stream__create_stream_impl(port, ptr, rust_vec_len, data_len), _ => unreachable!(), } } @@ -1308,7 +1311,7 @@ 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 { - 8 => wire__crate__api__http__register_client_sync_impl(ptr, rust_vec_len, data_len), + 6 => wire__crate__api__http__register_client_sync_impl(ptr, rust_vec_len, data_len), _ => unreachable!(), } } @@ -2401,7 +2404,7 @@ mod io { // Section: imports use super::*; - use crate::api::http::*; + use crate::api::stream::*; use flutter_rust_bridge::for_generated::byteorder::{ NativeEndian, ReadBytesExt, WriteBytesExt, }; @@ -2416,14 +2419,14 @@ mod io { pub extern "C" fn frbgen_rhttp_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerDart2RustStreamReceiver( ptr: *const std::ffi::c_void, ) { - MoiArc::>::increment_strong_count(ptr as _); + MoiArc::>::increment_strong_count(ptr as _); } #[no_mangle] pub extern "C" fn frbgen_rhttp_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerDart2RustStreamReceiver( ptr: *const std::ffi::c_void, ) { - MoiArc::>::decrement_strong_count(ptr as _); + MoiArc::>::decrement_strong_count(ptr as _); } #[no_mangle] @@ -2452,7 +2455,7 @@ mod web { // Section: imports use super::*; - use crate::api::http::*; + use crate::api::stream::*; use flutter_rust_bridge::for_generated::byteorder::{ NativeEndian, ReadBytesExt, WriteBytesExt, }; @@ -2469,14 +2472,14 @@ mod web { pub fn rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerDart2RustStreamReceiver( ptr: *const std::ffi::c_void, ) { - MoiArc::>::increment_strong_count(ptr as _); + MoiArc::>::increment_strong_count(ptr as _); } #[wasm_bindgen] pub fn rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerDart2RustStreamReceiver( ptr: *const std::ffi::c_void, ) { - MoiArc::>::decrement_strong_count(ptr as _); + MoiArc::>::decrement_strong_count(ptr as _); } #[wasm_bindgen]