mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-22 16:23:50 +00:00
commit
a299a5b505
@ -1,5 +1,13 @@
|
||||
# Changelog
|
||||
|
||||
## 0.4.23
|
||||
|
||||
* `Versions`:
|
||||
* `Ktor`: `1.5.0` -> `1.5.1`
|
||||
* `Serialization`
|
||||
* `Base64`
|
||||
* New serializer `Base64BytesToFromStringSerializer` has been added
|
||||
|
||||
## 0.4.22
|
||||
|
||||
* `Versions`:
|
||||
|
@ -11,7 +11,7 @@ kotlin_coroutines_version=1.4.2
|
||||
kotlin_serialisation_core_version=1.0.1
|
||||
kotlin_exposed_version=0.29.1
|
||||
|
||||
ktor_version=1.5.0
|
||||
ktor_version=1.5.1
|
||||
|
||||
klockVersion=2.0.4
|
||||
|
||||
@ -44,5 +44,5 @@ dokka_version=1.4.20
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.4.22
|
||||
android_code_version=26
|
||||
version=0.4.23
|
||||
android_code_version=27
|
||||
|
@ -0,0 +1,17 @@
|
||||
package dev.inmo.micro_utils.serialization.base64
|
||||
|
||||
import dev.inmo.micro_utils.crypto.*
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
/**
|
||||
* Converts [ByteArray] into base64 encoded string due to serialization and decode base64 encoded string into bytes
|
||||
*/
|
||||
object Base64BytesToFromStringSerializer: KSerializer<ByteArray> {
|
||||
override val descriptor: SerialDescriptor = String.serializer().descriptor
|
||||
override fun deserialize(decoder: Decoder): SourceBytes = decoder.decodeString().decodeBase64()
|
||||
override fun serialize(encoder: Encoder, value: SourceBytes) = encoder.encodeString(value.encodeBase64String())
|
||||
}
|
@ -1,9 +1,6 @@
|
||||
package dev.inmo.micro_utils.serialization.base64
|
||||
|
||||
import dev.inmo.micro_utils.crypto.*
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.Serializer
|
||||
import kotlinx.serialization.builtins.serializer
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
@ -12,9 +9,9 @@ open class Base64Serializer<T>(
|
||||
private val converterFrom: (T) -> String,
|
||||
private val converterTo: (String) -> T,
|
||||
) : KSerializer<T> {
|
||||
override val descriptor: SerialDescriptor = String.serializer().descriptor
|
||||
override fun deserialize(decoder: Decoder): T = converterTo(decoder.decodeString().decodeBase64String())
|
||||
override fun serialize(encoder: Encoder, value: T) = encoder.encodeString(converterFrom(value).encodeBase64String())
|
||||
override val descriptor: SerialDescriptor = Base64BytesToFromStringSerializer.descriptor
|
||||
override fun deserialize(decoder: Decoder): T = converterTo(Base64BytesToFromStringSerializer.deserialize(decoder).decodeToString())
|
||||
override fun serialize(encoder: Encoder, value: T) = Base64BytesToFromStringSerializer.serialize(encoder, converterFrom(value).encodeToByteArray())
|
||||
}
|
||||
|
||||
object Base64StringSerializer : Base64Serializer<String>({ it }, { it })
|
||||
|
Loading…
Reference in New Issue
Block a user