Package-level declarations

Types

Link copied to clipboard

Channel for asynchronous reading and writing of sequences of bytes. This is a buffered single-reader single-writer channel.

Link copied to clipboard

Sequential (non-concurrent) byte channel implementation

Link copied to clipboard
Link copied to clipboard
expect interface ByteReadChannel

Channel for asynchronous reading of sequences of bytes. This is a single-reader channel.

actual interface ByteReadChannel

Channel for asynchronous reading of sequences of bytes. This is a single-reader channel.

actual interface ByteReadChannel

Channel for asynchronous reading of sequences of bytes. This is a single-reader channel.

actual interface ByteReadChannel

Channel for asynchronous reading of sequences of bytes. This is a single-reader channel.

Link copied to clipboard
expect interface ByteWriteChannel

Channel for asynchronous writing of sequences of bytes. This is a single-writer channel.

actual interface ByteWriteChannel

Channel for asynchronous writing of sequences of bytes. This is a single-writer channel.

actual interface ByteWriteChannel

Channel for asynchronous writing of sequences of bytes. This is a single-writer channel.

actual interface ByteWriteChannel

Channel for asynchronous writing of sequences of bytes. This is a single-writer channel.

Link copied to clipboard
typealias CancellationException = kotlinx.coroutines.CancellationException
Link copied to clipboard
class ClosedWriteChannelException(message: String?) : CancellationException

Indicates attempt to write on isClosedForWrite channel that was closed without a cause. A failed channel rethrows the original close cause exception on send attempts.

Link copied to clipboard
typealias ConsumeEachBufferVisitor = (buffer: ByteBuffer, last: Boolean) -> Boolean

Visitor function that is invoked for every available buffer (or chunk) of a channel. The last parameter shows that the buffer is known to be the last.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
interface ReaderJob : Job

A coroutine job that is reading from a byte channel

Link copied to clipboard
interface ReaderScope : CoroutineScope
Link copied to clipboard
interface ReadSession
Link copied to clipboard
Link copied to clipboard
interface WriterJob : Job

A coroutine job that is writing to a byte channel

Link copied to clipboard
interface WriterScope : CoroutineScope
Link copied to clipboard
interface WriterSession
Link copied to clipboard

Functions

Link copied to clipboard
expect fun ByteChannel(autoFlush: Boolean = false): ByteChannel

Creates buffered channel for asynchronous reading and writing of sequences of bytes.

actual fun ByteChannel(autoFlush: Boolean): ByteChannel

Creates buffered channel for asynchronous reading and writing of sequences of bytes.

actual fun ByteChannel(autoFlush: Boolean): ByteChannel

Creates buffered channel for asynchronous reading and writing of sequences of bytes.

fun ByteChannel(autoFlush: Boolean = false, exceptionMapper: (Throwable?) -> Throwable?): ByteChannel

Creates buffered channel for asynchronous reading and writing of sequences of bytes using close function to close channel.

actual fun ByteChannel(autoFlush: Boolean): ByteChannel

Creates buffered channel for asynchronous reading and writing of sequences of bytes.

Link copied to clipboard

Creates channel for reading from the specified byte array. Please note that it could use content directly or copy its bytes depending on the platform.

fun ByteReadChannel(text: String, charset: Charset = Charsets.UTF_8): ByteReadChannel

expect fun ByteReadChannel(content: ByteArray, offset: Int, length: Int): ByteReadChannel

Creates channel for reading from the specified byte array. Please note that it could use content directly or copy its bytes depending on the platform

Creates channel for reading from the specified ArrayBufferView

actual fun ByteReadChannel(content: ByteArray, offset: Int, length: Int): ByteReadChannel

Creates channel for reading from the specified byte array.

Creates channel for reading from the specified byte buffer.

actual fun ByteReadChannel(content: ByteArray, offset: Int, length: Int): ByteReadChannel

Creates channel for reading from the specified byte array.

actual fun ByteReadChannel(content: ByteArray, offset: Int, length: Int): ByteReadChannel

Creates channel for reading from the specified byte array.

Link copied to clipboard
Link copied to clipboard

Closes this channel with no failure (successfully)

Link copied to clipboard

For every available bytes range invokes visitor function until it return false or end of stream encountered. The provided buffer should be never captured outside of the visitor block otherwise resource leaks, crashes and data corruptions may occur. The visitor block may be invoked multiple times, once or never.

Link copied to clipboard
Link copied to clipboard
suspend fun ByteReadChannel.copyAndClose(dst: ByteWriteChannel, limit: Long = Long.MAX_VALUE): Long

Reads all the bytes from receiver channel and writes them to dst channel and then closes it. Closes dst channel if fails to read or write with cause exception.

Link copied to clipboard

Reads bytes from receiver channel and writes them to dst channel. Closes dst channel if fails to read or write with cause exception.

expect suspend fun ByteReadChannel.copyTo(dst: ByteWriteChannel, limit: Long): Long

Reads up to limit bytes from receiver channel and writes them to dst channel. Closes dst channel if fails to read or write with cause exception.

actual suspend fun ByteReadChannel.copyTo(dst: ByteWriteChannel, limit: Long): Long

Reads up to limit bytes from receiver channel and writes them to dst channel. Closes dst channel if fails to read or write with cause exception.

actual suspend fun ByteReadChannel.copyTo(dst: ByteWriteChannel, limit: Long): Long

Reads up to limit bytes from receiver channel and writes them to dst channel. Closes dst channel if fails to read or write with cause exception.

actual suspend fun ByteReadChannel.copyTo(dst: ByteWriteChannel, limit: Long): Long

