20 lines
445 B
Kotlin
20 lines
445 B
Kotlin
package com.infendro.bytearray
|
|
|
|
import com.infendro.bytearray.ByteOrder.BIG_ENDIAN
|
|
import com.infendro.bytearray.ByteOrder.LITTLE_ENDIAN
|
|
|
|
enum class ByteOrder {
|
|
BIG_ENDIAN, LITTLE_ENDIAN;
|
|
}
|
|
|
|
fun ByteArray.normalize(
|
|
order: ByteOrder,
|
|
): ByteArray = when (order) {
|
|
BIG_ENDIAN -> this
|
|
LITTLE_ENDIAN -> reversedArray()
|
|
}
|
|
|
|
fun UByteArray.normalize(
|
|
order: ByteOrder,
|
|
): UByteArray = asByteArray().normalize(order).asUByteArray()
|