Package io.ktor.utils.io.bits

Types

Memory

expect class Memory

Represents a linear range of bytes. All operations are guarded by range-checks by default however at some platforms they could be disabled in release builds.

Extensions for External Classes

java.nio.ByteBuffer

kotlin.ByteArray

kotlin.Double

kotlin.Float

kotlin.Int

kotlin.Long

kotlin.Short

Functions

copyTo

expect fun Memory.copyTo(
    destination: ByteArray,
    offset: Int,
    length: Int,
    destinationOffset: Int = 0
): Unit
expect fun Memory.copyTo(
    destination: ByteArray,
    offset: Long,
    length: Int,
    destinationOffset: Int = 0
): Unit

Copies bytes from this memory range from the specified offset and length to the destination at destinationOffset.

fun Memory.copyTo(destination: ByteBuffer, offset: Int): Unit
fun Memory.copyTo(
    destination: ByteBuffer,
    offset: Long
): Unit

Copies bytes from this memory range from the specified offset to the destination buffer.

fill

expect fun Memory.fill(
    offset: Long,
    count: Long,
    value: Byte
): Unit
expect fun Memory.fill(
    offset: Int,
    count: Int,
    value: Byte
): Unit

Fill memory range starting at the specified offset with value repeated count times.

get

operator fun Memory.get(index: Int): Byte
operator fun Memory.get(index: Long): Byte

Read byte at the specified index.

loadByteArray

