martinzink commented on code in PR #2186:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2186#discussion_r3654705035


##########
minifi_rust/minifi_native/src/c_ffi/c_ffi_process_session.rs:
##########
@@ -0,0 +1,580 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use super::c_ffi_flow_file::CffiFlowFile;
+use crate::MinifiError;
+use crate::api::process_session::{IoState, OutputStream};
+use crate::api::{InputStream, ProcessSession};
+use crate::c_ffi::c_ffi_primitives::{ConvertMinifiStringView, StringView};
+use crate::c_ffi::c_ffi_streams::{CffiInputStream, CffiOutputStream};
+use minifi_native_sys::{
+    minifi_input_stream, minifi_input_stream_read, minifi_input_stream_size,
+    minifi_io_status_MINIFI_IO_CANCEL, minifi_io_status_MINIFI_IO_ERROR, 
minifi_output_stream,
+    minifi_output_stream_write, minifi_process_session, 
minifi_process_session_create,
+    minifi_process_session_get, minifi_process_session_get_flow_file_attribute,
+    minifi_process_session_get_flow_file_attributes, 
minifi_process_session_get_flow_file_id,
+    minifi_process_session_read, minifi_process_session_remove,
+    minifi_process_session_set_flow_file_attribute, 
minifi_process_session_transfer,
+    minifi_process_session_write, minifi_status_MINIFI_STATUS_SUCCESS, 
minifi_string_view,
+};
+use std::ffi::{CString, c_void};
+use std::io::Read;
+use std::num::NonZeroU32;
+use std::os::raw::c_char;
+
+const _: () = {
+    if minifi_status_MINIFI_STATUS_SUCCESS != 0 {
+        panic!("minifi_status_MINIFI_STATUS_SUCCESS expected to be 0");
+    }
+};
+
+unsafe fn write_all_to_output_stream(
+    output_stream: *mut minifi_output_stream,
+    data: &[u8],
+) -> Result<i64, i64> {
+    let mut offset = 0;
+    while offset < data.len() {
+        let remaining = data.len() - offset;
+        let written = unsafe {
+            minifi_output_stream_write(
+                output_stream,
+                data.as_ptr().add(offset) as *const c_char,
+                remaining,
+            )
+        };
+        if written < 0 {
+            return Err(written);
+        }
+        if written == 0 {
+            return Err(minifi_io_status_MINIFI_IO_ERROR); // To avoid 
spinning, but not sure about it
+        }
+        let written_usize = written as usize;
+        if written_usize > remaining {
+            return Err(minifi_io_status_MINIFI_IO_ERROR);
+        }

Review Comment:
   
https://github.com/apache/nifi-minifi-cpp/pull/2186/changes/6bd47c8d6de571003ab57eb6f123b6ffd17c9c9b#diff-f7280f037c756b7c91ee34b1cb0bd0e134e7ae053242a7146439227742513f95R66



##########
minifi_rust/minifi_native/src/c_ffi/c_ffi_process_session.rs:
##########
@@ -0,0 +1,580 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   https://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use super::c_ffi_flow_file::CffiFlowFile;
+use crate::MinifiError;
+use crate::api::process_session::{IoState, OutputStream};
+use crate::api::{InputStream, ProcessSession};
+use crate::c_ffi::c_ffi_primitives::{ConvertMinifiStringView, StringView};
+use crate::c_ffi::c_ffi_streams::{CffiInputStream, CffiOutputStream};
+use minifi_native_sys::{
+    minifi_input_stream, minifi_input_stream_read, minifi_input_stream_size,
+    minifi_io_status_MINIFI_IO_CANCEL, minifi_io_status_MINIFI_IO_ERROR, 
minifi_output_stream,
+    minifi_output_stream_write, minifi_process_session, 
minifi_process_session_create,
+    minifi_process_session_get, minifi_process_session_get_flow_file_attribute,
+    minifi_process_session_get_flow_file_attributes, 
minifi_process_session_get_flow_file_id,
+    minifi_process_session_read, minifi_process_session_remove,
+    minifi_process_session_set_flow_file_attribute, 
minifi_process_session_transfer,
+    minifi_process_session_write, minifi_status_MINIFI_STATUS_SUCCESS, 
minifi_string_view,
+};
+use std::ffi::{CString, c_void};
+use std::io::Read;
+use std::num::NonZeroU32;
+use std::os::raw::c_char;
+
+const _: () = {
+    if minifi_status_MINIFI_STATUS_SUCCESS != 0 {
+        panic!("minifi_status_MINIFI_STATUS_SUCCESS expected to be 0");
+    }
+};
+
+unsafe fn write_all_to_output_stream(
+    output_stream: *mut minifi_output_stream,
+    data: &[u8],
+) -> Result<i64, i64> {
+    let mut offset = 0;
+    while offset < data.len() {
+        let remaining = data.len() - offset;
+        let written = unsafe {
+            minifi_output_stream_write(
+                output_stream,
+                data.as_ptr().add(offset) as *const c_char,
+                remaining,
+            )
+        };
+        if written < 0 {
+            return Err(written);
+        }
+        if written == 0 {
+            return Err(minifi_io_status_MINIFI_IO_ERROR); // To avoid 
spinning, but not sure about it
+        }

Review Comment:
   
https://github.com/apache/nifi-minifi-cpp/pull/2186/changes/6bd47c8d6de571003ab57eb6f123b6ffd17c9c9b#diff-f7280f037c756b7c91ee34b1cb0bd0e134e7ae053242a7146439227742513f95R63



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to