1.3.2 release #7

Merged
Infendro merged 3 commits from develop into main 2026-01-15 15:23:33 +00:00
4 changed files with 50 additions and 26 deletions
Showing only changes of commit d7e65ccc32 - Show all commits

View File

@@ -12,6 +12,6 @@ repositories {
}
commonMain.dependencies {
implementation("com.infendro:bytes:1.3.1")
implementation("com.infendro:bytes:1.3.2")
}
```

View File

@@ -5,7 +5,7 @@ import com.infendro.plugin.token
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
group = "com.infendro"
version = "1.3.1"
version = "1.3.2"
plugins {
alias(libs.plugins.infendro)

View File

@@ -9,12 +9,16 @@ fun ByteArray.toInt(startIndex: Int = 0, order: ByteOrder = BIG_ENDIAN): Int {
return when (order) {
BIG_ENDIAN -> {
(this[startIndex].toInt() shl 24) or (this[startIndex + 1].toInt() shl 16) or
(this[startIndex + 2].toInt() shl 8) or this[startIndex + 3].toInt()
((this[startIndex].toInt() and 0xFF) shl 24) or
((this[startIndex + 1].toInt() and 0xFF) shl 16) or
((this[startIndex + 2].toInt() and 0xFF) shl 8) or
(this[startIndex + 3].toInt() and 0xFF)
}
LITTLE_ENDIAN -> {
this[startIndex].toInt() or (this[startIndex + 1].toInt() shl 8) or
(this[startIndex + 2].toInt() shl 16) or (this[startIndex + 3].toInt() shl 24)
(this[startIndex].toInt() and 0xFF) or
((this[startIndex + 1].toInt() and 0xFF) shl 8) or
((this[startIndex + 2].toInt() and 0xFF) shl 16) or
((this[startIndex + 3].toInt() and 0xFF) shl 24)
}
}
}
@@ -33,16 +37,24 @@ fun ByteArray.toLong(startIndex: Int = 0, order: ByteOrder = BIG_ENDIAN): Long {
return when (order) {
BIG_ENDIAN -> {
(this[startIndex].toLong() shl 56) or (this[startIndex + 1].toLong() shl 48) or
(this[startIndex + 2].toLong() shl 40) or (this[startIndex + 3].toLong() shl 32) or
(this[startIndex + 4].toLong() shl 24) or (this[startIndex + 5].toLong() shl 16) or
(this[startIndex + 6].toLong() shl 8) or this[startIndex + 7].toLong()
((this[startIndex].toLong() and 0xFFL) shl 56) or
((this[startIndex + 1].toLong() and 0xFFL) shl 48) or
((this[startIndex + 2].toLong() and 0xFFL) shl 40) or
((this[startIndex + 3].toLong() and 0xFFL) shl 32) or
((this[startIndex + 4].toLong() and 0xFFL) shl 24) or
((this[startIndex + 5].toLong() and 0xFFL) shl 16) or
((this[startIndex + 6].toLong() and 0xFFL) shl 8) or
(this[startIndex + 7].toLong() and 0xFFL)
}
LITTLE_ENDIAN -> {
this[startIndex].toLong() or (this[startIndex + 1].toLong() shl 8) or
(this[startIndex + 2].toLong() shl 16) or (this[startIndex + 3].toLong() shl 24) or
(this[startIndex + 4].toLong() shl 32) or (this[startIndex + 5].toLong() shl 40) or
(this[startIndex + 6].toLong() shl 48) or (this[startIndex + 7].toLong() shl 56)
(this[startIndex].toLong() and 0xFFL) or
((this[startIndex + 1].toLong() and 0xFFL) shl 8) or
((this[startIndex + 2].toLong() and 0xFFL) shl 16) or
((this[startIndex + 3].toLong() and 0xFFL) shl 24) or
((this[startIndex + 4].toLong() and 0xFFL) shl 32) or
((this[startIndex + 5].toLong() and 0xFFL) shl 40) or
((this[startIndex + 6].toLong() and 0xFFL) shl 48) or
((this[startIndex + 7].toLong() and 0xFFL) shl 56)
}
}
}

View File

@@ -21,16 +21,20 @@ fun ByteArray.copyInto(
repeat(length / 4) { i ->
val offset = startIndex + (i * 4)
destination[destinationOffset + i] =
(this[offset].toInt() shl 24) or (this[offset + 1].toInt() shl 16) or
(this[offset + 2].toInt() shl 8) or this[offset + 3].toInt()
((this[offset].toInt() and 0xFF) shl 24) or
((this[offset + 1].toInt() and 0xFF) shl 16) or
((this[offset + 2].toInt() and 0xFF) shl 8) or
(this[offset + 3].toInt() and 0xFF)
}
}
LITTLE_ENDIAN -> {
repeat(length / 4) { i ->
val offset = startIndex + (i * 4)
destination[destinationOffset + i] =
this[offset].toInt() or (this[offset + 1].toInt() shl 8) or
(this[offset + 2].toInt() shl 16) or (this[offset + 3].toInt() shl 24)
(this[offset].toInt() and 0xFF) or
((this[offset + 1].toInt() and 0xFF) shl 8) or
((this[offset + 2].toInt() and 0xFF) shl 16) or
((this[offset + 3].toInt() and 0xFF) shl 24)
}
}
}
@@ -61,20 +65,28 @@ fun ByteArray.copyInto(
repeat(length / 8) { i ->
val offset = startIndex + (i * 8)
destination[destinationOffset + i] =
(this[offset].toLong() shl 56) or (this[offset + 1].toLong() shl 48) or
(this[offset + 2].toLong() shl 40) or (this[offset + 3].toLong() shl 32) or
(this[offset + 4].toLong() shl 24) or (this[offset + 5].toLong() shl 16) or
(this[offset + 6].toLong() shl 8) or this[offset + 7].toLong()
((this[offset].toLong() and 0xFFL) shl 56) or
((this[offset + 1].toLong() and 0xFFL) shl 48) or
((this[offset + 2].toLong() and 0xFFL) shl 40) or
((this[offset + 3].toLong() and 0xFFL) shl 32) or
((this[offset + 4].toLong() and 0xFFL) shl 24) or
((this[offset + 5].toLong() and 0xFFL) shl 16) or
((this[offset + 6].toLong() and 0xFFL) shl 8) or
(this[offset + 7].toLong() and 0xFFL)
}
}
LITTLE_ENDIAN -> {
repeat(length / 8) { i ->
val offset = startIndex + (i * 8)
destination[destinationOffset + i] =
this[offset].toLong() or (this[offset + 1].toLong() shl 8) or
(this[offset + 2].toLong() shl 16) or (this[offset + 3].toLong() shl 24) or
(this[offset + 4].toLong() shl 32) or (this[offset + 5].toLong() shl 40) or
(this[offset + 6].toLong() shl 48) or (this[offset + 7].toLong() shl 56)
(this[offset].toLong() and 0xFFL) or
((this[offset + 1].toLong() and 0xFFL) shl 8) or
((this[offset + 2].toLong() and 0xFFL) shl 16) or
((this[offset + 3].toLong() and 0xFFL) shl 24) or
((this[offset + 4].toLong() and 0xFFL) shl 32) or
((this[offset + 5].toLong() and 0xFFL) shl 40) or
((this[offset + 6].toLong() and 0xFFL) shl 48) or
((this[offset + 7].toLong() and 0xFFL) shl 56)
}
}
}