fun Memory.loadByteArray(
    offset: Int,
    destination: ByteArray,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit

Copies bytes from this memory range from the specified offset and count to the destination at destinationOffset.

fun Memory.loadByteArray(
    offset: Long,
    destination: ByteArray,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit

Copies unsigned shorts integers from this memory range from the specified offset and count to the destination at destinationOffset interpreting numbers in the network order (Big Endian).

loadDoubleArray

expect fun Memory.loadDoubleArray(
    offset: Int,
    destination: DoubleArray,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit
expect fun Memory.loadDoubleArray(
    offset: Long,
    destination: DoubleArray,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit

Copies floating point numbers from this memory range from the specified offset and count to the destination at destinationOffset interpreting numbers in the network order (Big Endian).

loadDoubleAt

expect fun Memory.loadDoubleAt(offset: Int): Double
expect fun Memory.loadDoubleAt(offset: Long): Double

Read short signed 64bit floating point number in the network byte order (Big Endian)

loadFloatArray

expect fun Memory.loadFloatArray(
    offset: Int,
    destination: FloatArray,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit
expect fun Memory.loadFloatArray(
    offset: Long,
    destination: FloatArray,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit

Copies floating point numbers from this memory range from the specified offset and count to the destination at destinationOffset interpreting numbers in the network order (Big Endian).

loadFloatAt

expect fun Memory.loadFloatAt(offset: Int): Float
expect fun Memory.loadFloatAt(offset: Long): Float

Read short signed 32bit floating point number in the network byte order (Big Endian)

loadIntArray

expect fun Memory.loadIntArray(
    offset: Int,
    destination: IntArray,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit
expect fun Memory.loadIntArray(
    offset: Long,
    destination: IntArray,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit

Copies regular integers from this memory range from the specified offset and count to the destination at destinationOffset interpreting numbers in the network order (Big Endian).

loadIntAt

expect fun Memory.loadIntAt(offset: Int): Int
expect fun Memory.loadIntAt(offset: Long): Int

Read regular signed 32bit integer in the network byte order (Big Endian)

loadLongArray

expect fun Memory.loadLongArray(
    offset: Int,
    destination: LongArray,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit
expect fun Memory.loadLongArray(
    offset: Long,
    destination: LongArray,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit

Copies long integers from this memory range from the specified offset and count to the destination at destinationOffset interpreting numbers in the network order (Big Endian).

loadLongAt

expect fun Memory.loadLongAt(offset: Int): Long
expect fun Memory.loadLongAt(offset: Long): Long

Read short signed 64bit integer in the network byte order (Big Endian)

loadShortArray

expect fun Memory.loadShortArray(
    offset: Int,
    destination: ShortArray,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit
expect fun Memory.loadShortArray(
    offset: Long,
    destination: ShortArray,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit

Copies shorts integers from this memory range from the specified offset and count to the destination at destinationOffset interpreting numbers in the network order (Big Endian).

loadShortAt

expect fun Memory.loadShortAt(offset: Int): Short
expect fun Memory.loadShortAt(offset: Long): Short

Read short signed 16bit integer in the network byte order (Big Endian)

loadUByteArray

fun Memory.loadUByteArray(
    offset: Int,
    destination: <ERROR CLASS>,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit
fun Memory.loadUByteArray(
    offset: Long,
    destination: <ERROR CLASS>,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit

Copies unsigned shorts integers from this memory range from the specified offset and count to the destination at destinationOffset interpreting numbers in the network order (Big Endian).

loadUIntArray

fun Memory.loadUIntArray(
    offset: Int,
    destination: <ERROR CLASS>,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit
fun Memory.loadUIntArray(
    offset: Long,
    destination: <ERROR CLASS>,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit

Copies unsigned integers from this memory range from the specified offset and count to the destination at destinationOffset interpreting numbers in the network order (Big Endian).

loadUIntAt

fun Memory.loadUIntAt(offset: Int): <ERROR CLASS>
fun Memory.loadUIntAt(offset: Long): <ERROR CLASS>

Read regular unsigned 32bit integer in the network byte order (Big Endian)

loadULongArray

fun Memory.loadULongArray(
    offset: Int,
    destination: <ERROR CLASS>,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit
fun Memory.loadULongArray(
    offset: Long,
    destination: <ERROR CLASS>,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit

Copies unsigned long integers from this memory range from the specified offset and count to the destination at destinationOffset interpreting numbers in the network order (Big Endian).

loadULongAt

fun Memory.loadULongAt(offset: Int): <ERROR CLASS>
fun Memory.loadULongAt(offset: Long): <ERROR CLASS>

Read short signed 64bit integer in the network byte order (Big Endian)

loadUShortArray

fun Memory.loadUShortArray(
    offset: Int,
    destination: <ERROR CLASS>,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit
fun Memory.loadUShortArray(
    offset: Long,
    destination: <ERROR CLASS>,
    destinationOffset: Int = 0,
    count: Int = destination.size - destinationOffset
): Unit

Copies unsigned shorts integers from this memory range from the specified offset and count to the destination at destinationOffset interpreting numbers in the network order (Big Endian).

loadUShortAt

fun Memory.loadUShortAt(offset: Int): <ERROR CLASS>
fun Memory.loadUShortAt(offset: Long): <ERROR CLASS>

Read short unsigned 16bit integer in the network byte order (Big Endian)

reverseByteOrder

fun <ERROR CLASS>.reverseByteOrder(): <ERROR CLASS>

Reverse number’s byte order

set

operator fun Memory.set(index: Long, value: Byte): Unit
operator fun Memory.set(index: Int, value: Byte): Unit

Index write operator to write value at the specified index

storeAt

fun Memory.storeAt(index: Long, value: <ERROR CLASS>): Unit
fun Memory.storeAt(index: Int, value: <ERROR CLASS>): Unit

Index write operator to write value at the specified index

storeByteArray

fun Memory.storeByteArray(
    offset: Int,
    source: ByteArray,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit
fun Memory.storeByteArray(
    offset: Long,
    source: ByteArray,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit

Copies unsigned shorts integers from the source array at sourceOffset to this memory at the specified offset.

storeDoubleArray

expect fun Memory.storeDoubleArray(
    offset: Int,
    source: DoubleArray,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit
expect fun Memory.storeDoubleArray(
    offset: Long,
    source: DoubleArray,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit

Copies floating point numbers from the source array at sourceOffset to this memory at the specified offset interpreting numbers in the network order (Big Endian).

storeDoubleAt

expect fun Memory.storeDoubleAt(
    offset: Int,
    value: Double
): Unit
expect fun Memory.storeDoubleAt(
    offset: Long,
    value: Double
): Unit

Write short signed 64bit floating point number in the network byte order (Big Endian)

storeFloatArray

expect fun Memory.storeFloatArray(
    offset: Int,
    source: FloatArray,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit
expect fun Memory.storeFloatArray(
    offset: Long,
    source: FloatArray,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit

Copies floating point numbers from the source array at sourceOffset to this memory at the specified offset interpreting numbers in the network order (Big Endian).

storeFloatAt

expect fun Memory.storeFloatAt(
    offset: Int,
    value: Float
): Unit
expect fun Memory.storeFloatAt(
    offset: Long,
    value: Float
): Unit

Write short signed 32bit floating point number in the network byte order (Big Endian)

storeIntArray

expect fun Memory.storeIntArray(
    offset: Int,
    source: IntArray,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit
expect fun Memory.storeIntArray(
    offset: Long,
    source: IntArray,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit

Copies regular integers from the source array at sourceOffset to this memory at the specified offset interpreting numbers in the network order (Big Endian).

storeIntAt

expect fun Memory.storeIntAt(offset: Int, value: Int): Unit
expect fun Memory.storeIntAt(offset: Long, value: Int): Unit

Write regular signed 32bit integer in the network byte order (Big Endian)

storeLongArray

expect fun Memory.storeLongArray(
    offset: Int,
    source: LongArray,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit
expect fun Memory.storeLongArray(
    offset: Long,
    source: LongArray,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit

Copies long integers from the source array at sourceOffset to this memory at the specified offset interpreting numbers in the network order (Big Endian).

storeLongAt

expect fun Memory.storeLongAt(offset: Int, value: Long): Unit

Write short signed 64bit integer in the network byte order (Big Endian)

expect fun Memory.storeLongAt(
    offset: Long,
    value: Long
): Unit

write short signed 64bit integer in the network byte order (Big Endian)

storeShortArray

expect fun Memory.storeShortArray(
    offset: Int,
    source: ShortArray,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit
expect fun Memory.storeShortArray(
    offset: Long,
    source: ShortArray,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit

Copies shorts integers from the source array at sourceOffset to this memory at the specified offset interpreting numbers in the network order (Big Endian).

storeShortAt

expect fun Memory.storeShortAt(
    offset: Int,
    value: Short
): Unit
expect fun Memory.storeShortAt(
    offset: Long,
    value: Short
): Unit

Write short signed 16bit integer in the network byte order (Big Endian)

storeUByteArray

fun Memory.storeUByteArray(
    offset: Int,
    source: <ERROR CLASS>,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit
fun Memory.storeUByteArray(
    offset: Long,
    source: <ERROR CLASS>,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit

Copies unsigned shorts integers from the source array at sourceOffset to this memory at the specified offset.

storeUIntArray

fun Memory.storeUIntArray(
    offset: Int,
    source: <ERROR CLASS>,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit
fun Memory.storeUIntArray(
    offset: Long,
    source: <ERROR CLASS>,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit

Copies unsigned integers from the source array at sourceOffset to this memory at the specified offset interpreting numbers in the network order (Big Endian).

storeUIntAt

fun Memory.storeUIntAt(
    offset: Int,
    value: <ERROR CLASS>
): Unit
fun Memory.storeUIntAt(
    offset: Long,
    value: <ERROR CLASS>
): Unit

Write regular unsigned 32bit integer in the network byte order (Big Endian)

storeULongArray

fun Memory.storeULongArray(
    offset: Int,
    source: <ERROR CLASS>,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit
fun Memory.storeULongArray(
    offset: Long,
    source: <ERROR CLASS>,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit

Copies unsigned long integers from the source array at sourceOffset to this memory at the specified offset interpreting numbers in the network order (Big Endian).

storeULongAt

fun Memory.storeULongAt(
    offset: Int,
    value: <ERROR CLASS>
): Unit
fun Memory.storeULongAt(
    offset: Long,
    value: <ERROR CLASS>
): Unit

Write short signed 64bit integer in the network byte order (Big Endian)

storeUShortArray

fun Memory.storeUShortArray(
    offset: Int,
    source: <ERROR CLASS>,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit
fun Memory.storeUShortArray(
    offset: Long,
    source: <ERROR CLASS>,
    sourceOffset: Int = 0,
    count: Int = source.size - sourceOffset
): Unit

Copies unsigned shorts integers from the source array at sourceOffset to this memory at the specified offset interpreting numbers in the network order (Big Endian).

storeUShortAt

fun Memory.storeUShortAt(
    offset: Int,
    value: <ERROR CLASS>
): Unit
fun Memory.storeUShortAt(
    offset: Long,
    value: <ERROR CLASS>
): Unit

Write short unsigned 16bit integer in the network byte order (Big Endian)

withMemory

fun <R> withMemory(size: Int, block: (Memory) -> R): R
fun <R> withMemory(size: Long, block: (Memory) -> R): R

Invoke block function with a temporary Memory 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.

Companion Object Functions

of

fun Memory.Companion.of(
    array: ByteArray,
    offset: Int = 0,
    length: Int = array.size - offset
): Memory

Create Memory view for the specified array range starting at offset and the specified bytes length.

fun Memory.Companion.of(buffer: ByteBuffer): Memory

Create Memory view for the specified buffer range starting at ByteBuffer.position and ending at ByteBuffer.limit. Changing the original buffer’s position/limit will not affect previously created Memory instances.