(#[data] state: State, #[body] body: Bytes)
| 43 | #[post("/analyze/bytes")] |
| 44 | #[openapi(summary = "analyze user define bytes")] |
| 45 | async fn analyze(#[data] state: State, #[body] body: Bytes) -> Result<impl Reply, Rejection> { |
| 46 | let id = state.id(); |
| 47 | |
| 48 | let pyobject: PyObject = Python::with_gil(|py| -> PyResult<_> { |
| 49 | let ndarray = body.to_pyarray(py); |
| 50 | |
| 51 | Ok([("data", ndarray.to_object(py))].into_py_dict(py).into()) |
| 52 | }) |
| 53 | .map_err(reject_cause)?; |
| 54 | |
| 55 | let r = { |
| 56 | let (s, r) = oneshot::channel(); |
| 57 | state.mapping.lock().await.insert(id, s); |
| 58 | let envelope = Envelope::with_info( |
| 59 | pyobject, |
| 60 | EnvelopeInfo { |
| 61 | partial_id: Some(id), |
| 62 | ..Default::default() |
| 63 | }, |
| 64 | ); |
| 65 | state.out.send(envelope).await.ok(); |
| 66 | r |
| 67 | }; |
| 68 | let message = r.await.map_err(reject_cause)?; |
| 69 | Python::with_gil(|py| -> PyResult<_> { |
| 70 | let dict: &PyDict = message.extract(py)?; |
| 71 | flow_rs::helper::uget_slice(py, dict.get_item("data").expect("error key<data>")) |
| 72 | }) |
| 73 | .map_err(reject_cause) |
| 74 | .map(|data| RwebBytes::new(&(data.to_vec()))) |
| 75 | } |
| 76 | |
| 77 | impl BytesServer { |
| 78 | fn new(_: String, args: &Table) -> BytesServer { |
no test coverage detected