Package io.ktor.utils.io.core

Types

Link copied to clipboard
open class Buffer(memory: Memory)

Represents a buffer with read and write positions.

Link copied to clipboard
class BufferLimitExceededException(message: String) : Exception
Link copied to clipboard
expect enum ByteOrder : Enum<ByteOrder>
actual enum ByteOrder : Enum<ByteOrder>
actual enum ByteOrder : Enum<ByteOrder>
actual enum ByteOrder : Enum<ByteOrder>
Link copied to clipboard
class BytePacketBuilder(pool: ObjectPool<ChunkBuffer>) : Output

A builder that provides ability to build byte packets with no knowledge of it's size. Unlike Java's ByteArrayOutputStream it doesn't copy the whole content every time it's internal buffer overflows but chunks buffers instead. Packet building via build function is O(1) operation and only does instantiate a new ByteReadPacket. Once a byte packet has been built via build function call, the builder could be reused again. You also can discard all written bytes via reset or release. Please note that an instance of builder need to be terminated either via build function invocation or via release call otherwise it will cause byte buffer leak so that may have performance impact.

Link copied to clipboard
class ByteReadPacket : Input

Read-only immutable byte packet. Could be consumed only once however it does support copy that doesn't copy every byte but creates a new view instead. Once packet created it should be either completely read (consumed) or released via release.

Link copied to clipboard
expect interface Closeable
actual interface Closeable
actual typealias Closeable = Closeable
actual interface Closeable
Link copied to clipboard
class DefaultBufferPool(bufferSize: Int, capacity: Int, allocator: Allocator) : DefaultPool<ChunkBuffer>
Link copied to clipboard
expect class EOFException(message: String) : IOException
actual typealias EOFException = EOFException
actual typealias EOFException = EOFException
actual typealias EOFException = EOFException
Link copied to clipboard
abstract class Input(head: ChunkBuffer, remaining: Long, pool: ObjectPool<ChunkBuffer>) : Closeable

Usually shouldn't be implemented directly. Inherit Input instead.

Link copied to clipboard
class InsufficientSpaceException(message: String) : Exception
Link copied to clipboard
abstract class Output(pool: ObjectPool<ChunkBuffer>) : Appendable, Closeable

This shouldn't be implemented directly. Inherit Output instead.

Functions

Link copied to clipboard
fun Buffer.append(c: Char): Buffer
fun Buffer.append(csq: CharSequence?): Buffer
fun Buffer.append(csq: CharArray, start: Int, end: Int): Buffer
fun Buffer.append(csq: CharSequence?, start: Int, end: Int): Buffer
fun Output.append(csq: CharArray, start: Int = 0, end: Int = csq.size): Appendable
fun Output.append(csq: CharSequence, start: Int = 0, end: Int = csq.length): Appendable
Link copied to clipboard
inline fun buildPacket(block: BytePacketBuilder.() -> Unit): ByteReadPacket

Build a byte packet in block lambda. Creates a temporary builder and releases it in case of failure

Link copied to clipboard
inline fun ByteReadPacket(array: ByteArray, offset: Int = 0, length: Int = array.size): ByteReadPacket
expect fun ByteReadPacket(array: ByteArray, offset: Int = 0, length: Int = array.size, block: (ByteArray) -> Unit): ByteReadPacket
actual fun ByteReadPacket(array: ByteArray, offset: Int = 0, length: Int = array.size, block: (ByteArray) -> Unit): ByteReadPacket
fun ByteReadPacket(bb: ByteBuffer, release: (ByteBuffer) -> Unit = {}): ByteReadPacket
actual inline fun ByteReadPacket(array: ByteArray, offset: Int = 0, length: Int = array.size, crossinline block: (ByteArray) -> Unit): ByteReadPacket
actual fun ByteReadPacket(array: ByteArray, offset: Int = 0, length: Int = array.size, block: (ByteArray) -> Unit): ByteReadPacket
Link copied to clipboard
inline fun Buffer.canRead(): Boolean
Link copied to clipboard
inline fun Buffer.canWrite(): Boolean
Link copied to clipboard
fun checkIndices(offset: Int, length: Int, bytes: ByteArray): Nothing
Link copied to clipboard
fun ChunkBuffer(buffer: ByteBuffer, pool: ObjectPool<ChunkBuffer>? = null): ChunkBuffer
fun ChunkBuffer(ptr: <ERROR CLASS><out <ERROR CLASS>>, lengthInBytes: Int, origin: ChunkBuffer?): ChunkBuffer
fun ChunkBuffer(ptr: <ERROR CLASS><out <ERROR CLASS>>, lengthInBytes: Long, origin: ChunkBuffer?): ChunkBuffer
Link copied to clipboard
fun Input.copyTo(output: Output): Long

