add fromHex extension

This commit is contained in:
InsanusMokrassar 2020-08-26 11:48:02 +06:00
parent dd9a5da3ae
commit ee3867e946
2 changed files with 4 additions and 8 deletions

View File

@ -1,6 +1,6 @@
package com.insanusmokrassar.postssystem.ktor
import kotlinx.serialization.SerializationStrategy
import kotlinx.serialization.encodeToHexString
import kotlinx.serialization.*
fun <T> T.toHex(with: SerializationStrategy<T>) = standardKtorSerialFormat.encodeToHexString(with, this)
fun <T> String.fromHex(with: DeserializationStrategy<T>): T = standardKtorSerialFormat.decodeFromHexString(with, this)

View File

@ -1,5 +1,6 @@
package com.insanusmokrassar.postssystem.ktor.server
import com.insanusmokrassar.postssystem.ktor.fromHex
import com.insanusmokrassar.postssystem.ktor.standardKtorSerialFormat
import io.ktor.application.ApplicationCall
import io.ktor.http.HttpStatusCode
@ -28,12 +29,7 @@ suspend fun <T> ApplicationCall.uniload(
fun <T> ApplicationCall.uniloadFromQuery(
parameterName: String,
deserializer: DeserializationStrategy<T>
): T? {
return standardKtorSerialFormat.decodeFromHexString(
deserializer,
getQueryParameter(parameterName) ?: return null
)
}
): T? = getQueryParameter(parameterName) ?.fromHex(deserializer)
suspend fun <T> ApplicationCall.uniloadFromQueryOrSendError(
parameterName: String,