kivy/pyobjus

How to pass bytes object into void* argument of a function? (NSData.dataWithBytes:length:)

0x-kohmar opened this issue · 1 comments

Im having a hard time creating an NSData object with initializing it with my bytes. The length will be correct, however the underlying bytes will all be zero. Passing in a string creates a filled NSData object, but it will change the bytes I want to save.

My goal is to pass the bytes as they are. What am I doing wrong?

The code:

value_passed_in = b"\x01\x02\x03"
ns_data = autoclass('NSData').dataWithBytes_length_(value_passed_in, len(value_passed_in))
print(f"value passed in: {value_passed_in}")
print(f"NS data: {ns_data.description().UTF8String()}")

value_passed_in = b"12345"
ns_data = autoclass('NSData').dataWithBytes_length_(value_passed_in, len(value_passed_in))
print(f"value passed in: {value_passed_in}")
print(f"NS data: {ns_data.description().UTF8String()}")

value_passed_in = str(b"12345")
ns_data = autoclass('NSData').dataWithBytes_length_(value_passed_in, len(value_passed_in))
print(f"value passed in: {value_passed_in}")
print(f"NS data: {ns_data.description().UTF8String()}")

The output:

value passed in: b'\x01\x02\x03'
NS data: {length = 3, bytes = 0x000000}

value passed in: b'12345'


NS data: {length = 5, bytes = 0x0000000000}

value passed in: b'12345'
NS data: {length = 8, bytes = 0x6227313233343527}

I have taken a look at pull request #26 and commit 516eac6 , however I was not able to reach my goal.

This is a support question, not a bug report. Please check out the latest support channels for assistance.

Closing as not a bug.