Edoardo Luppi
08/15/2023, 3:39 PMByteArray
(Int8Array
) to a Uint8Array
is
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.turansky
08/15/2023, 5:44 PMEdoardo Luppi
08/15/2023, 7:25 PMEdoardo Luppi
08/15/2023, 7:27 PMByteArray
? Is it a sort of shared buffer, and that's why the offset is not zero?turansky
08/15/2023, 8:48 PM@turansky which name would suite better?
toByteArray
turansky
08/15/2023, 8:49 PMInt8Array.asByteArray
missed in your example