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

@@ -39,24 +39,24 @@ fun ByteArray.padStart(
length: Int,
padByte: Byte,
): ByteArray {
return buildList {
repeat(length - this@padStart.size) {
add(padByte)
}
addAll(this@padStart)
}.toByteArray()
val bytes = mutableListOf<Byte>()
repeat(length - size) {
bytes += padByte
}
bytes += this.toList()
return bytes.toByteArray()
}
fun ByteArray.padEnd(
length: Int,
padByte: Byte,
): ByteArray {
return buildList {
addAll(this@padEnd)
repeat(length - this@padEnd.size) {
add(padByte)
}
}.toByteArray()
val bytes = mutableListOf<Byte>()
bytes += this.toList()
repeat(length - size) {
bytes += padByte
}
return bytes.toByteArray()
}
fun ByteArray.toInt(