MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / pack

Method pack

flow-rs/src/loader/python/envelope.rs:37–66  ·  view source on GitHub ↗
(py: Python, msg: PyObject, info: Option<Py<PyDict>>)

Source from the content-addressed store, hash-verified

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);

Callers 4

source_defFunction · 0.80
execMethod · 0.80
execMethod · 0.80
sendFunction · 0.80

Calls 4

as_refMethod · 0.80
to_objectMethod · 0.80
is_noneMethod · 0.45
info_mutMethod · 0.45

Tested by

no test coverage detected