| 35 | #[staticmethod] |
| 36 | #[args(info = "None")] |
| 37 | fn pack(py: Python, msg: PyObject, info: Option<Py<PyDict>>) -> PyResult<Self> { |
| 38 | let mut envelope = if msg.is_none(py) { |
| 39 | Envelope::<PyObject>::empty() |
| 40 | } else { |
| 41 | Envelope::new(msg) |
| 42 | }; |
| 43 | |
| 44 | if let Some(info) = info { |
| 45 | let info = info.as_ref(py); |
| 46 | let target = envelope.info_mut(); |
| 47 | macro_rules! restore { |
| 48 | ($k:ident) => { |
| 49 | if let Some($k) = info.get_item(stringify!($k)) { |
| 50 | target.$k = $k.extract()?; |
| 51 | } |
| 52 | }; |
| 53 | } |
| 54 | restore!(from_addr); |
| 55 | restore!(to_addr); |
| 56 | restore!(transfer_addr); |
| 57 | restore!(partial_id); |
| 58 | restore!(tag); |
| 59 | if let Some(extra_data) = info.get_item("extra_data") { |
| 60 | target.extra_data = Some(Arc::new(extra_data.to_object(py))) |
| 61 | } |
| 62 | } |
| 63 | Ok(PyEnvelope { |
| 64 | imp: Some(envelope), |
| 65 | }) |
| 66 | } |
| 67 | |
| 68 | fn repack(&self, msg: PyObject) -> Self { |
| 69 | let envelope = self.imp.as_ref().expect(ERR_MSG); |