refactor and simplify functions

This commit is contained in:
2025-12-01 17:48:45 +01:00
parent 4fbadfba1e
commit fa2c6b6621
7 changed files with 68 additions and 81 deletions

View File

@@ -15,11 +15,11 @@ fun ULong.toByteArray(
fun ULongArray.toByteArray(
order: ByteOrder = BIG_ENDIAN,
): ByteArray {
return buildList {
for (n in this@toByteArray) {
addAll(n.toByteArray(order))
}
}.toByteArray()
val bytes = mutableListOf<Byte>()
for (n in this) {
bytes += n.toByteArray(order).toList()
}
return bytes.toByteArray()
}
fun ULong.toUByteArray(
@@ -35,9 +35,9 @@ fun ULong.toUByteArray(
fun ULongArray.toUByteArray(
order: ByteOrder = BIG_ENDIAN,
): UByteArray {
return buildList {
for (n in this@toUByteArray) {
addAll(n.toUByteArray(order))
}
}.toUByteArray()
val bytes = mutableListOf<UByte>()
for (n in this) {
bytes += n.toUByteArray(order)
}
return bytes.toUByteArray()
}