Closed dvicini closed 3 months ago
I think I found the issue. The binding:
.def("write", [](Stream &s, nb::bytes b) {
std::string data(b.c_str());
s.write(data.c_str(), data.size());
}, D(Stream, write))
should be
.def("write", [](Stream &s, nb::bytes b) {
s.write(b.c_str(), b.size());
}, D(Stream, write))
Otherwise the string conversion goes wrong, due to the way null-termination characters are handled. In PyBind11, the py::bytes
type had a specialized conversion to get a std::string
, but directly converting b.c_str()
to string will stop at the termination character
Yep, you're right! I just discovered this too and put up a PR #1255
Something appears to go wrong when writing bytes into the
mi.MemoryStream
in Python. I have some code that uses the memory stream to load EXR files. However, it appears that writing data of typebytes
to the MemoryStream is somehow not quite working. Here is what I have:This prints
As you can see, somehow only the first 5 bytes get written. Do I need to pass something else to memory stream rather than Python
bytes
?The code runs fine using the last pre-nanobind version