Skip to content

Commit

Permalink
Merge pull request #406 from dora-rs/fix-cxx-node-input
Browse files Browse the repository at this point in the history
Fix read error in C++ node input
  • Loading branch information
phil-opp authored Jan 4, 2024
2 parents 4330709 + 06a7d0b commit d97e034
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
28 changes: 15 additions & 13 deletions apis/c/node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![deny(unsafe_op_in_unsafe_fn)]

use arrow_array::BinaryArray;
use arrow_array::UInt8Array;
use dora_node_api::{arrow::array::AsArray, DoraNode, Event, EventStream};
use eyre::Context;
use std::{ffi::c_void, ptr, slice};
Expand Down Expand Up @@ -170,22 +170,24 @@ pub unsafe extern "C" fn read_dora_input_data(
) {
let event: &Event = unsafe { &*event.cast() };
match event {
Event::Input { data, .. } => {
let data: Option<&BinaryArray> = data.as_binary_opt();
if let Some(data) = data {
let ptr = data.value(0).as_ptr();
let len = data.value(0).len();
Event::Input { data, metadata, .. } => match metadata.type_info.data_type {
dora_node_api::arrow::datatypes::DataType::UInt8 => {
let array: &UInt8Array = data.as_primitive();
let ptr = array.values().as_ptr();
unsafe {
*out_ptr = ptr;
*out_len = len;
}
} else {
unsafe {
*out_ptr = ptr::null();
*out_len = 0;
*out_len = metadata.type_info.len;
}
}
}
dora_node_api::arrow::datatypes::DataType::Null => unsafe {
*out_ptr = ptr::null();
*out_len = 0;
},
_ => {
todo!("dora C++ Node does not yet support higher level type of arrow. Only UInt8.
The ultimate solution should be based on arrow FFI interface. Feel free to contribute :)")
}
},
_ => unsafe {
*out_ptr = ptr::null();
*out_len = 0;
Expand Down
2 changes: 1 addition & 1 deletion examples/c++-dataflow/dataflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ nodes:
custom:
source: build/node_c_api
inputs:
tick: dora/timer/millis/300
tick: cxx-node-rust-api/counter
outputs:
- counter

Expand Down

0 comments on commit d97e034

Please sign in to comment.