7
7
8
8
namespace py = pybind11;
9
9
10
+ /*
11
+ py::bytes Get_wrapper(size_t blockSize) {
12
+ void* data = Get(blockSize);
13
+ py::buffer buffer;
14
+
15
+ if (data == nullptr) {
16
+ throw std::runtime_error("Failed to get data");
17
+ }
18
+ return py::bytes(static_cast<const char*>(data), blockSize);
19
+ }*/
20
+ py::bytes Get_wrapper2 (BBlockCache& self, size_t blockSize) {
21
+ void * data = self.Get (blockSize);
22
+ if (data == nullptr ) {
23
+ throw std::runtime_error (" Failed to get data" );
24
+ }
25
+ py::buffer_info buf_info (static_cast <char *>(data), sizeof (char ), py::format_descriptor<char >::format (), 1 , {blockSize}, {sizeof (char )} );
26
+ // return py::array(buf_info);
27
+ return py::bytes (static_cast <const char *>(buf_info.ptr ), buf_info.size * buf_info.itemsize ); // convert py::buffer to py::bytes
28
+ };
10
29
11
30
PYBIND11_MODULE (BlockCache, m)
12
31
{
@@ -15,8 +34,9 @@ m.attr("B_MALLOC_CACHE") = 1;//py::cast(B_MALLOC_CACHE);
15
34
16
35
py::class_<BBlockCache>(m, " BBlockCache" )
17
36
.def (py::init<uint32, size_t , uint32>(), " " , py::arg (" blockCount" ), py::arg (" blockSize" ), py::arg (" allocationType" ))
18
- .def (" Get" , &BBlockCache::Get, " " , py::arg (" blockSize" ))
19
- .def (" Save" , &BBlockCache::Save, " " , py::arg (" pointer" ), py::arg (" blockSize" ))
37
+ // .def("Get", &BBlockCache::Get, "", py::arg("blockSize"))//TODO this returns a void * -- let's return a py::bytes or a py::buffer
38
+ .def (" Get" , &Get_wrapper2, " " , py::arg (" blockSize" ))
39
+ .def (" Save" , &BBlockCache::Save, " " , py::arg (" pointer" ), py::arg (" blockSize" ))// TODO: pointer is a void * -> python can't use void *
20
40
;
21
41
22
42
0 commit comments