implement typed array to byte array conversions

This commit is contained in:
2025-12-01 16:24:35 +01:00
parent 941a486217
commit eb2cdbea73
6 changed files with 96 additions and 16 deletions

View File

@@ -12,6 +12,16 @@ fun ULong.toByteArray(
return order.normalize(bytes)
}
fun ULongArray.toByteArray(
order: ByteOrder = BIG_ENDIAN,
): ByteArray {
return buildList {
for (n in this@toByteArray) {
addAll(n.toByteArray(order))
}
}.toByteArray()
}
fun ULong.toUByteArray(
order: ByteOrder = BIG_ENDIAN,
): UByteArray {
@@ -21,3 +31,13 @@ fun ULong.toUByteArray(
}
return order.normalize(bytes)
}
fun ULongArray.toUByteArray(
order: ByteOrder = BIG_ENDIAN,
): UByteArray {
return buildList {
for (n in this@toUByteArray) {
addAll(n.toUByteArray(order))
}
}.toUByteArray()
}