Reads up to limit bytes from receiver channel and writes them to dst channel. Closes dst channel if fails to read or write with cause exception.

Link copied to clipboard

Discards all bytes in the channel and suspends until end of stream.

Link copied to clipboard
inline suspend fun ByteReadChannel.discardExact(n: Long)

Discards exactly n bytes or fails if not enough bytes in the channel

Link copied to clipboard
expect suspend fun ByteReadChannel.joinTo(dst: ByteWriteChannel, closeOnEnd: Boolean)
actual suspend fun ByteReadChannel.joinTo(dst: ByteWriteChannel, closeOnEnd: Boolean)
actual suspend fun ByteReadChannel.joinTo(dst: ByteWriteChannel, closeOnEnd: Boolean)
actual suspend fun ByteReadChannel.joinTo(dst: ByteWriteChannel, closeOnEnd: Boolean)
Link copied to clipboard
expect fun Throwable.printStack()

Print exception stacktrace.

actual fun Throwable.printStack()

Print exception stacktrace.

actual fun Throwable.printStack()

Print exception stacktrace.

actual fun Throwable.printStack()

Print exception stacktrace.

Link copied to clipboard
inline suspend fun ByteReadChannel.read(desiredSize: Int = 1, block: (source: Memory, start: Long, endExclusive: Long) -> Int): Int

Await until at least desiredSize is available for read or EOF and invoke block function. The block function should never capture a provided Memory instance outside otherwise an undefined behaviour may occur including accidental crash or data corruption. Block function should return number of bytes consumed or 0.

Link copied to clipboard
Link copied to clipboard
inline suspend fun ByteReadChannel.readDouble(byteOrder: ByteOrder): Double
Link copied to clipboard
Link copied to clipboard
fun CoroutineScope.reader(coroutineContext: CoroutineContext = EmptyCoroutineContext, channel: ByteChannel, block: suspend ReaderScope.() -> Unit): ReaderJob
fun CoroutineScope.reader(coroutineContext: CoroutineContext = EmptyCoroutineContext, autoFlush: Boolean = false, block: suspend ReaderScope.() -> Unit): ReaderJob
fun reader(coroutineContext: CoroutineContext, channel: ByteChannel, parent: Job? = null, block: suspend ReaderScope.() -> Unit): ReaderJob
fun reader(coroutineContext: CoroutineContext, autoFlush: Boolean = false, parent: Job? = null, block: suspend ReaderScope.() -> Unit): ReaderJob
Link copied to clipboard
inline suspend fun ByteReadChannel.readFloat(byteOrder: ByteOrder): Float
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
inline suspend fun ByteReadChannel.readInt(byteOrder: ByteOrder): Int
Link copied to clipboard
Link copied to clipboard
inline suspend fun ByteReadChannel.readLong(byteOrder: ByteOrder): Long
Link copied to clipboard
Link copied to clipboard

Reads all remaining bytes and makes a byte packet

Link copied to clipboard
inline suspend fun ByteReadChannel.readShort(byteOrder: ByteOrder): Short
Link copied to clipboard
Link copied to clipboard

Reads from the channel to the specified dst byte buffer until one of the following:

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
suspend fun ByteReadChannel.skipDelimiter(delimiter: ByteBuffer)
Link copied to clipboard
fun <E : Throwable> tryCopyException(exception: E, cause: Throwable): E?

Try copy exception using cause as cause.

Link copied to clipboard
inline suspend fun ByteWriteChannel.write(desiredSpace: Int = 1, block: (freeSpace: Memory, startOffset: Long, endExclusive: Long) -> Int): Int

Await for desiredSpace will be available for write and invoke block function providing Memory instance and the corresponding range suitable for wiring in the memory. The block function should return number of bytes were written, possibly 0.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Writes UTF16 character

Link copied to clipboard
suspend fun ByteWriteChannel.writeDouble(value: Double, byteOrder: ByteOrder)
Link copied to clipboard
Link copied to clipboard
suspend fun ByteWriteChannel.writeFloat(value: Float, byteOrder: ByteOrder)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
suspend fun ByteWriteChannel.writeInt(value: Int, byteOrder: ByteOrder)
suspend fun ByteWriteChannel.writeInt(i: Long, byteOrder: ByteOrder)
Link copied to clipboard
Link copied to clipboard
suspend fun ByteWriteChannel.writeLong(value: Long, byteOrder: ByteOrder)
Link copied to clipboard
Link copied to clipboard
inline suspend fun ByteWriteChannel.writePacket(builder: BytePacketBuilder.() -> Unit)
Link copied to clipboard
suspend fun ByteWriteChannel.writePacketSuspend(builder: suspend BytePacketBuilder.() -> Unit)
Link copied to clipboard
fun CoroutineScope.writer(coroutineContext: CoroutineContext = EmptyCoroutineContext, channel: ByteChannel, block: suspend WriterScope.() -> Unit): WriterJob
fun CoroutineScope.writer(coroutineContext: CoroutineContext = EmptyCoroutineContext, autoFlush: Boolean = false, block: suspend WriterScope.() -> Unit): WriterJob
fun writer(coroutineContext: CoroutineContext, channel: ByteChannel, parent: Job? = null, block: suspend WriterScope.() -> Unit): WriterJob
fun writer(coroutineContext: CoroutineContext, autoFlush: Boolean = false, parent: Job? = null, block: suspend WriterScope.() -> Unit): WriterJob
Link copied to clipboard
suspend fun ByteWriteChannel.writeShort(s: Int, byteOrder: ByteOrder)
suspend fun ByteWriteChannel.writeShort(value: Short, byteOrder: ByteOrder)
Link copied to clipboard
Link copied to clipboard