BTW, are there any support for unsigned bytes in K...
# kotlin-native
m
BTW, are there any support for unsigned bytes in K/N? I had to "upcast" bytes to ints to be able to work with them properly...
g
Not yet. But Kotlin Team probably implement it in the future https://discuss.kotlinlang.org/t/when-does-bit-fiddling-come-to-kotlin/2249
🙇 1
👍 1
o
what kind of unsigned operations you need most?
m
Not sure whether it was stupid me or what... Take a look at this
ioctl
call: https://github.com/fablabnbg/airco2ntrold/blob/master/airco2ntrold.py#L56. Python doc says that if the last parameter is string (as in this case), then it is treated as a struct of bytes. So, looks like the intent was to send
[0x00, 0xc4, 0xc6, 0xc0, 0x92, 0x40, 0x23, 0xdc, 0x96]
byte array into the device. Indeed it's true - checked with WireShark, the payload was exactrly it. Some of this values, like
0xC4
are greater that 128, so must be unsigned. So what I had to do in K/N is
arr.map { it.toByte() }.toByteArray().refTo(0)
. The second issue was reading from the device. Again, it expects an unsigned byte buffer, I used
ByteArray(8)
, but to get "real" values in [0..255] range I had to do
frame.map { it.toInt() and 0xFF }.toIntArray()
...
I suppose it would be much easier if I just have an unsigned byte type which is able to store values in 0..255 range