Package-level declarations

Types

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

Represents a buffer with read and write positions.

Link copied to clipboard
Link copied to clipboard
expect enum ByteOrder : Enum<ByteOrder>
actual 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> = ChunkBuffer.Pool) : 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

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 = java.io.Closeable
actual interface Closeable
Link copied to clipboard
class DefaultBufferPool(bufferSize: Int = DEFAULT_BUFFER_SIZE, capacity: Int = 1000, allocator: Allocator = DefaultAllocator) : DefaultPool<ChunkBuffer>
Link copied to clipboard
expect class EOFException(message: String) : IOException
Link copied to clipboard
abstract class Input(head: ChunkBuffer = ChunkBuffer.Empty, remaining: Long = head.remainingAll(), val pool: ObjectPool<ChunkBuffer> = ChunkBuffer.Pool) : Closeable

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

Link copied to clipboard
class InsufficientSpaceException(message: String = "Not enough free space") : Exception
Link copied to clipboard

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

Properties

Link copied to clipboard

For streaming input it should be Input.endOfInput instead.

Link copied to clipboard

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
actual val PACKET_MAX_COPY_SIZE: Int = 200
actual val PACKET_MAX_COPY_SIZE: Int = 200

Functions

Link copied to clipboard
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

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, length: Int, block: (ByteArray) -> Unit): ByteReadPacket
fun ByteReadPacket(bb: ByteBuffer, release: (ByteBuffer) -> Unit = {}): <Error class: unknown class>
actual inline fun ByteReadPacket(array: ByteArray, offset: Int, length: Int, crossinline block: (ByteArray) -> Unit): ByteReadPacket
actual fun ByteReadPacket(array: ByteArray, offset: Int, length: Int, block: (ByteArray) -> Unit): ByteReadPacket
actual fun ByteReadPacket(array: ByteArray, offset: Int, length: Int, 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
fun checkIndices(offset: Int, length: Int, bytes: ByteArray): Nothing
Link copied to clipboard
fun ChunkBuffer(buffer: ByteBuffer, pool: <Error class: unknown class><<Error class: unknown class>>? = null): <Error class: unknown class>
fun ChunkBuffer(ptr: CPointer<*>, lengthInBytes: Int, origin: ChunkBuffer?): ChunkBuffer
fun ChunkBuffer(ptr: CPointer<*>, 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

Discard all remaining bytes.

Link copied to clipboard

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

Link copied to clipboard

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
inline fun Buffer.forEach(block: (Byte) -> Unit)

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

Link copied to clipboard
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
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 <Error class: unknown class>.readAvailable(dst: ByteBuffer): Int

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

fun <Error class: unknown class>.readAvailable(dst: ByteBuffer, length: Int = dst.remaining()): Int
fun Buffer.readAvailable(dst: ByteBuffer, length: Int = dst.remaining()): Int

Read at most limit bytes to the specified dst address

fun Buffer.readAvailable(pointer: CPointer<ByteVar>, offset: Int, length: Int): Int
fun Buffer.readAvailable(pointer: CPointer<ByteVar>, offset: Long, length: Int): Int
fun Input.readAvailable(dst: CPointer<ByteVar>, offset: Int, length: Int): Int
fun Input.readAvailable(dst: CPointer<ByteVar>, 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 <Error class: unknown class>.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

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.

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 <Error class: unknown class>.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: (ByteBuffer) -> Unit): Int
inline fun <Error class: unknown class>.readDirect(size: Int, block: (ByteBuffer) -> Unit)
inline fun <Error class: unknown class>.readDirect(size: Int, block: (ByteBuffer) -> Unit)
inline fun Buffer.readDirect(block: (CPointer<ByteVar>) -> Int): Int
inline fun Buffer.readDirect(block: (ByteArray) -> Int): Int
Link copied to clipboard
inline fun Buffer.readDirectByteArray(block: (ByteArray) -> Int): Int
Link copied to clipboard
inline fun Buffer.readDirectInt8Array(block: (Int8Array) -> Int): Int
Link copied to clipboard

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(byteOrder: ByteOrder): Double
Link copied to clipboard
Link copied to clipboard

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(byteOrder: ByteOrder): Float
Link copied to clipboard
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 <Error class: unknown class>.readFully(dst: ByteBuffer): Int

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

fun Buffer.readFully(destination: ByteBuffer)

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

fun <Error class: unknown class>.readFully(dst: ByteBuffer, length: Int = dst.remaining())
fun Buffer.readFully(dst: ByteBuffer, length: Int)

Read exactly size bytes to the specified dst address

fun Buffer.readFully(pointer: CPointer<ByteVar>, offset: Int, length: Int)
fun Buffer.readFully(pointer: CPointer<ByteVar>, offset: Long, length: Int)
fun Input.readFully(dst: CPointer<ByteVar>, offset: Int, length: Int)
fun Input.readFully(dst: CPointer<ByteVar>, 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

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

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

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

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

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(byteOrder: ByteOrder): 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

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

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

Link copied to clipboard

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 ChunkBuffer.readUInt(): UInt
Link copied to clipboard

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).

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

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).

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

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

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, length: Int, charset: Charset): 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, length: Int, charset: Charset): 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, length: Int, charset: Charset): 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 false block 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
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 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 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 <Error class: unknown class>.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 <Error class: unknown class>.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 <Error class: unknown class>.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(size: Int = 1, block: (ByteBuffer) -> Unit): Int
inline fun Buffer.writeDirect(block: (CPointer<ByteVar>) -> Int): Int
inline fun Buffer.writeDirect(block: (ByteArray) -> Int): Int
Link copied to clipboard
inline fun Buffer.writeDirectInt8Array(block: (Int8Array) -> Int): Int
Link copied to clipboard

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).

inline fun ChunkBuffer.writeDouble(value: Double)
fun Output.writeDouble(value: Double, byteOrder: ByteOrder)
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

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 <Error class: unknown class>.writeFully(bb: ByteBuffer)

Write source buffer content moving its position.

Write all remaining src buffer bytes and change its position accordingly

fun Buffer.writeFully(pointer: CPointer<ByteVar>, offset: Int, length: Int)
fun Buffer.writeFully(pointer: CPointer<ByteVar>, offset: Long, length: Int)
fun Output.writeFully(src: CPointer<ByteVar>, offset: Int, length: Int)
fun Output.writeFully(src: CPointer<ByteVar>, 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
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
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 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.

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 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 ChunkBuffer.writeULong(value: ULong)
Link copied to clipboard

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 ChunkBuffer.writeUShort(value: UShort)