commonMain.transport.ktor.ByteChannel.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yass2-ktor-jvm Show documentation
Show all versions of yass2-ktor-jvm Show documentation
Yet Another Service Solution
The newest version!
package ch.softappeal.yass2.transport.ktor
import ch.softappeal.yass2.transport.BytesReader
import ch.softappeal.yass2.transport.Transport
import io.ktor.utils.io.ByteReadChannel
import io.ktor.utils.io.ByteWriteChannel
import io.ktor.utils.io.readFully
import io.ktor.utils.io.writeFully
import io.ktor.utils.io.writeInt
internal suspend fun ByteWriteChannel.write(transport: Transport, value: Any?) {
val writer = transport.createWriter()
transport.write(writer, value)
writeInt(writer.current)
writeFully(writer.buffer, 0, writer.current)
}
internal suspend fun ByteReadChannel.read(transport: Transport, length: Int): Any? {
val buffer = transport.readBytes(length) { bytes, offset, size -> readFully(bytes, offset, offset + size) }
val reader = BytesReader(buffer)
return transport.read(reader).apply {
check(reader.isDrained)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy