Compare commits

...

2 Commits

Author SHA1 Message Date
19b2fb36fd bump version to 1.3.4
All checks were successful
/ test (pull_request) Successful in 1m44s
2026-02-03 23:02:24 +01:00
f18adc08b9 implement shorthand bytearray operations 2026-02-03 23:01:19 +01:00
4 changed files with 74 additions and 16 deletions

View File

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

View File

@@ -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.3" version = "1.3.4"
plugins { plugins {
alias(libs.plugins.infendro) alias(libs.plugins.infendro)

View File

@@ -49,15 +49,11 @@ private inline fun ByteArray.combine(that: ByteArray, combine: (Byte, Byte) -> B
return ByteArray(size).also { combineInto(that, it, combine = combine) } return ByteArray(size).also { combineInto(that, it, combine = combine) }
} }
private inline fun ByteArray.combine(that: Byte, combine: (Byte, Byte) -> Byte): ByteArray = private inline fun ByteArray.combine(that: Byte, combine: (Byte, Byte) -> Byte): ByteArray {
ByteArray(size).also { combineInto(that, it, combine = combine) } return ByteArray(size).also { combineInto(that, it, combine = combine) }
}
fun ByteArray.invInto( fun ByteArray.invInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) {
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) {
val length = endIndex - startIndex val length = endIndex - startIndex
require(length >= 0) require(length >= 0)
require(startIndex in 0..(size - length)) require(startIndex in 0..(size - length))
@@ -68,6 +64,9 @@ fun ByteArray.invInto(
} }
} }
fun ByteArray.invInto(startIndex: Int = 0, endIndex: Int = size) =
invInto(this, startIndex, startIndex, endIndex)
fun ByteArray.inv(): ByteArray = fun ByteArray.inv(): ByteArray =
ByteArray(size).also { invInto(it) } ByteArray(size).also { invInto(it) }
@@ -88,6 +87,16 @@ fun ByteArray.andInto(
endIndex: Int = size, endIndex: Int = size,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a and b } ) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a and b }
fun ByteArray.andInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =
combineInto(
destination,
destination,
destinationOffset,
startIndex,
endIndex,
destinationOffset,
) { a, b -> a and b }
infix fun ByteArray.and(that: ByteArray): ByteArray = infix fun ByteArray.and(that: ByteArray): ByteArray =
combine(that) { a, b -> a and b } combine(that) { a, b -> a and b }
@@ -111,6 +120,16 @@ fun ByteArray.orInto(
endIndex: Int = size, endIndex: Int = size,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a or b } ) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a or b }
fun ByteArray.orInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =
combineInto(
destination,
destination,
destinationOffset,
startIndex,
endIndex,
destinationOffset,
) { a, b -> a or b }
infix fun ByteArray.or(that: ByteArray): ByteArray = infix fun ByteArray.or(that: ByteArray): ByteArray =
combine(that) { a, b -> a or b } combine(that) { a, b -> a or b }
@@ -134,6 +153,16 @@ fun ByteArray.xorInto(
endIndex: Int = size, endIndex: Int = size,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a xor b } ) = combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a xor b }
fun ByteArray.xorInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =
combineInto(
destination,
destination,
destinationOffset,
startIndex,
endIndex,
destinationOffset,
) { a, b -> a xor b }
infix fun ByteArray.xor(that: ByteArray): ByteArray = infix fun ByteArray.xor(that: ByteArray): ByteArray =
combine(that) { a, b -> a xor b } combine(that) { a, b -> a xor b }

View File

@@ -5,12 +5,11 @@ import com.infendro.bytes.bytearray.invInto
import com.infendro.bytes.bytearray.orInto import com.infendro.bytes.bytearray.orInto
import com.infendro.bytes.bytearray.xorInto import com.infendro.bytes.bytearray.xorInto
fun UByteArray.invInto( fun UByteArray.invInto(destination: UByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =
destination: UByteArray, asByteArray().invInto(destination.asByteArray(), destinationOffset, startIndex, endIndex)
destinationOffset: Int = 0,
startIndex: Int = 0, fun UByteArray.invInto(startIndex: Int = 0, endIndex: Int = size) =
endIndex: Int = size, asByteArray().invInto(asByteArray(), startIndex, startIndex, endIndex)
) = asByteArray().invInto(destination.asByteArray(), destinationOffset, startIndex, endIndex)
fun UByteArray.inv(): UByteArray = fun UByteArray.inv(): UByteArray =
UByteArray(size).also { invInto(it) } UByteArray(size).also { invInto(it) }
@@ -45,6 +44,16 @@ fun UByteArray.andInto(
endIndex, endIndex,
) )
fun UByteArray.andInto(destination: UByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =
asByteArray().andInto(
destination.asByteArray(),
destination.asByteArray(),
destinationOffset,
startIndex,
endIndex,
destinationOffset,
)
infix fun UByteArray.and(that: UByteArray): UByteArray = infix fun UByteArray.and(that: UByteArray): UByteArray =
UByteArray(size).also { andInto(that, it) } UByteArray(size).also { andInto(that, it) }
@@ -81,6 +90,16 @@ fun UByteArray.orInto(
endIndex, endIndex,
) )
fun UByteArray.orInto(destination: UByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =
asByteArray().orInto(
destination.asByteArray(),
destination.asByteArray(),
destinationOffset,
startIndex,
endIndex,
destinationOffset,
)
infix fun UByteArray.or(that: UByteArray): UByteArray = infix fun UByteArray.or(that: UByteArray): UByteArray =
UByteArray(size).also { orInto(that, it) } UByteArray(size).also { orInto(that, it) }
@@ -117,6 +136,16 @@ fun UByteArray.xorInto(
endIndex, endIndex,
) )
fun UByteArray.xorInto(destination: UByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =
asByteArray().xorInto(
destination.asByteArray(),
destination.asByteArray(),
destinationOffset,
startIndex,
endIndex,
destinationOffset,
)
infix fun UByteArray.xor(that: UByteArray): UByteArray = infix fun UByteArray.xor(that: UByteArray): UByteArray =
UByteArray(size).also { xorInto(that, it) } UByteArray(size).also { xorInto(that, it) }