refactor
This commit is contained in:
@@ -1,38 +1,22 @@
|
||||
package com.infendro.bytearray
|
||||
|
||||
import com.infendro.bytearray.ByteOrder.BIG_ENDIAN
|
||||
import com.infendro.bytearray.ByteOrder.LITTLE_ENDIAN
|
||||
|
||||
enum class ByteOrder {
|
||||
BIG_ENDIAN {
|
||||
override fun normalize(
|
||||
bytes: ByteArray,
|
||||
): ByteArray {
|
||||
return bytes
|
||||
}
|
||||
|
||||
override fun normalize(
|
||||
bytes: UByteArray,
|
||||
): UByteArray {
|
||||
return bytes
|
||||
}
|
||||
},
|
||||
LITTLE_ENDIAN {
|
||||
override fun normalize(
|
||||
bytes: ByteArray,
|
||||
): ByteArray {
|
||||
return bytes.reversedArray()
|
||||
}
|
||||
|
||||
override fun normalize(
|
||||
bytes: UByteArray,
|
||||
): UByteArray {
|
||||
return bytes.reversedArray()
|
||||
}
|
||||
};
|
||||
|
||||
internal abstract fun normalize(
|
||||
bytes: ByteArray,
|
||||
): ByteArray
|
||||
|
||||
internal abstract fun normalize(
|
||||
bytes: UByteArray,
|
||||
): UByteArray
|
||||
BIG_ENDIAN, LITTLE_ENDIAN;
|
||||
}
|
||||
|
||||
fun ByteArray.normalize(
|
||||
order: ByteOrder,
|
||||
): ByteArray = when (order) {
|
||||
BIG_ENDIAN -> this
|
||||
LITTLE_ENDIAN -> reversedArray()
|
||||
}
|
||||
|
||||
fun UByteArray.normalize(
|
||||
order: ByteOrder,
|
||||
): UByteArray = when (order) {
|
||||
BIG_ENDIAN -> this
|
||||
LITTLE_ENDIAN -> reversedArray()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user