remove unsigned support

This commit is contained in:
2026-02-04 18:19:50 +01:00
parent 421beeed1e
commit 03ec68cc40
36 changed files with 286 additions and 874 deletions

View File

@@ -0,0 +1,7 @@
package com.infendro.bytes.byte
import kotlin.experimental.inv
operator fun Byte.not(): Byte {
return inv()
}

View File

@@ -23,15 +23,6 @@ fun ByteArray.toInt(startIndex: Int = 0, order: ByteOrder = BIG_ENDIAN): Int {
}
}
fun ByteArray.toUInt(startIndex: Int = 0, order: ByteOrder = BIG_ENDIAN): UInt =
toInt(startIndex, order).toUInt()
fun ByteArray.toIntArray(order: ByteOrder = BIG_ENDIAN): IntArray =
IntArray(size / 4).also { copyInto(it, order = order) }
fun ByteArray.toUIntArray(order: ByteOrder = BIG_ENDIAN): UIntArray =
UIntArray(size / 4).also { copyInto(it, order = order) }
fun ByteArray.toLong(startIndex: Int = 0, order: ByteOrder = BIG_ENDIAN): Long {
require(startIndex in 0..(size - 8))
@@ -59,11 +50,16 @@ fun ByteArray.toLong(startIndex: Int = 0, order: ByteOrder = BIG_ENDIAN): Long {
}
}
fun ByteArray.toULong(startIndex: Int = 0, order: ByteOrder = BIG_ENDIAN): ULong =
toLong(startIndex, order).toULong()
fun ByteArray.toIntArray(startIndex: Int = 0, endIndex: Int = size, order: ByteOrder = BIG_ENDIAN): IntArray {
val length = endIndex - startIndex
val result = IntArray(length / 4)
copyInto(result, startIndex = startIndex, endIndex = endIndex, order = order)
return result
}
fun ByteArray.toLongArray(order: ByteOrder = BIG_ENDIAN): LongArray =
LongArray(size / 8).also { copyInto(it, order = order) }
fun ByteArray.toULongArray(order: ByteOrder = BIG_ENDIAN): ULongArray =
ULongArray(size / 8).also { copyInto(it, order = order) }
fun ByteArray.toLongArray(startIndex: Int = 0, endIndex: Int = size, order: ByteOrder = BIG_ENDIAN): LongArray {
val length = endIndex - startIndex
val result = LongArray(length / 8)
copyInto(result, startIndex = startIndex, endIndex = endIndex, order = order)
return result
}

View File

@@ -40,14 +40,6 @@ fun ByteArray.copyInto(
}
}
fun ByteArray.copyInto(
destination: UIntArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
order: ByteOrder = BIG_ENDIAN,
) = copyInto(destination.asIntArray(), destinationOffset, startIndex, endIndex, order)
fun ByteArray.copyInto(
destination: LongArray,
destinationOffset: Int = 0,
@@ -91,11 +83,3 @@ fun ByteArray.copyInto(
}
}
}
fun ByteArray.copyInto(
destination: ULongArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
order: ByteOrder = BIG_ENDIAN,
) = copyInto(destination.asLongArray(), destinationOffset, startIndex, endIndex, order)

View File

