To get rid of the `.toByte()` you can just call `....
# language-proposals
s
To get rid of the
.toByte()
you can just call
.map()
To get rid of the many
0xFF
then I guess you can specify it in Longs
0xFF_FF_FF_FF_FF_FF_FF
and convert to bytes. Im not sure additional syntex is needed.. seems a util package for bits and bytes could take care of most of it
👍 1
l
.map()
si still an extra call that has nothing to do with bytes, and this method doesn't exist in stdlib.
I had already tried
0xFF_FF_FF_FF_FF_FF_FF
for UUIDs, but it didn't work because it's treated as a positive, 65 bits value, which is beyond the 64 bits of
Long
, causing a compilation error, and guess what... It still doesn't work, and the
.toLong()
ugly workaround doesn't work because there's no way to represent the 65 bits constant in first place
Finally, writing code to transform longs to byte array is extremely error-prone since it's very likely that you would need offsets since your byte array may have a length different from a 64 bits multiple
So, @spand, I'm sure I'd like a dedicated syntax for this
s
Sure. I just believe its within the realm of possibilities that one could make a library that is almost as nice to use. Hence, in my opinion the usecase is not a sufficient argument for special syntax.
l
@spand Personally have already 4 projects dealing with Bluetooth/BLE and raw bytes, so that's 4 use cases where I have error prone and ugly code, and there's no way to make this a library. Remember the most natural look I could get is using hex strings plus a conversion utility method, but this introduces an overhead for conversion, and is error-prone since nothing prevents you from adding
g
or any other non hex character, and you would notice it only when that part of the code is run, which is not ideal to test since when you work with bluetooth, it's impossible to unit test communication between devices. Also, there's the issue with uppercase and lowercase characters which either introduce more overhead to let both work, or are more error prone if you allow only uppercase, or only lowercase