implement typed array to byte array conversions
This commit is contained in:
@@ -12,6 +12,16 @@ fun UInt.toByteArray(
|
||||
return order.normalize(bytes)
|
||||
}
|
||||
|
||||
fun UIntArray.toByteArray(
|
||||
order: ByteOrder = BIG_ENDIAN,
|
||||
): ByteArray {
|
||||
return buildList {
|
||||
for (n in this@toByteArray) {
|
||||
addAll(n.toByteArray(order))
|
||||
}
|
||||
}.toByteArray()
|
||||
}
|
||||
|
||||
fun UInt.toUByteArray(
|
||||
order: ByteOrder = BIG_ENDIAN,
|
||||
): UByteArray {
|
||||
@@ -21,3 +31,13 @@ fun UInt.toUByteArray(
|
||||
}
|
||||
return order.normalize(bytes)
|
||||
}
|
||||
|
||||
fun UIntArray.toUByteArray(
|
||||
order: ByteOrder = BIG_ENDIAN,
|
||||
): UByteArray {
|
||||
return buildList {
|
||||
for (n in this@toUByteArray) {
|
||||
addAll(n.toUByteArray(order))
|
||||
}
|
||||
}.toUByteArray()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user