Browse Source

Send empty map empty arrays to `None` when sending outputs

tags/v0.2.3-rc
Philipp Oppermann 2 years ago
parent
commit
8ec45239ce
Failed to extract signature
3 changed files with 24 additions and 39 deletions
  1. +3
    -8
      apis/rust/node/src/node/mod.rs
  2. +20
    -26
      binaries/runtime/src/operator/python.rs
  3. +1
    -5
      binaries/runtime/src/operator/shared_lib.rs

+ 3
- 8
apis/rust/node/src/node/mod.rs View File

@@ -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(


+ 20
- 26
binaries/runtime/src/operator/python.rs View File

@@ -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(|| {


+ 1
- 5
binaries/runtime/src/operator/shared_lib.rs View File

@@ -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


Loading…
Cancel
Save