diff --git a/apis/c++/node/src/lib.rs b/apis/c++/node/src/lib.rs index e3476de87..fea50fba7 100644 --- a/apis/c++/node/src/lib.rs +++ b/apis/c++/node/src/lib.rs @@ -1,8 +1,8 @@ -use std::any::Any; +use std::{any::Any, vec}; use dora_node_api::{ self, - arrow::array::{AsArray, BinaryArray}, + arrow::array::{AsArray, UInt8Array}, merged::{MergeExternal, MergedEvent}, Event, EventStream, }; @@ -138,18 +138,26 @@ fn event_type(event: &DoraEvent) -> ffi::DoraEventType { } fn event_as_input(event: Box) -> eyre::Result { - let Some(Event::Input { - id, - metadata: _, - data, - }) = event.0 - else { + let Some(Event::Input { id, metadata, data }) = event.0 else { bail!("not an input event"); }; - let data: Option<&BinaryArray> = data.as_binary_opt(); + let data = match metadata.type_info.data_type { + dora_node_api::arrow::datatypes::DataType::UInt8 => { + let array: &UInt8Array = data.as_primitive(); + array.values().to_vec() + } + dora_node_api::arrow::datatypes::DataType::Null => { + vec![] + } + _ => { + 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 :)") + } + }; + Ok(ffi::DoraInput { id: id.into(), - data: data.map(|d| d.value(0).to_owned()).unwrap_or_default(), + data, }) } diff --git a/binaries/cli/src/template/cxx/listener-template.cc b/binaries/cli/src/template/cxx/listener-template.cc index 0f62a8ceb..1871dcc33 100644 --- a/binaries/cli/src/template/cxx/listener-template.cc +++ b/binaries/cli/src/template/cxx/listener-template.cc @@ -23,7 +23,8 @@ int main() { auto input = event_as_input(std::move(event)); auto input_id = input.id; - std::cout << "I heard from " << std::string(input_id) << std::endl; + auto message = std::string(reinterpret_cast(input.data.data()), input.data.size()); + std::cout << "I heard " << message << " from " << std::string(input_id) << std::endl; } else { std::cerr << "Unknown event type " << static_cast(ty) << std::endl;