Extensions for java.nio.channels.WritableByteChannel

asOutput

fun WritableByteChannel.asOutput(
    pool: ObjectPool<ChunkBuffer> = ChunkBuffer.Pool
): Output

write

fun WritableByteChannel.write(buffer: IoBuffer): Int

Does the same as WritableByteChannel.write but from a IoBuffer instance

fun WritableByteChannel.write(buffer: Buffer): Int

Does the same as WritableByteChannel.write but from a Buffer instance

fun WritableByteChannel.write(
    source: Memory,
    sourceOffset: Int = 0,
    maxLength: Int = source.size32 - sourceOffset
): Int

Does the same as WritableByteChannel.write but from a Memory instance

writePacket

fun WritableByteChannel.writePacket(
    builder: BytePacketBuilder.() -> Unit
): ByteReadPacket?

Builds packet and write it to a NIO channel. May block if the channel is configured as blocking or may write packet partially so this function returns remaining packet. So for blocking channel this function always returns null.

fun WritableByteChannel.writePacket(
    p: ByteReadPacket
): Boolean

Writes packet to a NIO channel. May block if the channel is configured as blocking or may write packet only partially if the channel is non-blocking and there is not enough buffer space.