diff --git a/korge-foundation/build.gradle.kts b/korge-foundation/build.gradle.kts index 1bc16dd828..2a3cca80b5 100644 --- a/korge-foundation/build.gradle.kts +++ b/korge-foundation/build.gradle.kts @@ -23,11 +23,11 @@ dependencies { //add("commonTestApi", project(":korge-test")) commonTestApi(libs.kotlinx.coroutines.test) commonMainApi(project(":korlibs-time")) + commonMainApi(project(":korlibs-datastructure")) commonMainApi(project(":korlibs-crypto")) commonMainApi(project(":korlibs-platform")) - commonMainApi(project(":korlibs-datastructure")) - commonMainApi(project(":korlibs-util")) commonMainApi(project(":korlibs-math-core")) - commonMainApi(project(":korlibs-inject")) + commonMainApi(project(":korlibs-memory")) commonMainApi(project(":korlibs-logger")) + commonMainApi(project(":korlibs-inject")) } diff --git a/korge-foundation/src/korlibs/memory/ByteArrayBuilderExtentions.kt b/korge-foundation/src/korlibs/memory/ByteArrayBuilderExtentions.kt new file mode 100644 index 0000000000..9f58edc783 --- /dev/null +++ b/korge-foundation/src/korlibs/memory/ByteArrayBuilderExtentions.kt @@ -0,0 +1,14 @@ +package korlibs.memory + +import korlibs.number.* + +/** + * Analogous to [StringBuilder] but for [ByteArray]. Allows to [append] values to end calling [toByteArray]. + * Provides some methods like [s16LE] or [f32BE] to append specific bit representations easily. + */ +fun ByteArrayBuilder.f16(v: Half, little: Boolean): ByteArrayBuilder = s16(v.rawBits.toInt(), little) +fun ByteArrayBuilder.f16LE(v: Half): ByteArrayBuilder = s16LE(v.rawBits.toInt()) +fun ByteArrayBuilder.f16BE(v: Half): ByteArrayBuilder = s16BE(v.rawBits.toInt()) + +fun ByteArrayBuilderLE.f16(v: Half): ByteArrayBuilder = bab.f16LE(v) +fun ByteArrayBuilderBE.f16(v: Half): ByteArrayBuilder = bab.f16BE(v) diff --git a/korge-foundation/src/korlibs/memory/ByteArrayExtention.kt b/korge-foundation/src/korlibs/memory/ByteArrayExtention.kt new file mode 100644 index 0000000000..d62e3913d1 --- /dev/null +++ b/korge-foundation/src/korlibs/memory/ByteArrayExtention.kt @@ -0,0 +1,17 @@ +package korlibs.memory + +import korlibs.number.Half + +private fun ByteArray.u8(offset: Int): Int = this[offset].toInt() and 0xFF +private inline fun ByteArray.get16LE(offset: Int): Int = (u8(offset + 0) shl 0) or (u8(offset + 1) shl 8) +private inline fun ByteArray.get16BE(offset: Int): Int = (u8(offset + 1) shl 0) or (u8(offset + 0) shl 8) + +// Signed +fun ByteArray.getF16LE(offset: Int): Half = Half.fromBits(get16LE(offset)) +fun ByteArray.getF16BE(offset: Int): Half = Half.fromBits(get16BE(offset)) + +// Custom Endian +fun ByteArray.getF16(offset: Int, littleEndian: Boolean): Half = if (littleEndian) getF16LE(offset) else getF16BE(offset) +fun ByteArray.setF16(offset: Int, value: Half, littleEndian: Boolean) { if (littleEndian) setF16LE(offset, value) else setF16BE(offset, value) } +fun ByteArray.setF16LE(offset: Int, value: Half) { set16LE(offset + 0, value.toRawBits().toInt()) } +fun ByteArray.setF16BE(offset: Int, value: Half) { set16BE(offset + 0, value.toRawBits().toInt()) } diff --git a/korge-foundation/src/korlibs/memory/ByteArrayReadWriteOldWithHalf.kt b/korge-foundation/src/korlibs/memory/ByteArrayReadWriteOldWithHalf.kt new file mode 100644 index 0000000000..70101d5f8d --- /dev/null +++ b/korge-foundation/src/korlibs/memory/ByteArrayReadWriteOldWithHalf.kt @@ -0,0 +1,16 @@ +package korlibs.memory + +import korlibs.number.Half + +@Deprecated("", ReplaceWith("getF16LE(o)")) +fun ByteArray.readF16LE(o: Int): Half = getF16LE(o) +@Deprecated("", ReplaceWith("getF16BE(o)")) +fun ByteArray.readF16BE(o: Int): Half = getF16BE(o) +@Deprecated("", ReplaceWith("getF16(o, little)")) +fun ByteArray.readF16(o: Int, little: Boolean): Half = getF16(o, little) +@Deprecated("", ReplaceWith("setF16(o, v, little)")) +fun ByteArray.writeF16(o: Int, v: Half, little: Boolean) = setF16(o, v, little) +@Deprecated("", ReplaceWith("setF16LE(o, v)")) +fun ByteArray.writeF16LE(o: Int, v: Half) = setF16LE(o, v) +@Deprecated("", ReplaceWith("setF16BE(o, v)")) +fun ByteArray.writeF16BE(o: Int, v: Half) = setF16BE(o, v) diff --git a/korge-foundation/src/korlibs/memory/ByteArrayReaderExtention.kt b/korge-foundation/src/korlibs/memory/ByteArrayReaderExtention.kt new file mode 100644 index 0000000000..b88b30c7e9 --- /dev/null +++ b/korge-foundation/src/korlibs/memory/ByteArrayReaderExtention.kt @@ -0,0 +1,10 @@ +package korlibs.memory + +import korlibs.number.* + + +fun ByteArrayReader.f16(little: Boolean): Half = Half.fromBits(s16(little)) +fun ByteArrayReader.f16LE(): Half = Half.fromBits(s16LE()) +fun ByteArrayReader.f16BE(): Half = Half.fromBits(s16BE()) +fun ByteArrayReaderLE.f16(): Half = bar.f16LE() +fun ByteArrayReaderBE.f16(): Half = bar.f16BE() diff --git a/korge-foundation/src/korlibs/number/Half.kt b/korge-foundation/src/korlibs/number/Half.kt index dfecbdd73e..6e9db25935 100644 --- a/korge-foundation/src/korlibs/number/Half.kt +++ b/korge-foundation/src/korlibs/number/Half.kt @@ -2,7 +2,7 @@ package korlibs.number -import korlibs.memory.* +import korlibs.memory.reinterpretAsFloat /** * Represents a floating point value of 16 bits. Also known as Half-precision floating-point format (IEEE 754-2008). diff --git a/korlibs-memory/.gitignore b/korlibs-memory/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/korlibs-memory/.gitignore @@ -0,0 +1 @@ +/build diff --git a/korlibs-memory/build.gradle.kts b/korlibs-memory/build.gradle.kts new file mode 100644 index 0000000000..8e3fba71c7 --- /dev/null +++ b/korlibs-memory/build.gradle.kts @@ -0,0 +1,21 @@ +import korlibs.* + +description = "Korlibs Memory" + +project.extensions.extraProperties.properties.apply { + applyProjectProperties( + "https://raw.githubusercontent.com/korlibs/korge/main/korlibs-memory", + "Public Domain", + "https://raw.githubusercontent.com/korlibs/korge/main/korlibs-memory/LICENSE" + ) +} + +dependencies { + commonMainApi(libs.kotlinx.coroutines.core) + commonMainApi(libs.kotlinx.atomicfu) + commonTestApi(libs.kotlinx.coroutines.test) + commonMainApi(project(":korlibs-math-core")) + commonMainApi(project(":korlibs-platform")) + commonMainApi(project(":korlibs-util")) + commonMainApi(project(":korlibs-crypto")) +} diff --git a/korge-foundation/src/korlibs/memory/Arrays.kt b/korlibs-memory/src/korlibs/memory/Arrays.kt similarity index 100% rename from korge-foundation/src/korlibs/memory/Arrays.kt rename to korlibs-memory/src/korlibs/memory/Arrays.kt diff --git a/korge-foundation/src/korlibs/memory/Bits.kt b/korlibs-memory/src/korlibs/memory/Bits.kt similarity index 99% rename from korge-foundation/src/korlibs/memory/Bits.kt rename to korlibs-memory/src/korlibs/memory/Bits.kt index ff66f5f788..0e3e958438 100644 --- a/korge-foundation/src/korlibs/memory/Bits.kt +++ b/korlibs-memory/src/korlibs/memory/Bits.kt @@ -3,7 +3,8 @@ package korlibs.memory -import korlibs.math.* +import korlibs.math.clamp01 +import korlibs.math.toInt import kotlin.rotateLeft as rotateLeftKotlin import kotlin.rotateRight as rotateRightKotlin diff --git a/korge-foundation/src/korlibs/memory/Buffer.kt b/korlibs-memory/src/korlibs/memory/Buffer.kt similarity index 99% rename from korge-foundation/src/korlibs/memory/Buffer.kt rename to korlibs-memory/src/korlibs/memory/Buffer.kt index 4cd1c181d2..46887f44dd 100644 --- a/korge-foundation/src/korlibs/memory/Buffer.kt +++ b/korlibs-memory/src/korlibs/memory/Buffer.kt @@ -2,7 +2,9 @@ package korlibs.memory -import korlibs.math.* +import korlibs.math.unsigned +import korlibs.math.clampUByte +import korlibs.math.clampUShort import kotlin.jvm.* typealias DataView = Buffer diff --git a/korge-foundation/src/korlibs/memory/ByteArrayBuilder.kt b/korlibs-memory/src/korlibs/memory/ByteArrayBuilder.kt similarity index 93% rename from korge-foundation/src/korlibs/memory/ByteArrayBuilder.kt rename to korlibs-memory/src/korlibs/memory/ByteArrayBuilder.kt index cc1272db3c..0cb14bbc45 100644 --- a/korge-foundation/src/korlibs/memory/ByteArrayBuilder.kt +++ b/korlibs-memory/src/korlibs/memory/ByteArrayBuilder.kt @@ -1,7 +1,6 @@ package korlibs.memory -import korlibs.number.* -import kotlin.math.* +import kotlin.math.max /** * Analogous to [StringBuilder] but for [ByteArray]. Allows to [append] values to end calling [toByteArray]. @@ -83,11 +82,6 @@ public class ByteArrayBuilder(public var data: ByteArray, size: Int = data.size, public fun s32(v: Int, little: Boolean): ByteArrayBuilder = this.apply { prepare(4) { data.set32(_size, v, little) } } public fun s32LE(v: Int): ByteArrayBuilder = this.apply { prepare(4) { data.set32LE(_size, v) } } public fun s32BE(v: Int): ByteArrayBuilder = this.apply { prepare(4) { data.set32BE(_size, v) } } - - public fun f16(v: Half, little: Boolean): ByteArrayBuilder = this.apply { prepare(2) { data.setF16(_size, v, little) } } - public fun f16LE(v: Half): ByteArrayBuilder = this.apply { prepare(2) { data.setF16LE(_size, v) } } - public fun f16BE(v: Half): ByteArrayBuilder = this.apply { prepare(2) { data.setF16BE(_size, v) } } - public fun f32(v: Float, little: Boolean): ByteArrayBuilder = this.apply { prepare(4) { data.setF32(_size, v, little) } } public fun f32LE(v: Float): ByteArrayBuilder = this.apply { prepare(4) { data.setF32LE(_size, v) } } public fun f32BE(v: Float): ByteArrayBuilder = this.apply { prepare(4) { data.setF32BE(_size, v) } } @@ -115,7 +109,6 @@ public fun ByteArrayBuilderLE.s8(v: Int): ByteArrayBuilder = bab.s8(v) public fun ByteArrayBuilderLE.s16(v: Int): ByteArrayBuilder = bab.s16LE(v) public fun ByteArrayBuilderLE.s24(v: Int): ByteArrayBuilder = bab.s24LE(v) public fun ByteArrayBuilderLE.s32(v: Int): ByteArrayBuilder = bab.s32LE(v) -public fun ByteArrayBuilderLE.f16(v: Half): ByteArrayBuilder = bab.f16LE(v) public fun ByteArrayBuilderLE.f32(v: Float): ByteArrayBuilder = bab.f32LE(v) public fun ByteArrayBuilderLE.f64(v: Double): ByteArrayBuilder = bab.f64LE(v) public fun ByteArrayBuilderLE.clear(): Unit = bab.clear() @@ -133,7 +126,6 @@ public fun ByteArrayBuilderBE.s8(v: Int): ByteArrayBuilder = bab.s8(v) public fun ByteArrayBuilderBE.s16(v: Int): ByteArrayBuilder = bab.s16BE(v) public fun ByteArrayBuilderBE.s24(v: Int): ByteArrayBuilder = bab.s24BE(v) public fun ByteArrayBuilderBE.s32(v: Int): ByteArrayBuilder = bab.s32BE(v) -public fun ByteArrayBuilderBE.f16(v: Half): ByteArrayBuilder = bab.f16BE(v) public fun ByteArrayBuilderBE.f32(v: Float): ByteArrayBuilder = bab.f32BE(v) public fun ByteArrayBuilderBE.f64(v: Double): ByteArrayBuilder = bab.f64BE(v) public fun ByteArrayBuilderBE.clear(): Unit = bab.clear() diff --git a/korge-foundation/src/korlibs/memory/ByteArrayGetSet.kt b/korlibs-memory/src/korlibs/memory/ByteArrayGetSet.kt similarity index 94% rename from korge-foundation/src/korlibs/memory/ByteArrayGetSet.kt rename to korlibs-memory/src/korlibs/memory/ByteArrayGetSet.kt index 0756d78e34..b28b6a8452 100644 --- a/korge-foundation/src/korlibs/memory/ByteArrayGetSet.kt +++ b/korlibs-memory/src/korlibs/memory/ByteArrayGetSet.kt @@ -1,7 +1,6 @@ package korlibs.memory -import korlibs.math.* -import korlibs.number.* +import korlibs.math.unsigned ///////////////////////////////////////// ///////////////////////////////////////// @@ -34,14 +33,12 @@ public fun ByteArray.getS16LE(offset: Int): Int = get16LE(offset).signExtend(16) public fun ByteArray.getS24LE(offset: Int): Int = get24LE(offset).signExtend(24) public fun ByteArray.getS32LE(offset: Int): Int = get32LE(offset) public fun ByteArray.getS64LE(offset: Int): Long = get64LE(offset) -public fun ByteArray.getF16LE(offset: Int): Half = Half.fromBits(get16LE(offset)) public fun ByteArray.getF32LE(offset: Int): Float = Float.fromBits(get32LE(offset)) public fun ByteArray.getF64LE(offset: Int): Double = Double.fromBits(get64LE(offset)) public fun ByteArray.getS16BE(offset: Int): Int = get16BE(offset).signExtend(16) public fun ByteArray.getS24BE(offset: Int): Int = get24BE(offset).signExtend(24) public fun ByteArray.getS32BE(offset: Int): Int = get32BE(offset) public fun ByteArray.getS64BE(offset: Int): Long = get64BE(offset) -public fun ByteArray.getF16BE(offset: Int): Half = Half.fromBits(get16BE(offset)) public fun ByteArray.getF32BE(offset: Int): Float = Float.fromBits(get32BE(offset)) public fun ByteArray.getF64BE(offset: Int): Double = Double.fromBits(get64BE(offset)) @@ -53,7 +50,6 @@ public fun ByteArray.getS16(offset: Int, littleEndian: Boolean): Int = if (littl public fun ByteArray.getS24(offset: Int, littleEndian: Boolean): Int = if (littleEndian) getS24LE(offset) else getS24BE(offset) public fun ByteArray.getS32(offset: Int, littleEndian: Boolean): Int = if (littleEndian) getS32LE(offset) else getS32BE(offset) public fun ByteArray.getS64(offset: Int, littleEndian: Boolean): Long = if (littleEndian) getS64LE(offset) else getS64BE(offset) -public fun ByteArray.getF16(offset: Int, littleEndian: Boolean): Half = if (littleEndian) getF16LE(offset) else getF16BE(offset) public fun ByteArray.getF32(offset: Int, littleEndian: Boolean): Float = if (littleEndian) getF32LE(offset) else getF32BE(offset) public fun ByteArray.getF64(offset: Int, littleEndian: Boolean): Double = if (littleEndian) getF64LE(offset) else getF64BE(offset) @@ -92,7 +88,6 @@ public fun ByteArray.set16(offset: Int, value: Int, littleEndian: Boolean) { if public fun ByteArray.set24(offset: Int, value: Int, littleEndian: Boolean) { if (littleEndian) set24LE(offset, value) else set24BE(offset, value) } public fun ByteArray.set32(offset: Int, value: Int, littleEndian: Boolean) { if (littleEndian) set32LE(offset, value) else set32BE(offset, value) } public fun ByteArray.set64(offset: Int, value: Long, littleEndian: Boolean) { if (littleEndian) set64LE(offset, value) else set64BE(offset, value) } -public fun ByteArray.setF16(offset: Int, value: Half, littleEndian: Boolean) { if (littleEndian) setF16LE(offset, value) else setF16BE(offset, value) } public fun ByteArray.setF32(offset: Int, value: Float, littleEndian: Boolean) { if (littleEndian) setF32LE(offset, value) else setF32BE(offset, value) } public fun ByteArray.setF64(offset: Int, value: Double, littleEndian: Boolean) { if (littleEndian) setF64LE(offset, value) else setF64BE(offset, value) } @@ -101,7 +96,6 @@ public fun ByteArray.set24LE(offset: Int, value: Int) { this[offset + 0] = value public fun ByteArray.set32LE(offset: Int, value: Int) { this[offset + 0] = value.extractByte(0); this[offset + 1] = value.extractByte(8); this[offset + 2] = value.extractByte(16); this[offset + 3] = value.extractByte(24) } public fun ByteArray.set32LE(offset: Int, value: Long) { set32LE(offset, value.toInt()) } public fun ByteArray.set64LE(offset: Int, value: Long) { set32LE(offset + 0, (value ushr 0).toInt()); set32LE(offset + 4, (value ushr 32).toInt()) } -public fun ByteArray.setF16LE(offset: Int, value: Half) { set16LE(offset + 0, value.toRawBits().toInt()) } public fun ByteArray.setF32LE(offset: Int, value: Float) { set32LE(offset + 0, value.toRawBits()) } public fun ByteArray.setF64LE(offset: Int, value: Double) { set64LE(offset + 0, value.toRawBits()) } @@ -110,7 +104,6 @@ public fun ByteArray.set24BE(offset: Int, value: Int) { this[offset + 2] = value public fun ByteArray.set32BE(offset: Int, value: Int) { this[offset + 3] = value.extractByte(0); this[offset + 2] = value.extractByte(8); this[offset + 1] = value.extractByte(16); this[offset + 0] = value.extractByte(24) } public fun ByteArray.set32BE(offset: Int, value: Long) { set32BE(offset, value.toInt()) } public fun ByteArray.set64BE(offset: Int, value: Long) { set32BE(offset + 0, (value ushr 32).toInt()); set32BE(offset + 4, (value ushr 0).toInt()) } -public fun ByteArray.setF16BE(offset: Int, value: Half) { set16BE(offset + 0, value.toRawBits().toInt()) } public fun ByteArray.setF32BE(offset: Int, value: Float) { set32BE(offset + 0, value.toRawBits()) } public fun ByteArray.setF64BE(offset: Int, value: Double) { set64BE(offset + 0, value.toRawBits()) } diff --git a/korge-foundation/src/korlibs/memory/ByteArrayReadWriteOld.kt b/korlibs-memory/src/korlibs/memory/ByteArrayReadWriteOld.kt similarity index 93% rename from korge-foundation/src/korlibs/memory/ByteArrayReadWriteOld.kt rename to korlibs-memory/src/korlibs/memory/ByteArrayReadWriteOld.kt index 20ad95f87e..1c5f274052 100644 --- a/korge-foundation/src/korlibs/memory/ByteArrayReadWriteOld.kt +++ b/korlibs-memory/src/korlibs/memory/ByteArrayReadWriteOld.kt @@ -1,7 +1,5 @@ package korlibs.memory -import korlibs.number.* - ///////////////////////////////////////// ///////////////////////////////////////// ///////////////////////////////////////// @@ -21,14 +19,12 @@ import korlibs.number.* @Deprecated("", ReplaceWith("getS24LE(o)")) public fun ByteArray.readS24LE(o: Int): Int = getS24LE(o) @Deprecated("", ReplaceWith("getS32LE(o)")) public fun ByteArray.readS32LE(o: Int): Int = getS32LE(o) @Deprecated("", ReplaceWith("getS64LE(o)")) public fun ByteArray.readS64LE(o: Int): Long = getS64LE(o) -@Deprecated("", ReplaceWith("getF16LE(o)")) public fun ByteArray.readF16LE(o: Int): Half = getF16LE(o) @Deprecated("", ReplaceWith("getF32LE(o)")) public fun ByteArray.readF32LE(o: Int): Float = getF32LE(o) @Deprecated("", ReplaceWith("getF64LE(o)")) public fun ByteArray.readF64LE(o: Int): Double = getF64LE(o) @Deprecated("", ReplaceWith("getS16BE(o)")) public fun ByteArray.readS16BE(o: Int): Int = getS16BE(o) @Deprecated("", ReplaceWith("getS24BE(o)")) public fun ByteArray.readS24BE(o: Int): Int = getS24BE(o) @Deprecated("", ReplaceWith("getS32BE(o)")) public fun ByteArray.readS32BE(o: Int): Int = getS32BE(o) @Deprecated("", ReplaceWith("getS64BE(o)")) public fun ByteArray.readS64BE(o: Int): Long = getS64BE(o) -@Deprecated("", ReplaceWith("getF16BE(o)")) public fun ByteArray.readF16BE(o: Int): Half = getF16BE(o) @Deprecated("", ReplaceWith("getF32BE(o)")) public fun ByteArray.readF32BE(o: Int): Float = getF32BE(o) @Deprecated("", ReplaceWith("getF64BE(o)")) public fun ByteArray.readF64BE(o: Int): Double = getF64BE(o) @@ -40,7 +36,6 @@ import korlibs.number.* @Deprecated("", ReplaceWith("getS24(o, little)")) public fun ByteArray.readS24(o: Int, little: Boolean): Int = getS24(o, little) @Deprecated("", ReplaceWith("getS32(o, little)")) public fun ByteArray.readS32(o: Int, little: Boolean): Int = getS32(o, little) @Deprecated("", ReplaceWith("getS64(o, little)")) public fun ByteArray.readS64(o: Int, little: Boolean): Long = getS64(o, little) -@Deprecated("", ReplaceWith("getF16(o, little)")) public fun ByteArray.readF16(o: Int, little: Boolean): Half = getF16(o, little) @Deprecated("", ReplaceWith("getF32(o, little)")) public fun ByteArray.readF32(o: Int, little: Boolean): Float = getF32(o, little) @Deprecated("", ReplaceWith("getF64(o, little)")) public fun ByteArray.readF64(o: Int, little: Boolean): Double = getF64(o, little) @@ -75,7 +70,6 @@ import korlibs.number.* @Deprecated("", ReplaceWith("set24(o, v, little)")) public fun ByteArray.write24(o: Int, v: Int, little: Boolean) = set24(o, v, little) @Deprecated("", ReplaceWith("set32(o, v, little)")) public fun ByteArray.write32(o: Int, v: Int, little: Boolean) = set32(o, v, little) @Deprecated("", ReplaceWith("set64(o, v, little)")) public fun ByteArray.write64(o: Int, v: Long, little: Boolean) = set64(o, v, little) -@Deprecated("", ReplaceWith("setF16(o, v, little)")) public fun ByteArray.writeF16(o: Int, v: Half, little: Boolean) = setF16(o, v, little) @Deprecated("", ReplaceWith("setF32(o, v, little)")) public fun ByteArray.writeF32(o: Int, v: Float, little: Boolean) = setF32(o, v, little) @Deprecated("", ReplaceWith("setF64(o, v, little)")) public fun ByteArray.writeF64(o: Int, v: Double, little: Boolean) = setF64(o, v, little) @@ -84,7 +78,6 @@ import korlibs.number.* @Deprecated("", ReplaceWith("set32LE(o, v)")) public fun ByteArray.write32LE(o: Int, v: Int) = set32LE(o, v) @Deprecated("", ReplaceWith("set32LE(o, v)")) public fun ByteArray.write32LE(o: Int, v: Long) = set32LE(o, v) @Deprecated("", ReplaceWith("set64LE(o, v)")) public fun ByteArray.write64LE(o: Int, v: Long) = set64LE(o, v) -@Deprecated("", ReplaceWith("setF16LE(o, v)")) public fun ByteArray.writeF16LE(o: Int, v: Half) = setF16LE(o, v) @Deprecated("", ReplaceWith("setF32LE(o, v)")) public fun ByteArray.writeF32LE(o: Int, v: Float) = setF32LE(o, v) @Deprecated("", ReplaceWith("setF64LE(o, v)")) public fun ByteArray.writeF64LE(o: Int, v: Double) = setF64LE(o, v) @@ -93,7 +86,6 @@ import korlibs.number.* @Deprecated("", ReplaceWith("set32BE(o, v)")) public fun ByteArray.write32BE(o: Int, v: Int) = set32BE(o, v) @Deprecated("", ReplaceWith("set32BE(o, v)")) public fun ByteArray.write32BE(o: Int, v: Long) = set32BE(o, v) @Deprecated("", ReplaceWith("set64BE(o, v)")) public fun ByteArray.write64BE(o: Int, v: Long) = set64BE(o, v) -@Deprecated("", ReplaceWith("setF16BE(o, v)")) public fun ByteArray.writeF16BE(o: Int, v: Half) = setF16BE(o, v) @Deprecated("", ReplaceWith("setF32BE(o, v)")) public fun ByteArray.writeF32BE(o: Int, v: Float) = setF32BE(o, v) @Deprecated("", ReplaceWith("setF64BE(o, v)")) public fun ByteArray.writeF64BE(o: Int, v: Double) = setF64BE(o, v) diff --git a/korge-foundation/src/korlibs/memory/ByteArrayReader.kt b/korlibs-memory/src/korlibs/memory/ByteArrayReader.kt similarity index 93% rename from korge-foundation/src/korlibs/memory/ByteArrayReader.kt rename to korlibs-memory/src/korlibs/memory/ByteArrayReader.kt index 07bfc4a44d..91821e6a93 100644 --- a/korge-foundation/src/korlibs/memory/ByteArrayReader.kt +++ b/korlibs-memory/src/korlibs/memory/ByteArrayReader.kt @@ -1,7 +1,5 @@ package korlibs.memory -import korlibs.number.* - public class ByteArrayReader(public val data: ByteArray, public val start: Int, public val size: Int = 0) { private var offset = start public val remaining: Int get() = size - offset @@ -36,10 +34,6 @@ public class ByteArrayReader(public val data: ByteArray, public val start: Int, public fun s32LE(): Int = move(4) { getS32LE(it) } public fun u32BE(): Long = move(4) { getU32BE(it) } public fun s32BE(): Int = move(4) { getS32BE(it) } - - public fun f16(little: Boolean): Half = move(2) { getF16(it, little) } - public fun f16LE(): Half = move(2) { getF16LE(it) } - public fun f16BE(): Half = move(2) { getF16BE(it) } public fun f32(little: Boolean): Float = move(4) { getF32(it, little) } public fun f32LE(): Float = move(4) { getF32LE(it) } public fun f32BE(): Float = move(4) { getF32BE(it) } @@ -61,7 +55,6 @@ public fun ByteArrayReaderLE.u24(): Int = bar.u24LE() public fun ByteArrayReaderLE.s24(): Int = bar.s24LE() public fun ByteArrayReaderLE.u32(): Long = bar.u32LE() public fun ByteArrayReaderLE.s32(): Int = bar.s32LE() -public fun ByteArrayReaderLE.f16(): Half = bar.f16LE() public fun ByteArrayReaderLE.f32(): Float = bar.f32LE() public fun ByteArrayReaderLE.f64(): Double = bar.f64LE() @@ -78,7 +71,6 @@ public fun ByteArrayReaderBE.u24(): Int = bar.u24BE() public fun ByteArrayReaderBE.s24(): Int = bar.s24BE() public fun ByteArrayReaderBE.u32(): Long = bar.u32BE() public fun ByteArrayReaderBE.s32(): Int = bar.s32BE() -public fun ByteArrayReaderBE.f16(): Half = bar.f16BE() public fun ByteArrayReaderBE.f32(): Float = bar.f32BE() public fun ByteArrayReaderBE.f64(): Double = bar.f64BE() diff --git a/korge-foundation/src/korlibs/memory/FixedSizeByteArrayBuilder.kt b/korlibs-memory/src/korlibs/memory/FixedSizeByteArrayBuilder.kt similarity index 100% rename from korge-foundation/src/korlibs/memory/FixedSizeByteArrayBuilder.kt rename to korlibs-memory/src/korlibs/memory/FixedSizeByteArrayBuilder.kt diff --git a/korge-foundation/src/korlibs/memory/KmemGC.kt b/korlibs-memory/src/korlibs/memory/KmemGC.kt similarity index 100% rename from korge-foundation/src/korlibs/memory/KmemGC.kt rename to korlibs-memory/src/korlibs/memory/KmemGC.kt diff --git a/korge-foundation/src/korlibs/memory/_Memory_unit.kt b/korlibs-memory/src/korlibs/memory/_Memory_unit.kt similarity index 100% rename from korge-foundation/src/korlibs/memory/_Memory_unit.kt rename to korlibs-memory/src/korlibs/memory/_Memory_unit.kt diff --git a/korge-foundation/src@darwin/korlibs/memory/Buffer.native.kt b/korlibs-memory/src@darwin/korlibs/memory/Buffer.native.kt similarity index 100% rename from korge-foundation/src@darwin/korlibs/memory/Buffer.native.kt rename to korlibs-memory/src@darwin/korlibs/memory/Buffer.native.kt diff --git a/korge-foundation/src@darwin/korlibs/memory/KmemGCNative.kt b/korlibs-memory/src@darwin/korlibs/memory/KmemGCNative.kt similarity index 100% rename from korge-foundation/src@darwin/korlibs/memory/KmemGCNative.kt rename to korlibs-memory/src@darwin/korlibs/memory/KmemGCNative.kt diff --git a/korge-foundation/src@darwin/korlibs/memory/MemExt.kt b/korlibs-memory/src@darwin/korlibs/memory/MemExt.kt similarity index 100% rename from korge-foundation/src@darwin/korlibs/memory/MemExt.kt rename to korlibs-memory/src@darwin/korlibs/memory/MemExt.kt diff --git a/korge-foundation/src@darwin/korlibs/memory/NInt.kt b/korlibs-memory/src@darwin/korlibs/memory/NInt.kt similarity index 100% rename from korge-foundation/src@darwin/korlibs/memory/NInt.kt rename to korlibs-memory/src@darwin/korlibs/memory/NInt.kt diff --git a/korge-foundation/src@js/korlibs/memory/Buffer.js.kt b/korlibs-memory/src@js/korlibs/memory/Buffer.js.kt similarity index 100% rename from korge-foundation/src@js/korlibs/memory/Buffer.js.kt rename to korlibs-memory/src@js/korlibs/memory/Buffer.js.kt diff --git a/korge-foundation/src@js/korlibs/memory/KmemGCJs.kt b/korlibs-memory/src@js/korlibs/memory/KmemGCJs.kt similarity index 100% rename from korge-foundation/src@js/korlibs/memory/KmemGCJs.kt rename to korlibs-memory/src@js/korlibs/memory/KmemGCJs.kt diff --git a/korge-foundation/src@jvmAndroid/korlibs/memory/Buffer.jvm.kt b/korlibs-memory/src@jvmAndroid/korlibs/memory/Buffer.jvm.kt similarity index 100% rename from korge-foundation/src@jvmAndroid/korlibs/memory/Buffer.jvm.kt rename to korlibs-memory/src@jvmAndroid/korlibs/memory/Buffer.jvm.kt diff --git a/korge-foundation/src@jvmAndroid/korlibs/memory/KmemGCJvm.kt b/korlibs-memory/src@jvmAndroid/korlibs/memory/KmemGCJvm.kt similarity index 100% rename from korge-foundation/src@jvmAndroid/korlibs/memory/KmemGCJvm.kt rename to korlibs-memory/src@jvmAndroid/korlibs/memory/KmemGCJvm.kt diff --git a/korge-foundation/src@wasmJs/korlibs/memory/Buffer.wasmJs.kt b/korlibs-memory/src@wasmJs/korlibs/memory/Buffer.wasmJs.kt similarity index 100% rename from korge-foundation/src@wasmJs/korlibs/memory/Buffer.wasmJs.kt rename to korlibs-memory/src@wasmJs/korlibs/memory/Buffer.wasmJs.kt diff --git a/korge-foundation/src@wasmJs/korlibs/memory/KmemGCWasm.kt b/korlibs-memory/src@wasmJs/korlibs/memory/KmemGCWasm.kt similarity index 100% rename from korge-foundation/src@wasmJs/korlibs/memory/KmemGCWasm.kt rename to korlibs-memory/src@wasmJs/korlibs/memory/KmemGCWasm.kt diff --git a/korge-foundation/src@wasmJs/korlibs/memory/wasm/ArrayConversionExt.kt b/korlibs-memory/src@wasmJs/korlibs/memory/wasm/ArrayConversionExt.kt similarity index 100% rename from korge-foundation/src@wasmJs/korlibs/memory/wasm/ArrayConversionExt.kt rename to korlibs-memory/src@wasmJs/korlibs/memory/wasm/ArrayConversionExt.kt diff --git a/korge-foundation/test/korlibs/memory/AlignmentTest.kt b/korlibs-memory/test/korlibs/memory/AlignmentTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/AlignmentTest.kt rename to korlibs-memory/test/korlibs/memory/AlignmentTest.kt diff --git a/korge-foundation/test/korlibs/memory/ArrayCopyTest.kt b/korlibs-memory/test/korlibs/memory/ArrayCopyTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/ArrayCopyTest.kt rename to korlibs-memory/test/korlibs/memory/ArrayCopyTest.kt diff --git a/korge-foundation/test/korlibs/memory/ArrayEqualTest.kt b/korlibs-memory/test/korlibs/memory/ArrayEqualTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/ArrayEqualTest.kt rename to korlibs-memory/test/korlibs/memory/ArrayEqualTest.kt diff --git a/korge-foundation/test/korlibs/memory/ArrayExtTest.kt b/korlibs-memory/test/korlibs/memory/ArrayExtTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/ArrayExtTest.kt rename to korlibs-memory/test/korlibs/memory/ArrayExtTest.kt diff --git a/korge-foundation/test/korlibs/memory/ArrayFillTest.kt b/korlibs-memory/test/korlibs/memory/ArrayFillTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/ArrayFillTest.kt rename to korlibs-memory/test/korlibs/memory/ArrayFillTest.kt diff --git a/korge-foundation/test/korlibs/memory/ArraysTest.kt b/korlibs-memory/test/korlibs/memory/ArraysTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/ArraysTest.kt rename to korlibs-memory/test/korlibs/memory/ArraysTest.kt diff --git a/korge-foundation/test/korlibs/memory/BaseBufferTest.kt b/korlibs-memory/test/korlibs/memory/BaseBufferTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/BaseBufferTest.kt rename to korlibs-memory/test/korlibs/memory/BaseBufferTest.kt diff --git a/korge-foundation/test/korlibs/memory/BitsTest.kt b/korlibs-memory/test/korlibs/memory/BitsTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/BitsTest.kt rename to korlibs-memory/test/korlibs/memory/BitsTest.kt diff --git a/korge-foundation/test/korlibs/memory/BufferTest.kt b/korlibs-memory/test/korlibs/memory/BufferTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/BufferTest.kt rename to korlibs-memory/test/korlibs/memory/BufferTest.kt diff --git a/korge-foundation/test/korlibs/memory/ByteArrayBuilderTest.kt b/korlibs-memory/test/korlibs/memory/ByteArrayBuilderTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/ByteArrayBuilderTest.kt rename to korlibs-memory/test/korlibs/memory/ByteArrayBuilderTest.kt diff --git a/korge-foundation/test/korlibs/memory/ByteArrayReadWriteTest.kt b/korlibs-memory/test/korlibs/memory/ByteArrayReadWriteTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/ByteArrayReadWriteTest.kt rename to korlibs-memory/test/korlibs/memory/ByteArrayReadWriteTest.kt diff --git a/korge-foundation/test/korlibs/memory/ByteArrayReaderTest.kt b/korlibs-memory/test/korlibs/memory/ByteArrayReaderTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/ByteArrayReaderTest.kt rename to korlibs-memory/test/korlibs/memory/ByteArrayReaderTest.kt diff --git a/korge-foundation/test/korlibs/memory/ConvertRangeTest.kt b/korlibs-memory/test/korlibs/memory/ConvertRangeTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/ConvertRangeTest.kt rename to korlibs-memory/test/korlibs/memory/ConvertRangeTest.kt diff --git a/korge-foundation/test/korlibs/memory/FastForEachOneBits.kt b/korlibs-memory/test/korlibs/memory/FastForEachOneBits.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/FastForEachOneBits.kt rename to korlibs-memory/test/korlibs/memory/FastForEachOneBits.kt diff --git a/korge-foundation/test/korlibs/memory/FloatZeroNanInfinite.kt b/korlibs-memory/test/korlibs/memory/FloatZeroNanInfinite.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/FloatZeroNanInfinite.kt rename to korlibs-memory/test/korlibs/memory/FloatZeroNanInfinite.kt diff --git a/korge-foundation/test/korlibs/memory/IntDivExtTest.kt b/korlibs-memory/test/korlibs/memory/IntDivExtTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/IntDivExtTest.kt rename to korlibs-memory/test/korlibs/memory/IntDivExtTest.kt diff --git a/korge-foundation/test/korlibs/memory/NBufferTest.kt b/korlibs-memory/test/korlibs/memory/NBufferTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/NBufferTest.kt rename to korlibs-memory/test/korlibs/memory/NBufferTest.kt diff --git a/korge-foundation/test/korlibs/memory/NBufferTest2.kt b/korlibs-memory/test/korlibs/memory/NBufferTest2.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/NBufferTest2.kt rename to korlibs-memory/test/korlibs/memory/NBufferTest2.kt diff --git a/korge-foundation/test/korlibs/memory/NumbersTest.kt b/korlibs-memory/test/korlibs/memory/NumbersTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/NumbersTest.kt rename to korlibs-memory/test/korlibs/memory/NumbersTest.kt diff --git a/korge-foundation/test/korlibs/memory/ToIntExt.kt b/korlibs-memory/test/korlibs/memory/ToIntExt.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/ToIntExt.kt rename to korlibs-memory/test/korlibs/memory/ToIntExt.kt diff --git a/korge-foundation/test/korlibs/memory/UModTest.kt b/korlibs-memory/test/korlibs/memory/UModTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/UModTest.kt rename to korlibs-memory/test/korlibs/memory/UModTest.kt diff --git a/korge-foundation/test/korlibs/memory/UnsignedTest.kt b/korlibs-memory/test/korlibs/memory/UnsignedTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/UnsignedTest.kt rename to korlibs-memory/test/korlibs/memory/UnsignedTest.kt diff --git a/korge-foundation/test/korlibs/memory/dyn/DynamicLibraryCommonTest.kt b/korlibs-memory/test/korlibs/memory/dyn/DynamicLibraryCommonTest.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/dyn/DynamicLibraryCommonTest.kt rename to korlibs-memory/test/korlibs/memory/dyn/DynamicLibraryCommonTest.kt diff --git a/korge-foundation/test/korlibs/memory/internal.kt b/korlibs-memory/test/korlibs/memory/internal.kt similarity index 100% rename from korge-foundation/test/korlibs/memory/internal.kt rename to korlibs-memory/test/korlibs/memory/internal.kt diff --git a/korge-foundation/test@darwin/korlibs/memory/MemExtTest.kt b/korlibs-memory/test@darwin/korlibs/memory/MemExtTest.kt similarity index 100% rename from korge-foundation/test@darwin/korlibs/memory/MemExtTest.kt rename to korlibs-memory/test@darwin/korlibs/memory/MemExtTest.kt diff --git a/korge-foundation/test@darwin/korlibs/memory/dyn/DynamicLibraryNativeTest.kt b/korlibs-memory/test@darwin/korlibs/memory/dyn/DynamicLibraryNativeTest.kt similarity index 100% rename from korge-foundation/test@darwin/korlibs/memory/dyn/DynamicLibraryNativeTest.kt rename to korlibs-memory/test@darwin/korlibs/memory/dyn/DynamicLibraryNativeTest.kt diff --git a/settings.gradle.kts b/settings.gradle.kts index 975dc25168..b0e42274b7 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -29,6 +29,7 @@ include(":korlibs-concurrent") include(":korlibs-logger") include(":korlibs-platform") include(":korlibs-datastructure") +include(":korlibs-memory") include(":korlibs-util") include(":korlibs-math-core") include(":korlibs-inject")