| 103 | } |
| 104 | |
| 105 | py::object packet_get(bmf_sdk::Packet &pkt, const py::object &cls) { |
| 106 | std::string cls_name; |
| 107 | if (cls.is_none()) { |
| 108 | cls_name = "bmf.lib._bmf.sdk.PythonObject"; |
| 109 | } else { |
| 110 | cls_name = get_py_class_name(cls); |
| 111 | if (s_packet_casters.find(cls_name) == s_packet_casters.end()) { |
| 112 | cls_name = "bmf.lib._bmf.sdk.PythonObject"; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | auto obj = s_packet_casters.at(cls_name).from(pkt); |
| 117 | if (cls_name == "bmf.lib._bmf.sdk.PythonObject") { |
| 118 | obj = obj.cast<bmf_sdk::PythonObject>().obj(); |
| 119 | if (cls.is_none() || obj.get_type().is(cls)) { |
| 120 | return obj; |
| 121 | } else { |
| 122 | throw std::runtime_error("class type is not matched"); |
| 123 | } |
| 124 | } else { |
| 125 | return obj; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | bool packet_is(bmf_sdk::Packet &pkt, const py::object &cls) { |
| 130 | try { |
no test coverage detected