fix ByteArray to numeric conversion
All checks were successful
/ test (pull_request) Successful in 2m49s
All checks were successful
/ test (pull_request) Successful in 2m49s
This commit is contained in:
@@ -12,6 +12,6 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
commonMain.dependencies {
|
commonMain.dependencies {
|
||||||
implementation("com.infendro:bytes:1.3.1")
|
implementation("com.infendro:bytes:1.3.2")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.infendro.plugin.token
|
|||||||
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
|
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl
|
||||||
|
|
||||||
group = "com.infendro"
|
group = "com.infendro"
|
||||||
version = "1.3.1"
|
version = "1.3.2"
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
alias(libs.plugins.infendro)
|
alias(libs.plugins.infendro)
|
||||||
|
|||||||
@@ -9,12 +9,16 @@ fun ByteArray.toInt(startIndex: Int = 0, order: ByteOrder = BIG_ENDIAN): Int {
|
|||||||
|
|
||||||
return when (order) {
|
return when (order) {
|
||||||
BIG_ENDIAN -> {
|
BIG_ENDIAN -> {
|
||||||
(this[startIndex].toInt() shl 24) or (this[startIndex + 1].toInt() shl 16) or
|
((this[startIndex].toInt() and 0xFF) shl 24) or
|
||||||
(this[startIndex + 2].toInt() shl 8) or this[startIndex + 3].toInt()
|
((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 -> {
|
LITTLE_ENDIAN -> {
|
||||||
this[startIndex].toInt() or (this[startIndex + 1].toInt() shl 8) or
|
(this[startIndex].toInt() and 0xFF) or
|
||||||
(this[startIndex + 2].toInt() shl 16) or (this[startIndex + 3].toInt() shl 24)
|
((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) {
|
return when (order) {
|
||||||
BIG_ENDIAN -> {
|
BIG_ENDIAN -> {
|
||||||
(this[startIndex].toLong() shl 56) or (this[startIndex + 1].toLong() shl 48) or
|
((this[startIndex].toLong() and 0xFFL) shl 56) or
|
||||||
(this[startIndex + 2].toLong() shl 40) or (this[startIndex + 3].toLong() shl 32) or
|
((this[startIndex + 1].toLong() and 0xFFL) shl 48) or
|
||||||
(this[startIndex + 4].toLong() shl 24) or (this[startIndex + 5].toLong() shl 16) or
|
((this[startIndex + 2].toLong() and 0xFFL) shl 40) or
|
||||||
(this[startIndex + 6].toLong() shl 8) or this[startIndex + 7].toLong()
|
((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 -> {
|
LITTLE_ENDIAN -> {
|
||||||
this[startIndex].toLong() or (this[startIndex + 1].toLong() shl 8) or
|
(this[startIndex].toLong() and 0xFFL) or
|
||||||
(this[startIndex + 2].toLong() shl 16) or (this[startIndex + 3].toLong() shl 24) or
|
((this[startIndex + 1].toLong() and 0xFFL) shl 8) or
|
||||||
(this[startIndex + 4].toLong() shl 32) or (this[startIndex + 5].toLong() shl 40) or
|
((this[startIndex + 2].toLong() and 0xFFL) shl 16) or
|
||||||
(this[startIndex + 6].toLong() shl 48) or (this[startIndex + 7].toLong() shl 56)
|
((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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,16 +21,20 @@ fun ByteArray.copyInto(
|
|||||||
repeat(length / 4) { i ->
|
repeat(length / 4) { i ->
|
||||||
val offset = startIndex + (i * 4)
|
val offset = startIndex + (i * 4)
|
||||||
destination[destinationOffset + i] =
|
destination[destinationOffset + i] =
|
||||||
(this[offset].toInt() shl 24) or (this[offset + 1].toInt() shl 16) or
|
((this[offset].toInt() and 0xFF) shl 24) or
|
||||||
(this[offset + 2].toInt() shl 8) or this[offset + 3].toInt()
|
((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 -> {
|
LITTLE_ENDIAN -> {
|
||||||
repeat(length / 4) { i ->
|
repeat(length / 4) { i ->
|
||||||
val offset = startIndex + (i * 4)
|
val offset = startIndex + (i * 4)
|
||||||
destination[destinationOffset + i] =
|
destination[destinationOffset + i] =
|
||||||
this[offset].toInt() or (this[offset + 1].toInt() shl 8) or
|
(this[offset].toInt() and 0xFF) or
|
||||||
(this[offset + 2].toInt() shl 16) or (this[offset + 3].toInt() shl 24)
|
((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 ->
|
repeat(length / 8) { i ->
|
||||||
val offset = startIndex + (i * 8)
|
val offset = startIndex + (i * 8)
|
||||||
destination[destinationOffset + i] =
|
destination[destinationOffset + i] =
|
||||||
(this[offset].toLong() shl 56) or (this[offset + 1].toLong() shl 48) or
|
((this[offset].toLong() and 0xFFL) shl 56) or
|
||||||
(this[offset + 2].toLong() shl 40) or (this[offset + 3].toLong() shl 32) or
|
((this[offset + 1].toLong() and 0xFFL) shl 48) or
|
||||||
(this[offset + 4].toLong() shl 24) or (this[offset + 5].toLong() shl 16) or
|
((this[offset + 2].toLong() and 0xFFL) shl 40) or
|
||||||
(this[offset + 6].toLong() shl 8) or this[offset + 7].toLong()
|
((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 -> {
|
LITTLE_ENDIAN -> {
|
||||||
repeat(length / 8) { i ->
|
repeat(length / 8) { i ->
|
||||||
val offset = startIndex + (i * 8)
|
val offset = startIndex + (i * 8)
|
||||||
destination[destinationOffset + i] =
|
destination[destinationOffset + i] =
|
||||||
this[offset].toLong() or (this[offset + 1].toLong() shl 8) or
|
(this[offset].toLong() and 0xFFL) or
|
||||||
(this[offset + 2].toLong() shl 16) or (this[offset + 3].toLong() shl 24) or
|
((this[offset + 1].toLong() and 0xFFL) shl 8) or
|
||||||
(this[offset + 4].toLong() shl 32) or (this[offset + 5].toLong() shl 40) or
|
((this[offset + 2].toLong() and 0xFFL) shl 16) or
|
||||||
(this[offset + 6].toLong() shl 48) or (this[offset + 7].toLong() shl 56)
|
((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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user