mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-03-11 21:02:37 +00:00
generate docs for a lot of API (test try)
This commit is contained in:
@@ -5,6 +5,14 @@ import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
|
||||
/**
|
||||
* A serializer that encodes values to Base64 strings and decodes them back.
|
||||
* Uses custom conversion functions to transform between type [T] and string representation.
|
||||
*
|
||||
* @param T The type to serialize/deserialize
|
||||
* @param converterFrom Converts from type [T] to a string representation
|
||||
* @param converterTo Converts from a string representation back to type [T]
|
||||
*/
|
||||
open class Base64Serializer<T>(
|
||||
private val converterFrom: (T) -> String,
|
||||
private val converterTo: (String) -> T,
|
||||
@@ -14,5 +22,12 @@ open class Base64Serializer<T>(
|
||||
override fun serialize(encoder: Encoder, value: T) = Base64BytesToFromStringSerializer.serialize(encoder, converterFrom(value).encodeToByteArray())
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializer for [String] values encoded as Base64.
|
||||
*/
|
||||
object Base64StringSerializer : Base64Serializer<String>({ it }, { it })
|
||||
|
||||
/**
|
||||
* Serializer for [ByteArray] values encoded as Base64.
|
||||
*/
|
||||
object Base64ByteArraySerializer : Base64Serializer<ByteArray>({ it.decodeToString() }, { it.encodeToByteArray() })
|
||||
|
||||
Reference in New Issue
Block a user