@@ -1,7 +1,7 @@
package com.infendro.bytes.bytearray
import com.infendro.bytes.byte.not
import kotlin.experimental.and
import kotlin.experimental.inv
import kotlin.experimental.or
import kotlin.experimental.xor
@@ -20,7 +20,7 @@ private inline fun ByteArray.combineInto(
require(thatStartIndex in 0..(that.size - length))
require(destinationOffset in 0..(destination.size - length))
repeat(length) { i ->
for (i in 0..<length) {
destination[destinationOffset + i] = combine(this[startIndex + i], that[thatStartIndex + i])
}
}
@@ -38,7 +38,7 @@ private inline fun ByteArray.combineInto(
require(startIndex in 0..(size - length))
require(destinationOffset in 0..(destination.size - length))
repeat(length) { i ->
for (i in 0..<length) {
destination[destinationOffset + i] = combine(this[startIndex + i], that)
}
}
@@ -46,11 +46,114 @@ private inline fun ByteArray.combineInto(
private inline fun ByteArray.combine(that: ByteArray, combine: (Byte, Byte) -> Byte): ByteArray {
require(this.size == that.size)
return ByteArray(size).also { combineInto(that, it, combine = combine) }
val result = ByteArray(size)
combineInto(that, result, combine = combine)
return result
}
private inline fun ByteArray.combine(that: Byte, combine: (Byte, Byte) -> Byte): ByteArray {
return ByteArray(size).also { combineInto(that, it, combine = combine) }
val result = ByteArray(size)
combineInto(that, result, combine = combine)
return result
}
fun ByteArray.andInto(
that: ByteArray,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
thatStartIndex: Int = 0,
) {
combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a and b }
}
fun ByteArray.andInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) {
andInto(destination, destination, destinationOffset, startIndex, endIndex, destinationOffset)
}
fun ByteArray.andInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) {
combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a and b }
}
infix fun ByteArray.and(that: ByteArray): ByteArray {
return combine(that) { a, b -> a and b }
}
infix fun ByteArray.and(that: Byte): ByteArray {
return combine(that) { a, b -> a and b }
}
fun ByteArray.orInto(
that: ByteArray,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
thatStartIndex: Int = 0,
) {
combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a or b }
}
fun ByteArray.orInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) {
orInto(destination, destination, destinationOffset, startIndex, endIndex, destinationOffset)
}
fun ByteArray.orInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) {
combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a or b }
}
infix fun ByteArray.or(that: ByteArray): ByteArray {
return combine(that) { a, b -> a or b }
}
infix fun ByteArray.or(that: Byte): ByteArray {
return combine(that) { a, b -> a or b }
}
fun ByteArray.xorInto(
that: ByteArray,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
thatStartIndex: Int = 0,
) {
combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a xor b }
}
fun ByteArray.xorInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) {
xorInto(destination, destination, destinationOffset, startIndex, endIndex, destinationOffset)
}
fun ByteArray.xorInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) {
combineInto(that, destination, destinationOffset, startIndex, endIndex) { a, b -> a xor b }
}
infix fun ByteArray.xor(that: ByteArray): ByteArray {
return combine(that) { a, b -> a xor b }
}
infix fun ByteArray.xor(that: Byte): ByteArray {
return combine(that) { a, b -> a xor b }
}
fun ByteArray.invInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) {
@@ -59,112 +162,17 @@ fun ByteArray.invInto(destination: ByteArray, destinationOffset: Int = 0, startI
require(startIndex in 0..(size - length))
require(destinationOffset in 0..(destination.size - length))
repeat(length) { i ->
destination[destinationOffset + i] = this[startIndex + i].inv()
for (i in 0..<length) {
destination[destinationOffset + i] = !this[startIndex + i]
}
}
fun ByteArray.invInto(startIndex: Int = 0, endIndex: Int = size) =
fun ByteArray.inv(startIndex: Int = 0, endIndex: Int = size) {
invInto(this, startIndex, startIndex, endIndex)
}
fun ByteArray.inv(): ByteArray =
ByteArray(size).also { invInto(it) }
fun ByteArray.andInto(
that: ByteArray,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
thatStartIndex: Int = 0,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a and b }
fun ByteArray.andInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = 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 =
combine(that) { a, b -> a and b }
infix fun ByteArray.and(that: Byte): ByteArray =
combine(that) { a, b -> a and b }
fun ByteArray.orInto(
that: ByteArray,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
thatStartIndex: Int = 0,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a or b }
fun ByteArray.orInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = 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 =
combine(that) { a, b -> a or b }
infix fun ByteArray.or(that: Byte): ByteArray =
combine(that) { a, b -> a or b }
fun ByteArray.xorInto(
that: ByteArray,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
thatStartIndex: Int = 0,
) = combineInto(that, destination, destinationOffset, startIndex, endIndex, thatStartIndex) { a, b -> a xor b }
fun ByteArray.xorInto(
that: Byte,
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = 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 =
combine(that) { a, b -> a xor b }
infix fun ByteArray.xor(that: Byte): ByteArray =
combine(that) { a, b -> a xor b }
operator fun ByteArray.not(): ByteArray {
val result = ByteArray(size)
invInto(result)
return result
}

View File

@@ -3,8 +3,8 @@ package com.infendro.bytes.int
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
fun Int.toByteArray(order: ByteOrder = BIG_ENDIAN): ByteArray =
ByteArray(4).also { copyInto(it, order = order) }
fun Int.toUByteArray(order: ByteOrder = BIG_ENDIAN): UByteArray =
UByteArray(4).also { copyInto(it, order = order) }
fun Int.toByteArray(order: ByteOrder = BIG_ENDIAN): ByteArray {
val result = ByteArray(4)
copyInto(result, order = order)
return result
}

View File

@@ -4,11 +4,7 @@ import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
import com.infendro.bytes.ByteOrder.LITTLE_ENDIAN
fun Int.copyInto(
destination: ByteArray,
destinationOffset: Int = 0,
order: ByteOrder = BIG_ENDIAN,
) {
fun Int.copyInto(destination: ByteArray, destinationOffset: Int = 0, order: ByteOrder = BIG_ENDIAN) {
require(destinationOffset in 0..(destination.size - 4))
when (order) {
@@ -26,9 +22,3 @@ fun Int.copyInto(
}
}
}
fun Int.copyInto(
destination: UByteArray,
destinationOffset: Int = 0,
order: ByteOrder = BIG_ENDIAN,
) = copyInto(destination.asByteArray(), destinationOffset, order)

View File

@@ -0,0 +1,5 @@
package com.infendro.bytes.int
operator fun Int.not(): Int {
return inv()
}

View File

@@ -3,8 +3,9 @@ package com.infendro.bytes.intarray
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
fun IntArray.toByteArray(order: ByteOrder = BIG_ENDIAN): ByteArray =
ByteArray(size * 4).also { copyInto(it, order = order) }
fun IntArray.toUByteArray(order: ByteOrder = BIG_ENDIAN): UByteArray =
UByteArray(size * 4).also { copyInto(it, order = order) }
fun IntArray.toByteArray(startIndex: Int = 0, endIndex: Int = size, order: ByteOrder = BIG_ENDIAN): ByteArray {
val length = endIndex - startIndex
val result = ByteArray(length * 4)
copyInto(result, startIndex = startIndex, endIndex = endIndex, order = order)
return result
}

View File

@@ -39,11 +39,3 @@ fun IntArray.copyInto(
}
}
}
fun IntArray.copyInto(
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
order: ByteOrder = BIG_ENDIAN,
) = copyInto(destination.asByteArray(), destinationOffset, startIndex, endIndex, order)

View File

@@ -3,8 +3,8 @@ package com.infendro.bytes.long
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
fun Long.toByteArray(order: ByteOrder = BIG_ENDIAN): ByteArray =
ByteArray(8).also { copyInto(it, order = order) }
fun Long.toUByteArray(order: ByteOrder = BIG_ENDIAN): UByteArray =
UByteArray(8).also { copyInto(it, order = order) }
fun Long.toByteArray(order: ByteOrder = BIG_ENDIAN): ByteArray {
val result = ByteArray(8)
copyInto(result, order = order)
return result
}

View File

@@ -4,11 +4,7 @@ import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
import com.infendro.bytes.ByteOrder.LITTLE_ENDIAN
fun Long.copyInto(
destination: ByteArray,
destinationOffset: Int = 0,
order: ByteOrder = BIG_ENDIAN,
) {
fun Long.copyInto(destination: ByteArray, destinationOffset: Int = 0, order: ByteOrder = BIG_ENDIAN) {
require(destinationOffset in 0..(destination.size - 8))
when (order) {
@@ -34,9 +30,3 @@ fun Long.copyInto(
}
}
}
fun Long.copyInto(
destination: UByteArray,
destinationOffset: Int = 0,
order: ByteOrder = BIG_ENDIAN,
) = copyInto(destination.asByteArray(), destinationOffset, order)

View File

@@ -0,0 +1,5 @@
package com.infendro.bytes.long
operator fun Long.not(): Long {
return inv()
}

View File

@@ -3,8 +3,9 @@ package com.infendro.bytes.longarray
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
fun LongArray.toByteArray(order: ByteOrder = BIG_ENDIAN): ByteArray =
ByteArray(size * 8).also { copyInto(it, order = order) }
fun LongArray.toUByteArray(order: ByteOrder = BIG_ENDIAN): UByteArray =
UByteArray(size * 8).also { copyInto(it, order = order) }
fun LongArray.toByteArray(startIndex: Int = 0, endIndex: Int = size, order: ByteOrder = BIG_ENDIAN): ByteArray {
val length = endIndex - startIndex
val result = ByteArray(length * 8)
copyInto(result, startIndex = startIndex, endIndex = endIndex, order = order)
return result
}

View File

@@ -47,11 +47,3 @@ fun LongArray.copyInto(
}
}
}
fun LongArray.copyInto(
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
order: ByteOrder = BIG_ENDIAN,
) = copyInto(destination.asByteArray(), destinationOffset, startIndex, endIndex, order)

View File

@@ -1,32 +0,0 @@
package com.infendro.bytes.ubytearray
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
import com.infendro.bytes.bytearray.toInt
import com.infendro.bytes.bytearray.toLong
import com.infendro.bytes.bytearray.toUInt
import com.infendro.bytes.bytearray.toULong
fun UByteArray.toInt(startIndex: Int = 0, order: ByteOrder = BIG_ENDIAN): Int =
asByteArray().toInt(startIndex, order)
fun UByteArray.toUInt(startIndex: Int = 0, order: ByteOrder = BIG_ENDIAN): UInt =
asByteArray().toUInt(startIndex, order)
fun UByteArray.toIntArray(order: ByteOrder = BIG_ENDIAN): IntArray =
IntArray(size / 4).also { copyInto(it, order = order) }
fun UByteArray.toUIntArray(order: ByteOrder = BIG_ENDIAN): UIntArray =
UIntArray(size / 4).also { copyInto(it, order = order) }
fun UByteArray.toLong(startIndex: Int = 0, order: ByteOrder = BIG_ENDIAN): Long =
asByteArray().toLong(startIndex, order)
fun UByteArray.toULong(startIndex: Int = 0, order: ByteOrder = BIG_ENDIAN): ULong =
asByteArray().toULong(startIndex, order)
fun UByteArray.toLongArray(order: ByteOrder = BIG_ENDIAN): LongArray =
LongArray(size / 8).also { copyInto(it, order = order) }
fun UByteArray.toULongArray(order: ByteOrder = BIG_ENDIAN): ULongArray =
ULongArray(size / 8).also { copyInto(it, order = order) }

View File

@@ -1,37 +0,0 @@
package com.infendro.bytes.ubytearray
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
import com.infendro.bytes.bytearray.copyInto
fun UByteArray.copyInto(
destination: IntArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
order: ByteOrder = BIG_ENDIAN,
) = asByteArray().copyInto(destination, destinationOffset, startIndex, endIndex, order)
fun UByteArray.copyInto(
destination: UIntArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
order: ByteOrder = BIG_ENDIAN,
) = asByteArray().copyInto(destination, destinationOffset, startIndex, endIndex, order)
fun UByteArray.copyInto(
destination: ULongArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
order: ByteOrder = BIG_ENDIAN,
) = asByteArray().copyInto(destination, destinationOffset, startIndex, endIndex, order)
fun UByteArray.copyInto(
destination: LongArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
order: ByteOrder = BIG_ENDIAN,
) = asByteArray().copyInto(destination, destinationOffset, startIndex, endIndex, order)

View File

@@ -1,153 +0,0 @@
package com.infendro.bytes.ubytearray
import com.infendro.bytes.bytearray.andInto
import com.infendro.bytes.bytearray.invInto
import com.infendro.bytes.bytearray.orInto
import com.infendro.bytes.bytearray.xorInto
fun UByteArray.invInto(destination: UByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =
asByteArray().invInto(destination.asByteArray(), destinationOffset, startIndex, endIndex)
fun UByteArray.invInto(startIndex: Int = 0, endIndex: Int = size) =
asByteArray().invInto(asByteArray(), startIndex, startIndex, endIndex)
fun UByteArray.inv(): UByteArray =
UByteArray(size).also { invInto(it) }
fun UByteArray.andInto(
that: UByteArray,
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
thatStartIndex: Int = 0,
) = asByteArray().andInto(
that.asByteArray(),
destination.asByteArray(),
destinationOffset,
startIndex,
endIndex,
thatStartIndex,
)
fun UByteArray.andInto(
that: UByte,
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = asByteArray().andInto(
that.toByte(),
destination.asByteArray(),
destinationOffset,
startIndex,
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 =
UByteArray(size).also { andInto(that, it) }
infix fun UByteArray.and(that: UByte): UByteArray =
UByteArray(size).also { andInto(that, it) }
fun UByteArray.orInto(
that: UByteArray,
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
thatStartIndex: Int = 0,
) = asByteArray().orInto(
that.asByteArray(),
destination.asByteArray(),
destinationOffset,
startIndex,
endIndex,
thatStartIndex,
)
fun UByteArray.orInto(
that: UByte,
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = asByteArray().orInto(
that.toByte(),
destination.asByteArray(),
destinationOffset,
startIndex,
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 =
UByteArray(size).also { orInto(that, it) }
infix fun UByteArray.or(that: UByte): UByteArray =
UByteArray(size).also { orInto(that, it) }
fun UByteArray.xorInto(
that: UByteArray,
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
thatStartIndex: Int = 0,
) = asByteArray().xorInto(
that.asByteArray(),
destination.asByteArray(),
destinationOffset,
startIndex,
endIndex,
thatStartIndex,
)
fun UByteArray.xorInto(
that: UByte,
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
) = asByteArray().xorInto(
that.toByte(),
destination.asByteArray(),
destinationOffset,
startIndex,
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 =
UByteArray(size).also { xorInto(that, it) }
infix fun UByteArray.xor(that: UByte): UByteArray =
UByteArray(size).also { xorInto(that, it) }

View File

@@ -1,7 +0,0 @@
package com.infendro.bytes.ubytearray
fun String.encodeToUByteArray(): UByteArray =
encodeToByteArray().asUByteArray()
fun UByteArray.decodeToString(): String =
asByteArray().decodeToString()

View File

@@ -1,10 +0,0 @@
package com.infendro.bytes.uint
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
fun UInt.toByteArray(order: ByteOrder = BIG_ENDIAN): ByteArray =
ByteArray(4).also { copyInto(it, order = order) }
fun UInt.toUByteArray(order: ByteOrder = BIG_ENDIAN): UByteArray =
UByteArray(4).also { copyInto(it, order = order) }

View File

@@ -1,17 +0,0 @@
package com.infendro.bytes.uint
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
import com.infendro.bytes.int.copyInto
fun UInt.copyInto(
destination: ByteArray,
destinationOffset: Int = 0,
order: ByteOrder = BIG_ENDIAN,
) = toInt().copyInto(destination, destinationOffset, order)
fun UInt.copyInto(
destination: UByteArray,
destinationOffset: Int = 0,
order: ByteOrder = BIG_ENDIAN,
) = toInt().copyInto(destination, destinationOffset, order)

View File

@@ -1,10 +0,0 @@
package com.infendro.bytes.uintarray
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
fun UIntArray.toByteArray(order: ByteOrder = BIG_ENDIAN): ByteArray =
ByteArray(size * 4).also { copyInto(it, order = order) }
fun UIntArray.toUByteArray(order: ByteOrder = BIG_ENDIAN): UByteArray =
UByteArray(size * 4).also { copyInto(it, order = order) }

View File

@@ -1,21 +0,0 @@
package com.infendro.bytes.uintarray
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
import com.infendro.bytes.intarray.copyInto
fun UIntArray.copyInto(
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
order: ByteOrder = BIG_ENDIAN,
) = asIntArray().copyInto(destination, destinationOffset, startIndex, endIndex, order)
fun UIntArray.copyInto(
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
order: ByteOrder = BIG_ENDIAN,
) = asIntArray().copyInto(destination, destinationOffset, startIndex, endIndex, order)

View File

@@ -1,10 +0,0 @@
package com.infendro.bytes.ulong
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
fun ULong.toByteArray(order: ByteOrder = BIG_ENDIAN): ByteArray =
ByteArray(8).also { copyInto(it, order = order) }
fun ULong.toUByteArray(order: ByteOrder = BIG_ENDIAN): UByteArray =
UByteArray(8).also { copyInto(it, order = order) }

View File

@@ -1,17 +0,0 @@
package com.infendro.bytes.ulong
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
import com.infendro.bytes.long.copyInto
fun ULong.copyInto(
destination: ByteArray,
destinationOffset: Int = 0,
order: ByteOrder = BIG_ENDIAN,
) = toLong().copyInto(destination, destinationOffset, order)
fun ULong.copyInto(
destination: UByteArray,
destinationOffset: Int = 0,
order: ByteOrder = BIG_ENDIAN,
) = toLong().copyInto(destination, destinationOffset, order)

View File

@@ -1,10 +0,0 @@
package com.infendro.bytes.ulongarray
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
fun ULongArray.toByteArray(order: ByteOrder = BIG_ENDIAN): ByteArray =
ByteArray(size * 8).also { copyInto(it, order = order) }
fun ULongArray.toUByteArray(order: ByteOrder = BIG_ENDIAN): UByteArray =
UByteArray(size * 8).also { copyInto(it, order = order) }

View File

@@ -1,21 +0,0 @@
package com.infendro.bytes.ulongarray
import com.infendro.bytes.ByteOrder
import com.infendro.bytes.ByteOrder.BIG_ENDIAN
import com.infendro.bytes.longarray.copyInto
fun ULongArray.copyInto(
destination: ByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
order: ByteOrder = BIG_ENDIAN,
) = asLongArray().copyInto(destination, destinationOffset, startIndex, endIndex, order)
fun ULongArray.copyInto(
destination: UByteArray,
destinationOffset: Int = 0,
startIndex: Int = 0,
endIndex: Int = size,
order: ByteOrder = BIG_ENDIAN,
) = asLongArray().copyInto(destination, destinationOffset, startIndex, endIndex, order)