implement Base8 encoding, rename Binary and Hex encodings
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.infendro.encoding
|
||||
|
||||
object Hex : Encoding() {
|
||||
object Base16 : Encoding() {
|
||||
private val CHARACTERS = ubyteArrayOf(
|
||||
0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U,
|
||||
0x38U, 0x39U, 0x61U, 0x62U, 0x63U, 0x64U, 0x65U, 0x66U,
|
||||
@@ -8,19 +8,9 @@ object Hex : Encoding() {
|
||||
|
||||
override fun encode(
|
||||
bytes: UByteArray,
|
||||
): UByteArray {
|
||||
return encode(
|
||||
bytes,
|
||||
CHARACTERS,
|
||||
)
|
||||
}
|
||||
) = encode(bytes, CHARACTERS)
|
||||
|
||||
override fun decode(
|
||||
bytes: UByteArray,
|
||||
): UByteArray {
|
||||
return decode(
|
||||
bytes,
|
||||
CHARACTERS,
|
||||
)
|
||||
}
|
||||
) = decode(bytes, CHARACTERS)
|
||||
}
|
||||
15
src/commonMain/kotlin/com/infendro/encoding/Base2.kt
Normal file
15
src/commonMain/kotlin/com/infendro/encoding/Base2.kt
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.infendro.encoding
|
||||
|
||||
object Base2 : Encoding() {
|
||||
private val CHARACTERS = ubyteArrayOf(
|
||||
0x30U, 0x31U,
|
||||
)
|
||||
|
||||
override fun encode(
|
||||
bytes: UByteArray,
|
||||
) = encode(bytes, CHARACTERS)
|
||||
|
||||
override fun decode(
|
||||
bytes: UByteArray,
|
||||
) = decode(bytes, CHARACTERS)
|
||||
}
|
||||
@@ -11,21 +11,9 @@ object Base32 : Encoding() {
|
||||
|
||||
override fun encode(
|
||||
bytes: UByteArray,
|
||||
): UByteArray {
|
||||
return encode(
|
||||
bytes,
|
||||
CHARACTERS,
|
||||
PADDING,
|
||||
)
|
||||
}
|
||||
) = encode(bytes, CHARACTERS, PADDING)
|
||||
|
||||
override fun decode(
|
||||
bytes: UByteArray,
|
||||
): UByteArray {
|
||||
return decode(
|
||||
bytes,
|
||||
CHARACTERS,
|
||||
PADDING,
|
||||
)
|
||||
}
|
||||
) = decode(bytes, CHARACTERS, PADDING)
|
||||
}
|
||||
|
||||
@@ -15,21 +15,9 @@ object Base64 : Encoding() {
|
||||
|
||||
override fun encode(
|
||||
bytes: UByteArray,
|
||||
): UByteArray {
|
||||
return encode(
|
||||
bytes,
|
||||
CHARACTERS,
|
||||
PADDING,
|
||||
)
|
||||
}
|
||||
) = encode(bytes, CHARACTERS, PADDING)
|
||||
|
||||
override fun decode(
|
||||
bytes: UByteArray,
|
||||
): UByteArray {
|
||||
return decode(
|
||||
bytes,
|
||||
CHARACTERS,
|
||||
PADDING,
|
||||
)
|
||||
}
|
||||
) = decode(bytes, CHARACTERS, PADDING)
|
||||
}
|
||||
|
||||
15
src/commonMain/kotlin/com/infendro/encoding/Base8.kt
Normal file
15
src/commonMain/kotlin/com/infendro/encoding/Base8.kt
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.infendro.encoding
|
||||
|
||||
object Base8 : Encoding() {
|
||||
private val CHARACTERS = ubyteArrayOf(
|
||||
0x30U, 0x31U, 0x32U, 0x33U, 0x34U, 0x35U, 0x36U, 0x37U,
|
||||
)
|
||||
|
||||
override fun encode(
|
||||
bytes: UByteArray,
|
||||
) = encode(bytes, CHARACTERS)
|
||||
|
||||
override fun decode(
|
||||
bytes: UByteArray,
|
||||
) = decode(bytes, CHARACTERS)
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.infendro.encoding
|
||||
|
||||
object Binary : Encoding() {
|
||||
private val CHARACTERS = ubyteArrayOf(
|
||||
0x30U, 0x31U,
|
||||
)
|
||||
|
||||
override fun encode(
|
||||
bytes: UByteArray,
|
||||
): UByteArray {
|
||||
return encode(
|
||||
bytes,
|
||||
CHARACTERS,
|
||||
)
|
||||
}
|
||||
|
||||
override fun decode(
|
||||
bytes: UByteArray,
|
||||
): UByteArray {
|
||||
return decode(
|
||||
bytes,
|
||||
CHARACTERS,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ sealed class Encoding {
|
||||
padding: UByte? = null,
|
||||
): UByteArray {
|
||||
val length = log2(characters.size).toInt()
|
||||
val mask = 0xFFU
|
||||
val mask = 0xffU
|
||||
|
||||
val decoded = mutableListOf<UByte>()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user