Got a newb question for folks. The JS websocket d...
# javascript
e
Got a newb question for folks. The JS websocket definitions require an ArrayBuffer --- but I have code that hands me a ByteArray — There should be a way to convert them.. under the hood are they the same thing?
s
When targeting JS, instances of ByteArray are represented as
Int8Array
(https://kotlinlang.org/docs/reference/js-to-kotlin-interop.html#representing-kotlin-types-in-javascript). You can do
byteArray.unsafeCast<Int8Array>().buffer
to get the underlying ArrayBuffer.
e
thx.. now I need to go the other way as well..:) From an ArrayBuffer to a ByteArray……
gonna try Int8Array(arrayBuffer).unsafeCast< ByteArray>()