Copy all bytes to the output. Depending on actual input and output implementation it could be zero-copy or copy byte per byte. All regular types such as ByteReadPacket, BytePacketBuilder, Input and Output are always optimized so no bytes will be copied.

Link copied to clipboard
fun Input.discard(): Long

Discard all remaining bytes.

Link copied to clipboard
fun Input.discardExact(n: Int)
fun Input.discardExact(n: Long)

Discard exactly n bytes or fail if not enough bytes in the input to be discarded.

Link copied to clipboard
fun Input.discardUntilDelimiter(delimiter: Byte): Long

Discards bytes until delimiter occurred

Link copied to clipboard
fun Input.discardUntilDelimiters(delimiter1: Byte, delimiter2: Byte): Long

Discards bytes until of of the specified delimiters delimiter1 or delimiter2 occurred

Link copied to clipboard
fun Buffer.fill(times: Int, value: Byte)

Write byte value repeated the specified times.

fun Buffer.fill(times: Int, value: UByte)

Write unsigned byte value repeated the specified times.

fun Buffer.fill(n: Long, v: Byte)

Write byte v value repeated n times.

fun Output.fill(times: Long, value: Byte = 0)
Link copied to clipboard
fun Buffer.flush()
Link copied to clipboard
inline fun Buffer.forEach(block: (Byte) -> Unit)

For every byte from this buffer invokes block function giving it as parameter.

Link copied to clipboard
fun Buffer.makeView(): Buffer
fun ChunkBuffer.makeView(): ChunkBuffer
Link copied to clipboard
fun Input.peekCharUtf8(): Char
Link copied to clipboard
inline fun <R> BytePacketBuilder.preview(block: (tmp: ByteReadPacket) -> R): R

Creates a temporary packet view of the packet being build without discarding any bytes from the builder. This is similar to build().copy() except that the builder keeps already written bytes untouched. A temporary view packet is passed as argument to block function and it shouldn't leak outside of this block otherwise an unexpected behaviour may occur.

Link copied to clipboard
fun Buffer.pushBack(n: Int)

Push back n bytes: only possible if there were at least n bytes read before this operation.

Link copied to clipboard
inline fun Buffer.read(block: (memory: Memory, start: Int, endExclusive: Int) -> Int): Int

Apply block of code with buffer's memory providing read range indices. The returned value of block lambda should return number of bytes to be marked as consumed. No read/write functions on this buffer should be called inside of block otherwise an undefined behaviour may occur including data damage.

Link copied to clipboard
fun Buffer.readAvailable(dst: Buffer, length: Int = dst.writeRemaining): Int

Read at most length available bytes to the dst buffer or -1 if no bytes available for read.

