Skip to content
Snippets Groups Projects
Commit 640afa97 authored by Yentis's avatar Yentis
Browse files

read and write all bytes at once instead of one at a time

parent 65c375ef
No related branches found
No related tags found
No related merge requests found
...@@ -85,9 +85,12 @@ internal class WebSocket(private val socket: Socket) : SocketInterface { ...@@ -85,9 +85,12 @@ internal class WebSocket(private val socket: Socket) : SocketInterface {
private fun decodeBinary(length: ULong, key: UByteArray): UByteArray { private fun decodeBinary(length: ULong, key: UByteArray): UByteArray {
val decoded = ByteArrayOutputStream() val decoded = ByteArrayOutputStream()
for (i in 0 until length.toInt()) {
decoded.write(currentReceivedData.read() xor key[i and 0x3]) val bytes = currentReceivedData.readBytes(length.toInt()).mapIndexed { index, uByte ->
uByte xor key[index and 0x3]
} }
decoded.write(bytes.toUByteArray())
currentReceivedData.shift() currentReceivedData.shift()
return decoded.toByteArray() return decoded.toByteArray()
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment