[K/N] Experimental ByteArray.get/setPrimitiveAt(index) functions

As a part of Native stdlib stabilization efforts.

Merge-request: KT-MR-9346
Merged-by: Abduqodiri Qurbonzoda <abduqodiri.qurbonzoda@jetbrains.com>
This commit is contained in:
Abduqodiri Qurbonzoda
2023-04-17 12:42:31 +00:00
committed by Space Team
parent aceab2ac1f
commit 12f7a6de3e
@@ -4,6 +4,7 @@
*/
package kotlin.native
import kotlin.experimental.ExperimentalNativeApi
import kotlin.native.internal.GCUnsafeCall
/**
@@ -16,13 +17,14 @@ import kotlin.native.internal.GCUnsafeCall
* Gets [UByte] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalUnsignedTypes
@ExperimentalNativeApi
public fun ByteArray.getUByteAt(index: Int): UByte = UByte(get(index))
/**
* Gets [Char] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_getCharAt")
public external fun ByteArray.getCharAt(index: Int): Char
@@ -30,6 +32,7 @@ public external fun ByteArray.getCharAt(index: Int): Char
* Gets [Short] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_getShortAt")
public external fun ByteArray.getShortAt(index: Int): Short
@@ -37,6 +40,7 @@ public external fun ByteArray.getShortAt(index: Int): Short
* Gets [UShort] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_getShortAt")
@ExperimentalUnsignedTypes
public external fun ByteArray.getUShortAt(index: Int): UShort
@@ -45,6 +49,7 @@ public external fun ByteArray.getUShortAt(index: Int): UShort
* Gets [Int] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_getIntAt")
public external fun ByteArray.getIntAt(index: Int): Int
@@ -52,6 +57,7 @@ public external fun ByteArray.getIntAt(index: Int): Int
* Gets [UInt] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_getIntAt")
@ExperimentalUnsignedTypes
public external fun ByteArray.getUIntAt(index: Int): UInt
@@ -60,6 +66,7 @@ public external fun ByteArray.getUIntAt(index: Int): UInt
* Gets [Long] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_getLongAt")
public external fun ByteArray.getLongAt(index: Int): Long
@@ -67,6 +74,7 @@ public external fun ByteArray.getLongAt(index: Int): Long
* Gets [ULong] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_getLongAt")
@ExperimentalUnsignedTypes
public external fun ByteArray.getULongAt(index: Int): ULong
@@ -75,6 +83,7 @@ public external fun ByteArray.getULongAt(index: Int): ULong
* Gets [Float] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_getFloatAt")
public external fun ByteArray.getFloatAt(index: Int): Float
@@ -82,6 +91,7 @@ public external fun ByteArray.getFloatAt(index: Int): Float
* Gets [Double] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_getDoubleAt")
public external fun ByteArray.getDoubleAt(index: Int): Double
@@ -89,6 +99,7 @@ public external fun ByteArray.getDoubleAt(index: Int): Double
* Sets [UByte] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_set")
public external fun ByteArray.setUByteAt(index: Int, value: UByte)
@@ -96,6 +107,7 @@ public external fun ByteArray.setUByteAt(index: Int, value: UByte)
* Sets [Char] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_setCharAt")
public external fun ByteArray.setCharAt(index: Int, value: Char)
@@ -103,6 +115,7 @@ public external fun ByteArray.setCharAt(index: Int, value: Char)
* Sets [Short] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_setShortAt")
public external fun ByteArray.setShortAt(index: Int, value: Short)
@@ -110,6 +123,7 @@ public external fun ByteArray.setShortAt(index: Int, value: Short)
* Sets [UShort] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_setShortAt")
@ExperimentalUnsignedTypes
public external fun ByteArray.setUShortAt(index: Int, value: UShort)
@@ -118,6 +132,7 @@ public external fun ByteArray.setUShortAt(index: Int, value: UShort)
* Sets [Int] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_setIntAt")
public external fun ByteArray.setIntAt(index: Int, value: Int)
@@ -125,6 +140,7 @@ public external fun ByteArray.setIntAt(index: Int, value: Int)
* Sets [UInt] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_setIntAt")
public external fun ByteArray.setUIntAt(index: Int, value: UInt)
@@ -132,6 +148,7 @@ public external fun ByteArray.setUIntAt(index: Int, value: UInt)
* Sets [Long] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_setLongAt")
public external fun ByteArray.setLongAt(index: Int, value: Long)
@@ -139,6 +156,7 @@ public external fun ByteArray.setLongAt(index: Int, value: Long)
* Sets [ULong] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_setLongAt")
@ExperimentalUnsignedTypes
public external fun ByteArray.setULongAt(index: Int, value: ULong)
@@ -147,6 +165,7 @@ public external fun ByteArray.setULongAt(index: Int, value: ULong)
* Sets [Float] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_setFloatAt")
public external fun ByteArray.setFloatAt(index: Int, value: Float)
@@ -154,5 +173,6 @@ public external fun ByteArray.setFloatAt(index: Int, value: Float)
* Sets [Double] out of the [ByteArray] byte buffer at specified index [index]
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalNativeApi
@GCUnsafeCall("Kotlin_ByteArray_setDoubleAt")
public external fun ByteArray.setDoubleAt(index: Int, value: Double)