but what if my string contains newlines ? do i have to convert the string to a bytearray and send that (preceded with its size) or is there a better way ?
e
edenman
07/29/2020, 11:56 AM
this is what i do:
Copy code
private suspend fun ByteReadChannel.readEntireUTF8(): String {
val sb = StringBuilder()
while (!isClosedForRead) {
sb.append(readUTF8Line() ?: "")
}
return sb.toString()
}
edenman
07/29/2020, 11:56 AM
been working well in production for the last couple months but my N is still very small so ymmv
edenman
07/29/2020, 11:57 AM
oh also i just re-read your message and i imagine you could just add a sb.append(ā\nā) in that loop if you care about the newlines?
l
LastExceed
07/29/2020, 12:00 PM
what i want is something like
writeChannel.writeString(myString)
on the sender side and val
val myString = readChannel.readString()
on the receiver side without having to worry about the content of the string. i achieved this by creating such extension function that do what i explained in op