Is there a simpler way to do this ```val vendor = ...
# ktor
z
Is there a simpler way to do this
Copy code
val vendor = buildString {
    repeat(lengthOfVendor) {
        append(readChannel.readByte().toInt().toChar())
    }
}
e
on JVM,
Copy code
String(ByteArray(length) { readByte() }, Charsets.ISO_8859_1)
z
I'm on native, thanks anyways
e
then you have
Copy code
CharArray(length) { readByte().toInt().and(0xFF).toChar() }.concatToString()
a
If a vendor is encoded in UTF-8 then you can use the
readUTF8Line
method with a limit:
Copy code
val vendor = readChannel.readUTF8Line(lengthOfVendor)
z
I tried that but it just throws an error when it hits the limit, which I don't want
e
it could also stop before the limit, which would break the protocol
there is a helper
Copy code
val packet = readChannel.readPacket(size)
val text = packet.readText()
packet.release()
though