Edoardo Luppi
06/28/2023, 10:02 PMTcpSocketBuilder
and then the created ByteReadChannel
, how do I read a UInt
?Adam S
06/29/2023, 7:43 AMreadInt()
member function https://api.ktor.io/ktor-io/io.ktor.utils.io/-byte-read-channel/index.html#598794336%2FFunctions%2F599479352, but no readUInt()
member or extension function
And so, at a guess, you could try reading the number of bytes required UInt.SIZE_BYTES and then convert them into a UIntAleksei Tirman [JB]
06/29/2023, 7:43 AMchannel.readInt().toUInt()
Edoardo Luppi
06/29/2023, 7:48 AMEdoardo Luppi
06/29/2023, 7:48 AMAdam S
06/29/2023, 7:52 AMchannel.readInt().toUInt()
ahh yeah, if that works 👍. I assumed it wouldn’t because UInt.MAX_VALUE
is of course larger than Int.MAX_VALUE
- but I guess the byte representation is the sameEdoardo Luppi
06/29/2023, 7:55 AMAdam S
06/29/2023, 7:58 AMreadPacket(UInt.SIZE_BYTES)
https://api.ktor.io/ktor-io/io.ktor.utils.io/-byte-read-channel/read-packet.html which returns a ByteReadPacket, which has a readUInt() extensionEdoardo Luppi
06/29/2023, 8:02 AMEdoardo Luppi
06/29/2023, 8:30 AMreadFully
which accepts a buffer/byte array.
Not sure what's the differenceEdoardo Luppi
06/29/2023, 9:21 AMreadPacket
. Thanks both!
Now I'd like to perform a write. Is there a way to concatenate two ByteReadPacket
into a single ByteReadPacket
? I need to perform an "atomic" writeEdoardo Luppi
06/29/2023, 9:30 AMsendChannel.writePacket {
if (serializable.autosize()) {
writeUInt(outputStream.getWrittenBytes().toUInt())
}
writePacket(payloadBuilder.build())
}