fun Input.readAvailable(dst: Buffer, length: Int = dst.writeRemaining): Int
fun Input.readAvailable(destination: Memory, destinationOffset: Int, length: Int): Int
fun Input.readAvailable(destination: Memory, destinationOffset: Long, length: Long): Long
fun Input.readAvailable(dst: ByteArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailable(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
inline fun ChunkBuffer.readAvailable(destination: ByteArray, offset: Int = 0, length: Int = destination.size - offset): Int

fun Buffer.readAvailable(destination: ByteArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: UByteArray, offset: Int = 0, length: Int = destination.size - offset): Int

Read available for read bytes to the destination array range starting at array offset and length bytes. If less than length bytes available then less bytes will be copied and the corresponding number will be returned as result.

fun Buffer.readAvailable(destination: DoubleArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: FloatArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: IntArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: LongArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: ShortArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: UIntArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: ULongArray, offset: Int = 0, length: Int = destination.size - offset): Int
fun Buffer.readAvailable(destination: UShortArray, offset: Int = 0, length: Int = destination.size - offset): Int

Read available for read bytes to the destination array range starting at array offset and length elements. If less than length elements available then less elements will be copied and the corresponding number will be returned as result (possibly zero).

fun Buffer.readAvailable(dst: ArrayBuffer, offset: Int = 0, length: Int = dst.byteLength - offset): Int
fun Buffer.readAvailable(dst: ArrayBufferView, offset: Int = 0, length: Int = dst.byteLength - offset): Int
fun Input.readAvailable(dst: ArrayBuffer, offset: Int = 0, length: Int = dst.byteLength - offset): Int
fun Input.readAvailable(dst: ArrayBufferView, byteOffset: Int = 0, byteLength: Int = dst.byteLength - byteOffset): Int
fun Input.readAvailable(dst: Int8Array, offset: Int = 0, length: Int = dst.length - offset): Int
fun ByteReadPacket.readAvailable(dst: ByteBuffer): Int

Read at most dst.remaining() bytes to the specified dst byte buffer and change its position accordingly

fun Buffer.readAvailable(dst: ByteBuffer, length: Int = dst.remaining()): Int
fun Input.readAvailable(dst: ByteBuffer, length: Int = dst.remaining()): Int
fun ByteReadPacket.readAvailable(dst: <ERROR CLASS><<ERROR CLASS>>, limit: Int): Int
fun ByteReadPacket.readAvailable(dst: <ERROR CLASS><<ERROR CLASS>>, limit: Long): Long

Read at most limit bytes to the specified dst address

fun Buffer.readAvailable(pointer: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int): Int
fun Buffer.readAvailable(pointer: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Int): Int
fun Input.readAvailable(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int): Int
fun Input.readAvailable(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Long): Long
Link copied to clipboard
fun Buffer.readAvailableLittleEndian(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Buffer.readAvailableLittleEndian(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset): Int
fun Input.readAvailableLittleEndian(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset): Int
Link copied to clipboard
fun ByteReadPacket.readByteBuffer(n: Int = remaining.coerceAtMostMaxIntOrFail("Unable to make a ByteBuffer: packet is too big"), direct: Boolean = false): ByteBuffer

Read exactly n (optional, read all remaining by default) bytes to a newly allocated byte buffer

Link copied to clipboard
fun Input.readBytes(): ByteArray

Reads all remaining bytes from the input

fun Buffer.readBytes(count: Int = readRemaining): ByteArray

Read the specified number of bytes specified (optional, read all remaining by default)

fun ByteReadPacket.readBytes(n: Int = remaining.coerceAtMostMaxIntOrFail("Unable to convert to a ByteArray: packet is too big")): ByteArray

Read exactly n bytes (consumes all remaining if n is not specified but up to Int.MAX_VALUE bytes). Does fail if not enough bytes remaining.

fun Input.readBytes(n: Int): ByteArray

Reads exactly n bytes from the input or fails if not enough bytes available.

Link copied to clipboard
fun Input.readBytesOf(min: Int = 0, max: Int = Int.MAX_VALUE): ByteArray

Reads at least min but no more than max bytes from the input to a new byte array

Link copied to clipboard
inline fun Buffer.readDirect(block: (DataView) -> Int): Int
inline fun Buffer.readDirect(block: (ByteBuffer) -> Unit): Int
inline fun ByteReadPacket.readDirect(size: Int, block: (ByteBuffer) -> Unit)
inline fun Input.readDirect(size: Int, block: (ByteBuffer) -> Unit)

inline fun ChunkBuffer.readDirect(block: (ByteBuffer) -> Unit): Int

Apply block function on a ByteBuffer of readable bytes. The block function should return number of consumed bytes.

inline fun Buffer.readDirect(block: (<ERROR CLASS><<ERROR CLASS>>) -> Int): Int
Link copied to clipboard
inline fun Buffer.readDirectInt8Array(block: (Int8Array) -> Int): Int
Link copied to clipboard
fun Buffer.readDouble(): Double

Read a floating point number or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

fun Input.readDouble(): Double
inline fun ChunkBuffer.readDouble(): Double
fun Input.readDouble(byteOrder: ByteOrder): Double
Link copied to clipboard
fun Input.readDoubleFallback(): Double
Link copied to clipboard
fun Buffer.readDoubleLittleEndian(): Double
fun Input.readDoubleLittleEndian(): Double
Link copied to clipboard
fun Buffer.readFloat(): Float

Read a floating point number or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

fun Input.readFloat(): Float
inline fun ChunkBuffer.readFloat(): Float
fun Input.readFloat(byteOrder: ByteOrder): Float
Link copied to clipboard
fun Input.readFloatFallback(): Float
Link copied to clipboard
fun Buffer.readFloatLittleEndian(): Float
fun Input.readFloatLittleEndian(): Float
Link copied to clipboard
fun Buffer.readFully(dst: Buffer, length: Int = dst.writeRemaining): Int

Read at most length bytes from this buffer to the dst buffer.

fun Input.readFully(dst: Buffer, length: Int = dst.writeRemaining)
fun Buffer.readFully(dst: Array<Byte>, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(destination: Memory, destinationOffset: Int, length: Int)
fun Input.readFully(destination: Memory, destinationOffset: Long, length: Long)
fun Input.readFully(dst: ByteArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFully(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun Input.readFully(dst: UByteArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun Input.readFully(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun Input.readFully(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun Input.readFully(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset)
inline fun ChunkBuffer.readFully(destination: ByteArray, offset: Int = 0, length: Int = destination.size - offset)

fun Buffer.readFully(destination: ByteArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: UByteArray, offset: Int = 0, length: Int = destination.size - offset)

Read from this buffer to the destination array to offset and length bytes.

fun Buffer.readFully(destination: DoubleArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: FloatArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: IntArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: LongArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: ShortArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: UIntArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: ULongArray, offset: Int = 0, length: Int = destination.size - offset)
fun Buffer.readFully(destination: UShortArray, offset: Int = 0, length: Int = destination.size - offset)

Read from this buffer to the destination array to offset and length bytes. Numeric values are interpreted in the network byte order (Big Endian).

fun Buffer.readFully(dst: ArrayBuffer, offset: Int = 0, length: Int = dst.byteLength - offset)
fun Buffer.readFully(dst: ArrayBufferView, offset: Int = 0, length: Int = dst.byteLength - offset)
fun Input.readFully(dst: ArrayBuffer, offset: Int = 0, length: Int = dst.byteLength - offset)
fun Input.readFully(dst: ArrayBufferView, byteOffset: Int = 0, byteLength: Int = dst.byteLength - byteOffset)
fun Input.readFully(dst: Int8Array, offset: Int = 0, length: Int = dst.length - offset)
fun Buffer.readFully(destination: ByteBuffer)

Read buffer's content to the destination buffer moving its position.

fun ByteReadPacket.readFully(dst: ByteBuffer): Int

Read exactly dst.remaining() bytes to the specified dst byte buffer and change its position accordingly

fun Buffer.readFully(dst: ByteBuffer, length: Int)
fun Input.readFully(dst: ByteBuffer, length: Int = dst.remaining())
fun ByteReadPacket.readFully(dst: <ERROR CLASS><<ERROR CLASS>>, size: Int): Int
fun ByteReadPacket.readFully(dst: <ERROR CLASS><<ERROR CLASS>>, size: Long): Long

Read exactly size bytes to the specified dst address

fun Buffer.readFully(pointer: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int)
fun Buffer.readFully(pointer: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Int)
fun Input.readFully(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int)
fun Input.readFully(dst: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Long)
Link copied to clipboard
fun Buffer.readFullyLittleEndian(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Buffer.readFullyLittleEndian(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: DoubleArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: FloatArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: IntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: LongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: ShortArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: UIntArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: ULongArray, offset: Int = 0, length: Int = dst.size - offset)
fun Input.readFullyLittleEndian(dst: UShortArray, offset: Int = 0, length: Int = dst.size - offset)
Link copied to clipboard
fun Buffer.readInt(): Int

Read an integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

fun Input.readInt(): Int
inline fun ChunkBuffer.readInt(): Int
fun Input.readInt(byteOrder: ByteOrder): Int
Link copied to clipboard
fun Buffer.readIntLittleEndian(): Int
fun Input.readIntLittleEndian(): Int
Link copied to clipboard
fun Buffer.readLong(): Long

Read a long integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

fun Input.readLong(): Long
inline fun ChunkBuffer.readLong(): Long
fun Input.readLong(byteOrder: ByteOrder): Long
Link copied to clipboard
fun Buffer.readLongLittleEndian(): Long
fun Input.readLongLittleEndian(): Long
Link copied to clipboard
fun Buffer.readShort(): Short

Read a short integer or fail if no bytes available for reading. The numeric value is decoded in the network order (Big Endian).

fun Input.readShort(): Short
inline fun ChunkBuffer.readShort(): Short
fun Input.readShort(byteOrder: ByteOrder): Short
Link copied to clipboard
fun Buffer.readShortLittleEndian(): Short
fun Input.readShortLittleEndian(): Short
Link copied to clipboard
fun Buffer.readText(charset: Charset = Charsets.UTF_8, max: Int = Int.MAX_VALUE): String
fun Input.readText(charset: Charset = Charsets.UTF_8, max: Int = Int.MAX_VALUE): String
fun Input.readText(out: Appendable, charset: Charset = Charsets.UTF_8, max: Int = Int.MAX_VALUE): Int

Reads at most max characters decoding bytes with specified charset. Extra character bytes will remain unconsumed

fun Input.readText(decoder: CharsetDecoder, max: Int = Int.MAX_VALUE): String

Reads at most max characters decoding bytes with specified decoder. Extra character bytes will remain unconsumed

fun Buffer.readText(decoder: CharsetDecoder, out: Appendable, lastBuffer: Boolean, max: Int = Int.MAX_VALUE): Int
fun ByteReadPacket.readText(decoder: CharsetDecoder, out: Appendable, max: Int = Int.MAX_VALUE): Int
Link copied to clipboard
fun Input.readTextExact(charset: Charset = Charsets.UTF_8, n: Int): String

Read exactly n characters interpreting bytes in the specified charset.

Link copied to clipboard
fun Input.readTextExactBytes(charset: Charset = Charsets.UTF_8, bytes: Int): String

Read exactly the specified number of bytes interpreting bytes in the specified charset (optional, UTF-8 by default).

fun Input.readTextExactBytes(bytesCount: Int, charset: Charset = Charsets.UTF_8): String

Read exactly bytesCount interpreting bytes in the specified charset (optional, UTF-8 by default).

Link copied to clipboard
fun Input.readTextExactCharacters(charactersCount: Int, charset: Charset = Charsets.UTF_8): String

Read exactly charactersCount characters interpreting bytes in the specified charset.

Link copied to clipboard
fun Buffer.readUByte(): UByte

Read an unsigned byte or fail if no bytes available for reading.

inline fun Input.readUByte(): UByte
inline fun ChunkBuffer.readUByte(): UByte
Link copied to clipboard
fun Buffer.readUInt(): UInt

Read an unsigned integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

inline fun Input.readUInt(): UInt
inline fun ChunkBuffer.readUInt(): UInt
Link copied to clipboard
fun Buffer.readULong(): ULong

Read an unsigned long integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

inline fun Input.readULong(): ULong
inline fun ChunkBuffer.readULong(): ULong
Link copied to clipboard
fun Input.readUntilDelimiter(delimiter: Byte, dst: Output): Long

Copies to dst output until the specified delimiter occurred.

fun Input.readUntilDelimiter(delimiter: Byte, dst: ByteArray, offset: Int = 0, length: Int = dst.size): Int

Copies to dst array at offset at most length bytes or until the specified delimiter occurred.

Link copied to clipboard
fun Input.readUntilDelimiters(delimiter1: Byte, delimiter2: Byte, dst: Output): Long

Copies to dst output until one of the specified delimiters delimiter1 or delimiter2 occurred.

fun Input.readUntilDelimiters(delimiter1: Byte, delimiter2: Byte, dst: ByteArray, offset: Int = 0, length: Int = dst.size): Int

Copies to dst array at offset at most length bytes or until one of the specified delimiters delimiter1 or delimiter2 occurred.

Link copied to clipboard
fun Buffer.readUShort(): UShort

Read an unsigned short integer or fail if not enough bytes available for reading. The numeric value is decoded in the network order (Big Endian).

inline fun Input.readUShort(): UShort
inline fun ChunkBuffer.readUShort(): UShort
Link copied to clipboard
fun ByteReadPacket.readUTF8Line(estimate: Int = 16, limit: Int = Int.MAX_VALUE): String?
fun Input.readUTF8Line(estimate: Int = 16, limit: Int = Int.MAX_VALUE): String?

Read a string line considering optionally specified estimate but up to optional limit characters length (does fail once limit exceeded) or return null if the packet is empty

Link copied to clipboard
fun Input.readUTF8LineTo(out: Appendable, limit: Int): Boolean

Reads UTF-8 line and append all line characters to out except line endings. Supports CR, LF and CR+LF

Link copied to clipboard
fun Input.readUTF8UntilDelimiter(delimiters: String, limit: Int = Int.MAX_VALUE): String

Reads UTF-8 characters until one of the specified delimiters found, limit exceeded or end of stream encountered

Link copied to clipboard
fun Input.readUTF8UntilDelimiterTo(out: Output, delimiters: String, limit: Int = Int.MAX_VALUE): Int
fun Input.readUTF8UntilDelimiterTo(out: Appendable, delimiters: String, limit: Int = Int.MAX_VALUE): Int

Reads UTF-8 characters to out buffer until one of the specified delimiters found, limit exceeded or end of stream encountered

Link copied to clipboard
fun BytePacketBuilder.reset()

Discard all written bytes and prepare to build another packet.

Link copied to clipboard
expect fun String(bytes: ByteArray, offset: Int = 0, length: Int = bytes.size, charset: Charset = Charsets.UTF_8): String

Create an instance of String from the specified bytes range starting at offset and bytes length interpreting characters in the specified charset.

actual fun String(bytes: ByteArray, offset: Int = 0, length: Int = bytes.size, charset: Charset = Charsets.UTF_8): String

Create an instance of String from the specified bytes range starting at offset and bytes length interpreting characters in the specified charset.

actual fun String(bytes: ByteArray, offset: Int = 0, length: Int = bytes.size, charset: Charset = Charsets.UTF_8): String

Create an instance of String from the specified bytes range starting at offset and bytes length interpreting characters in the specified charset.

Link copied to clipboard
inline fun Input.takeWhile(block: (Buffer) -> Boolean)

Invoke block function for every chunk until end of input or block function return falseblock function returns true to request more chunks or false to stop loop

Link copied to clipboard
inline fun String.toByteArray(charset: Charset = Charsets.UTF_8): ByteArray
Link copied to clipboard
fun Buffer.tryPeek(): Int

Peek the next unsigned byte or return -1 if no more bytes available for reading. No bytes will be marked as consumed in any case.

Link copied to clipboard
inline fun <C : Closeable, R> C.use(block: (C) -> R): R
Link copied to clipboard
inline fun <R> withBuffer(pool: ObjectPool<Buffer>, block: Buffer.() -> R): R

Invoke block function with a temporary Buffer instance taken from the specified pool. Depending on the pool it may be safe or unsafe to capture and use the provided buffer outside of the block. Usually it is always recommended to NOT capture an instance outside.

inline fun <R> withBuffer(size: Int, block: Buffer.() -> R): R

Invoke block function with a temporary Buffer instance of the specified size in bytes. The provided instance shouldn't be captured and used outside of the block otherwise an undefined behaviour may occur including crash and/or data corruption.

Link copied to clipboard
inline fun Buffer.write(block: (memory: Memory, start: Int, endExclusive: Int) -> Int): Int

Apply block of code with buffer's memory providing write range indices. The returned value of block lambda should return number of bytes were written. o read/write functions on this buffer should be called inside of block otherwise an undefined behaviour may occur including data damage.

Link copied to clipboard
inline fun BytePacketBuilder.writeByteBufferDirect(size: Int, block: (ByteBuffer) -> Unit): Int

Write bytes directly to packet builder's segment. Generally shouldn't be used in user's code and useful for efficient integration.

Link copied to clipboard
inline fun Buffer.writeDirect(block: (DataView) -> Int): Int
inline fun Buffer.writeDirect(size: Int = 1, block: (ByteBuffer) -> Unit): Int

inline fun BytePacketBuilder.writeDirect(size: Int, block: (ByteBuffer) -> Unit)

Write bytes directly to packet builder's segment. Generally shouldn't be used in user's code and useful for efficient integration.

inline fun ChunkBuffer.writeDirect(size: Int, block: (ByteBuffer) -> Unit): Int

Apply block function on a ByteBuffer of the free space. The block function should return number of written bytes.

inline fun Buffer.writeDirect(block: (<ERROR CLASS><<ERROR CLASS>>) -> Int): Int
Link copied to clipboard
inline fun Buffer.writeDirectInt8Array(block: (Int8Array) -> Int): Int
Link copied to clipboard
fun Buffer.writeDouble(value: Double)

Write a floating point number or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

fun Output.writeDouble(value: Double)
inline fun ChunkBuffer.writeDouble(value: Double)
fun Output.writeDouble(value: Double, byteOrder: ByteOrder)
Link copied to clipboard
fun Buffer.writeDoubleLittleEndian(value: Double)
fun Output.writeDoubleLittleEndian(value: Double)
Link copied to clipboard
fun Buffer.writeFloat(value: Float)

Write a floating point number or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

fun Output.writeFloat(value: Float)
inline fun ChunkBuffer.writeFloat(value: Float)
fun Output.writeFloat(value: Float, byteOrder: ByteOrder)
Link copied to clipboard
fun Buffer.writeFloatLittleEndian(value: Float)
fun Output.writeFloatLittleEndian(value: Float)
Link copied to clipboard
fun Buffer.writeFully(src: Buffer)

Write all readable bytes from src to this buffer. Fails if not enough space available to write all bytes.

fun Buffer.writeFully(src: Buffer, length: Int)

Write at most length readable bytes from src to this buffer. Fails if not enough space available to write all bytes.

fun Output.writeFully(src: Buffer, length: Int = src.readRemaining)
fun Output.writeFully(src: Memory, offset: Int, length: Int)
fun Output.writeFully(src: Memory, offset: Long, length: Long)
fun Output.writeFully(src: ByteArray, offset: Int = 0, length: Int = src.size - offset)
fun Output.writeFully(src: DoubleArray, offset: Int = 0, length: Int = src.size - offset)
fun Output.writeFully(src: FloatArray, offset: Int = 0, length: Int = src.size - offset)
fun Output.writeFully(src: IntArray, offset: Int = 0, length: Int = src.size - offset)
fun Output.writeFully(src: LongArray, offset: Int = 0, length: Int = src.size - offset)
fun Output.writeFully(src: ShortArray, offset: Int = 0, length: Int = src.size - offset)
inline fun Output.writeFully(array: UByteArray, offset: Int = 0, length: Int = array.size - offset)
inline fun Output.writeFully(array: UIntArray, offset: Int = 0, length: Int = array.size - offset)
inline fun Output.writeFully(array: ULongArray, offset: Int = 0, length: Int = array.size - offset)
inline fun Output.writeFully(array: UShortArray, offset: Int = 0, length: Int = array.size - offset)
inline fun ChunkBuffer.writeFully(source: ByteArray, offset: Int = 0, length: Int = source.size - offset)

fun Buffer.writeFully(source: ByteArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: UByteArray, offset: Int = 0, length: Int = source.size - offset)

Write the whole source array range staring at offset and having the specified bytes length.

fun Buffer.writeFully(source: DoubleArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: FloatArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: IntArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: LongArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: ShortArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: UIntArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: ULongArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFully(source: UShortArray, offset: Int = 0, length: Int = source.size - offset)

Write the whole source array range staring at offset and having the specified items length. Numeric values are interpreted in the network byte order (Big Endian).

fun Buffer.writeFully(src: ArrayBuffer, offset: Int = 0, length: Int = src.byteLength)
fun Buffer.writeFully(src: ArrayBufferView, offset: Int = 0, length: Int = src.byteLength - offset)
fun Buffer.writeFully(source: ByteBuffer)

Write source buffer content moving its position.

fun Output.writeFully(bb: ByteBuffer)
fun BytePacketBuilder.writeFully(src: <ERROR CLASS><<ERROR CLASS>>, size: Int)

Write all remaining src buffer bytes and change its position accordingly

fun Buffer.writeFully(pointer: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int)
fun Buffer.writeFully(pointer: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Int)
fun Output.writeFully(src: <ERROR CLASS><<ERROR CLASS>>, offset: Int, length: Int)
fun Output.writeFully(src: <ERROR CLASS><<ERROR CLASS>>, offset: Long, length: Long)
Link copied to clipboard
fun Buffer.writeFullyLittleEndian(source: DoubleArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: FloatArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: IntArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: LongArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: ShortArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: UIntArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: ULongArray, offset: Int = 0, length: Int = source.size - offset)
fun Buffer.writeFullyLittleEndian(source: UShortArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: DoubleArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: FloatArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: IntArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: LongArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: ShortArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: UIntArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: ULongArray, offset: Int = 0, length: Int = source.size - offset)
fun Output.writeFullyLittleEndian(source: UShortArray, offset: Int = 0, length: Int = source.size - offset)
Link copied to clipboard
fun Buffer.writeInt(value: Int)

Write an integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

fun Output.writeInt(value: Int)
inline fun ChunkBuffer.writeInt(value: Int)
fun Output.writeInt(value: Int, byteOrder: ByteOrder)
Link copied to clipboard
fun Buffer.writeIntLittleEndian(value: Int)
fun Output.writeIntLittleEndian(value: Int)
Link copied to clipboard
fun Buffer.writeLong(value: Long)

Write a long integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

fun Output.writeLong(value: Long)
inline fun ChunkBuffer.writeLong(value: Long)
fun Output.writeLong(value: Long, byteOrder: ByteOrder)
Link copied to clipboard
fun Buffer.writeLongLittleEndian(value: Long)
fun Output.writeLongLittleEndian(value: Long)
Link copied to clipboard
fun Buffer.writeShort(value: Short)

Write a short integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

fun Output.writeShort(value: Short)
inline fun ChunkBuffer.writeShort(value: Short)
fun Output.writeShort(value: Short, byteOrder: ByteOrder)
Link copied to clipboard
fun Buffer.writeShortLittleEndian(value: Short)
fun Output.writeShortLittleEndian(value: Short)
Link copied to clipboard
fun Output.writeText(text: CharArray, fromIndex: Int = 0, toIndex: Int = text.size, charset: Charset = Charsets.UTF_8)
fun Output.writeText(text: CharSequence, fromIndex: Int = 0, toIndex: Int = text.length, charset: Charset = Charsets.UTF_8)

Writes text characters in range \[fromIndex .. toIndex) with the specified charset

Link copied to clipboard
fun Buffer.writeUByte(value: UByte)

Write an unsigned byte or fail if not enough space available for writing.

inline fun Output.writeUByte(v: UByte)
fun ChunkBuffer.writeUByte(value: UByte)
Link copied to clipboard
fun Buffer.writeUInt(value: UInt)

Write an unsigned integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

inline fun Output.writeUInt(v: UInt)
inline fun ChunkBuffer.writeUInt(value: UInt)
Link copied to clipboard
fun Buffer.writeULong(value: ULong)

Write an unsigned long integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

inline fun Output.writeULong(v: ULong)
inline fun ChunkBuffer.writeULong(value: ULong)
Link copied to clipboard
fun Buffer.writeUShort(value: UShort)

Write an unsigned short integer or fail if not enough space available for writing. The numeric value is encoded in the network order (Big Endian).

inline fun Output.writeUShort(v: UShort)
inline fun ChunkBuffer.writeUShort(value: UShort)

Properties

Link copied to clipboard
val Input.isEmpty: Boolean

For streaming input it should be Input.endOfInput instead.

Link copied to clipboard
val ByteReadPacket.isEmpty: Boolean
Link copied to clipboard
val Input.isNotEmpty: Boolean

For streaming input there is no reliable way to detect it without triggering bytes population from the underlying source. Consider using Input.endOfInput or use ByteReadPacket instead.

Link copied to clipboard
val ByteReadPacket.isNotEmpty: Boolean
Link copied to clipboard
expect val PACKET_MAX_COPY_SIZE: Int
actual val PACKET_MAX_COPY_SIZE: Int
actual val PACKET_MAX_COPY_SIZE: Int
actual val PACKET_MAX_COPY_SIZE: Int