diff --git a/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/ktor/HexConversations.kt b/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/ktor/HexConversations.kt index 94e7603d..eb7cb1d3 100644 --- a/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/ktor/HexConversations.kt +++ b/ktor/common/src/commonMain/kotlin/com/insanusmokrassar/postssystem/ktor/HexConversations.kt @@ -1,6 +1,6 @@ package com.insanusmokrassar.postssystem.ktor -import kotlinx.serialization.SerializationStrategy -import kotlinx.serialization.encodeToHexString +import kotlinx.serialization.* fun T.toHex(with: SerializationStrategy) = standardKtorSerialFormat.encodeToHexString(with, this) +fun String.fromHex(with: DeserializationStrategy): T = standardKtorSerialFormat.decodeFromHexString(with, this) diff --git a/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/ktor/server/ServerRoutingShortcuts.kt b/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/ktor/server/ServerRoutingShortcuts.kt index 3ce44c91..5cd6db27 100644 --- a/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/ktor/server/ServerRoutingShortcuts.kt +++ b/ktor/server/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/ktor/server/ServerRoutingShortcuts.kt @@ -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 ApplicationCall.uniload( fun ApplicationCall.uniloadFromQuery( parameterName: String, deserializer: DeserializationStrategy -): T? { - return standardKtorSerialFormat.decodeFromHexString( - deserializer, - getQueryParameter(parameterName) ?: return null - ) -} +): T? = getQueryParameter(parameterName) ?.fromHex(deserializer) suspend fun ApplicationCall.uniloadFromQueryOrSendError( parameterName: String,