diff --git a/apis/rust/node/src/node/mod.rs b/apis/rust/node/src/node/mod.rs index d4d78e5d..a301842e 100644 --- a/apis/rust/node/src/node/mod.rs +++ b/apis/rust/node/src/node/mod.rs @@ -84,15 +84,10 @@ impl DoraNode { where F: FnOnce(&mut [u8]), { - let sample = if data_len > 0 { - let mut sample = self.allocate_data_sample(data_len)?; - data(&mut sample); - Some(sample) - } else { - None - }; + let mut sample = self.allocate_data_sample(data_len)?; + data(&mut sample); - self.send_output_sample(output_id, parameters, sample) + self.send_output_sample(output_id, parameters, Some(sample)) } pub fn send_output_sample( diff --git a/binaries/runtime/src/operator/python.rs b/binaries/runtime/src/operator/python.rs index 056b41c4..b94001a5 100644 --- a/binaries/runtime/src/operator/python.rs +++ b/binaries/runtime/src/operator/python.rs @@ -279,31 +279,25 @@ mod callback_impl { py: Python, ) -> Result<()> { let data_len = python_output_len(&data, py)?; - let data = if data_len == 0 { - None - } else { - let mut sample = py.allow_threads(|| { - let (tx, rx) = oneshot::channel(); - self.events_tx - .blocking_send(OperatorEvent::AllocateOutputSample { - len: data_len, - sample: tx, - }) - .map_err(|_| eyre!("failed to send output to runtime"))?; - let sample = rx - .blocking_recv() - .wrap_err("failed to request output sample")? - .wrap_err("failed to allocate output sample")?; - Result::<_, eyre::Report>::Ok(sample) - })?; - - process_python_output(&data, py, |data| { - sample.copy_from_slice(data); - Ok(()) - })?; - - Some(sample) - }; + let mut sample = py.allow_threads(|| { + let (tx, rx) = oneshot::channel(); + self.events_tx + .blocking_send(OperatorEvent::AllocateOutputSample { + len: data_len, + sample: tx, + }) + .map_err(|_| eyre!("failed to send output to runtime"))?; + let sample = rx + .blocking_recv() + .wrap_err("failed to request output sample")? + .wrap_err("failed to allocate output sample")?; + Result::<_, eyre::Report>::Ok(sample) + })?; + + process_python_output(&data, py, |data| { + sample.copy_from_slice(data); + Ok(()) + })?; let metadata = pydict_to_metadata(metadata) .wrap_err("failed to parse metadata")? @@ -312,7 +306,7 @@ mod callback_impl { let event = OperatorEvent::Output { output_id: output.to_owned().into(), metadata, - data, + data: Some(sample), }; py.allow_threads(|| { diff --git a/binaries/runtime/src/operator/shared_lib.rs b/binaries/runtime/src/operator/shared_lib.rs index 7685caa1..1fd93793 100644 --- a/binaries/runtime/src/operator/shared_lib.rs +++ b/binaries/runtime/src/operator/shared_lib.rs @@ -123,11 +123,7 @@ impl<'lib> SharedLibraryOperator<'lib> { let event = OperatorEvent::Output { output_id: DataId::from(String::from(output_id)), metadata, - data: if data.is_empty() { - None - } else { - Some(data.to_owned().into()) - }, + data: Some(data.to_owned().into()), }; let result = self