public actual inline fun Uint8Array.toKotlinArray(): ByteArray =
Int8Array(buffer, byteOffset, byteLength).unsafeCast<ByteArray>()
@Suppress("NOTHING_TO_INLINE")
public actual inline fun ByteArray.toPlatformArray(): Uint8Array {
val i8a = unsafeCast<Int8Array>()
return Uint8Array(i8a.buffer, i8a.byteOffset, i8a.byteLength)
}
You basically need to specify the byte offset and byte length, otherwise the result is way off.
t
turansky
08/15/2023, 5:44 PM
First extension with fixed name expected as PR :)
e
Edoardo Luppi
08/15/2023, 7:25 PM
@turansky which name would suite better?
Edoardo Luppi
08/15/2023, 7:27 PM
@Artem Kobzar question if you know the answer, how is the backing array buffer handled for the KJS implementation of
ByteArray
? Is it a sort of shared buffer, and that's why the offset is not zero?