diff --git a/native/cpp/CommonCpp/grpc/blob_client/rust/build.rs b/native/cpp/CommonCpp/grpc/blob_client/rust/build.rs --- a/native/cpp/CommonCpp/grpc/blob_client/rust/build.rs +++ b/native/cpp/CommonCpp/grpc/blob_client/rust/build.rs @@ -1,4 +1,6 @@ fn main() { tonic_build::compile_protos("../../protos/blob.proto") .unwrap_or_else(|e| panic!("Failed to compile protos {:?}", e)); + let _cxx_build = + cxx_build::bridge("src/lib.rs").flag_if_supported("-std=c++14"); } diff --git a/native/cpp/CommonCpp/grpc/blob_client/rust/src/lib.rs b/native/cpp/CommonCpp/grpc/blob_client/rust/src/lib.rs --- a/native/cpp/CommonCpp/grpc/blob_client/rust/src/lib.rs +++ b/native/cpp/CommonCpp/grpc/blob_client/rust/src/lib.rs @@ -22,6 +22,33 @@ .unwrap(); } +#[cxx::bridge(namespace = "blob")] +mod ffi { + extern "Rust" { + type UploadState; + type DownloadState; + + fn initialize_upload_state_blocking() -> Result>; + fn start_upload_blocking( + state: &mut Box, + holder: String, + hash: String, + ) -> Result<()>; + fn upload_chunk_blocking( + state: &mut Box, + chunk: &String, + ) -> Result<()>; + fn complete_upload_blocking(client: Box) -> Result; + fn initialize_download_state_blocking( + holder: String, + ) -> Result>; + fn pull_chunk_blocking( + client: &mut Box, + buffer: &mut Vec, + ) -> Result; + } +} + pub struct UploadState { sender: mpsc::UnboundedSender, receiver_task: task::JoinHandle>, @@ -122,9 +149,7 @@ .await .map_err(|e| format!("Can't connect to blob service. Details {}", e))?; - let request = GetRequest { - holder: holder, - }; + let request = GetRequest { holder: holder }; let response_stream = client .get(Request::new(request)) .await @@ -154,3 +179,41 @@ } Ok(false) } + +pub fn initialize_upload_state_blocking() -> Result, String> { + RUNTIME.block_on(initialize_upload_state()) +} + +pub fn start_upload_blocking( + state: &mut Box, + holder: String, + hash: String, +) -> Result<(), String> { + RUNTIME.block_on(start_upload(state, holder, hash)) +} + +pub fn upload_chunk_blocking( + state: &mut Box, + chunk: &String, +) -> Result<(), String> { + RUNTIME.block_on(upload_chunk(state, chunk)) +} + +pub fn complete_upload_blocking( + client: Box, +) -> Result { + RUNTIME.block_on(complete_upload(client)) +} + +pub fn initialize_download_state_blocking( + holder: String, +) -> Result, String> { + RUNTIME.block_on(initialize_download_state(holder)) +} + +pub fn pull_chunk_blocking( + client: &mut Box, + buffer: &mut Vec, +) -> Result { + RUNTIME.block_on(pull_chunk(client, buffer)) +}