@@ -36,7 +36,32 @@ py::class_<BBlockCache>(m, "BBlockCache")
3636.def (py::init<uint32,size_t , uint32>()," " ,py::arg (" blockCount" ),py::arg (" blockSize" ),py::arg (" allocationType" ))
3737// .def("Get", &BBlockCache::Get, "", py::arg("blockSize"))//TODO this returns a void * -- let's return a py::bytes or a py::buffer
3838.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 *
39+ .def (" Get2" , [](BBlockCache& self,size_t blockSize)->py ::tuple{
40+ std::vector<char >buffer (blockSize);
41+ void * data = self.Get (blockSize);
42+ if (data !=nullptr ) {
43+ std::memcpy (buffer.data (), data, blockSize);
44+ }
45+ py::bytespyBytes (buffer.data (),blockSize);
46+ return py::make_tuple (pyBytes, blockSize);
47+ }," " ,py::arg (" blockSize" ))
48+ // .def("Save", &BBlockCache::Save, "", py::arg("pointer"), py::arg("blockSize"))//TODO: pointer is a void * -> python can't use void *
49+ .def (" Save" , [](BBlockCache& self, py::bytes data) {// if we pass a py::bytes we already pass the size along with data right?
50+ /* std::string byt = py::str(data);
51+ void* pointer = static_cast<void*>(const_cast<char*>(byt.data()));
52+ self.Save(pointer, byt.size());*/
53+ char * pointer;
54+ ssize_t size;
55+ PYBIND11_BYTES_AS_STRING_AND_SIZE (data.ptr (), &pointer, &size);
56+ self.Save (static_cast <void *>(pointer),static_cast <size_t >(size));
57+ }," " ,py::arg (" data" ))
58+ .def (" Save_from_buffer" , [](BBlockCache& self, py::buffer py_buffer){
59+ py::buffer_info buf_info = py_buffer.request ();
60+ void * pointer = buf_info.ptr ;
61+ // size_t blockSize = buf_info.size * buf_info.itemsize;
62+ size_t blockSize = buf_info.size ;
63+ self.Save (pointer, blockSize);
64+ }," " ,py::arg (" py_buffer" ))
4065;
4166
4267