Edoardo Luppi
08/02/2023, 9:52 AMBuffer to a Kotlin ByteArrayVampire
08/02/2023, 10:15 AMbuffer._asList_()._toByteArray_(), but I have no idea actually. 🙂ephemient
08/02/2023, 10:24 AM.unsafeCast<ByteArray>() to work, but actually since Buffer extends UInt8Array and not Int8Array it might have weird behavior without wrapping… haven't testedephemient
08/02/2023, 10:25 AMInt8Array(buffer).unsafeCast<ByteArray>())turansky
08/02/2023, 11:07 AMval uint8 = Uint8Array(arrayOf(1,2))
// conversion
val int8 = Int8Array(uint8.buffer)
val ba = int8.asByteArray()
asByteArray() extension - fine PR :)Edoardo Luppi
08/02/2023, 11:50 AMInt8Array(uint8.buffer)
Would asByteArray simply unsafeCast?turansky
08/02/2023, 11:58 AMWouldYessimplyasByteArray?unsafeCast
ephemient
08/02/2023, 12:06 PMEdoardo Luppi
08/02/2023, 12:07 PMasByteArrayephemient
08/02/2023, 12:10 PMUint8ClampedArray will clamp values outside of range, as its name implies, other JS TypedArray types will reinterpret the bitsEdoardo Luppi
08/02/2023, 12:12 PMwill reinterpret the bitsAs a "view" over those bits tho, right? If you transform a
Int8Array to a UInt8Array you get back the correct resultephemient
08/02/2023, 12:13 PMInt32Array etc. too (assuming you have a correct multiple number of bytes)Vampire
08/02/2023, 12:19 PMephemient
08/02/2023, 12:20 PMVampire
08/02/2023, 12:21 PMEdoardo Luppi
08/02/2023, 12:23 PMbuffer._asList_()Edoardo Luppi
08/02/2023, 12:24 PMephemient
08/02/2023, 12:24 PM.toByteArray makes a copy while the *TypedArray constructors and unsafeCast don'tEdoardo Luppi
08/02/2023, 12:24 PMephemient
08/02/2023, 12:24 PMBuffer to begin with…Vampire
08/02/2023, 12:28 PMturansky
08/02/2023, 3:01 PMByteArray for Kotlin library?
cc @Sergei GrishchenkoEdoardo Luppi
08/03/2023, 12:14 PMByteArray in common code, thus I need to convert the JS Buffer to said ByteArray