pyd icon indicating copy to clipboard operation
pyd copied to clipboard

Returning Python3 bytes

Open carver opened this issue 4 years ago • 1 comments

The bytes type isn't listed here: https://pyd.readthedocs.io/en/latest/conversion.html#d-to-python

What D type should I use to return a bytes value?

string isn't an option, because I need to support arbitrary data, which is often not unicode-valid. I also tried using a function signature that returns a char[]. Either way, the code raises UnicodeDecodeError when invoked in python.

For now, my workaround is to return a ubyte[] and then call bytes(returned_val). But that adds an unnecessary copy (and a 20% slowdown) that I'd rather avoid.

carver avatar Jan 27 '21 19:01 carver

there doesn't seem to be a good way to return bytes. can't have that.

https://github.com/ariovistus/pyd/pull/147

ariovistus avatar Jan 31 '21 21:01 ariovistus