|
2 | 2 | #include <pybind11/stl.h>
|
3 | 3 | #include <pybind11/iostream.h>
|
4 | 4 | #include <pybind11/operators.h>
|
| 5 | +#include <pybind11/numpy.h> |
5 | 6 |
|
6 | 7 | #include <app/Message.h>
|
7 | 8 | #include <new>
|
@@ -210,8 +211,35 @@ py::class_<BMessage,std::unique_ptr<BMessage, py::nodelete>>(m, "BMessage")
|
210 | 211 | .def("FindFlat", py::overload_cast<const char *, BFlattenable *>(&BMessage::FindFlat, py::const_), "", py::arg("name"), py::arg("object"))
|
211 | 212 | .def("FindFlat", py::overload_cast<const char *, int32, BFlattenable *>(&BMessage::FindFlat, py::const_), "", py::arg("name"), py::arg("index"), py::arg("object"))
|
212 | 213 | //.def("FindData", py::overload_cast<const char *, type_code, const void * *, ssize_t *>(&BMessage::FindData, py::const_), "", py::arg("name"), py::arg("type"), py::arg("data"), py::arg("numBytes"))
|
| 214 | +.def("FindData", [](BMessage &self, const char *name, type_code type) -> py::tuple { |
| 215 | + const void *vdata = nullptr; |
| 216 | + ssize_t numBytes; |
| 217 | + status_t ret = self.FindData(name, type, &vdata, &numBytes); |
| 218 | + |
| 219 | + if (ret == B_OK && vdata != nullptr) { |
| 220 | + // Converte i dati in un oggetto py::bytes |
| 221 | + const unsigned char *dataPtr = static_cast<const unsigned char *>(vdata); |
| 222 | + py::bytes result(reinterpret_cast<const char *>(dataPtr), numBytes); |
| 223 | + return py::make_tuple(ret, result); |
| 224 | + } |
| 225 | + |
| 226 | + return py::make_tuple(ret, py::none()); |
| 227 | +}, "", py::arg("name"), py::arg("type")) |
213 | 228 | //.def("FindData", py::overload_cast<const char *, type_code, int32, const void * *, ssize_t *>(&BMessage::FindData, py::const_), "", py::arg("name"), py::arg("type"), py::arg("index"), py::arg("data"), py::arg("numBytes"))
|
214 |
| - |
| 229 | +.def("FindData", [](BMessage &self, const char *name, type_code type, int32 index) -> py::tuple { |
| 230 | + const void *vdata = nullptr; |
| 231 | + ssize_t numBytes; |
| 232 | + status_t ret = self.FindData(name, type, index, &vdata, &numBytes); |
| 233 | + |
| 234 | + if (ret == B_OK && vdata != nullptr) { |
| 235 | + // Converte i dati in un oggetto py::bytes |
| 236 | + const unsigned char *dataPtr = static_cast<const unsigned char *>(vdata); |
| 237 | + py::bytes result(reinterpret_cast<const char *>(dataPtr), numBytes); |
| 238 | + return py::make_tuple(ret, result); |
| 239 | + } |
| 240 | + |
| 241 | + return py::make_tuple(ret, py::none()); |
| 242 | +}, "", py::arg("name"), py::arg("type"), py::arg("index")) |
215 | 243 | .def("ReplaceAlignment", py::overload_cast<const char *, const BAlignment &>(&BMessage::ReplaceAlignment), "", py::arg("name"), py::arg("alignment"))
|
216 | 244 | .def("ReplaceAlignment", py::overload_cast<const char *, int32, const BAlignment &>(&BMessage::ReplaceAlignment), "", py::arg("name"), py::arg("index"), py::arg("alignment"))
|
217 | 245 | .def("ReplaceRect", py::overload_cast<const char *, BRect>(&BMessage::ReplaceRect), "", py::arg("name"), py::arg("rect"))
|
|
0 commit comments