add fromHex extension
This commit is contained in:
parent
dd9a5da3ae
commit
ee3867e946
@ -1,6 +1,6 @@
|
|||||||
package com.insanusmokrassar.postssystem.ktor
|
package com.insanusmokrassar.postssystem.ktor
|
||||||
|
|
||||||
import kotlinx.serialization.SerializationStrategy
|
import kotlinx.serialization.*
|
||||||
import kotlinx.serialization.encodeToHexString
|
|
||||||
|
|
||||||
fun <T> T.toHex(with: SerializationStrategy<T>) = standardKtorSerialFormat.encodeToHexString(with, this)
|
fun <T> T.toHex(with: SerializationStrategy<T>) = standardKtorSerialFormat.encodeToHexString(with, this)
|
||||||
|
fun <T> String.fromHex(with: DeserializationStrategy<T>): T = standardKtorSerialFormat.decodeFromHexString(with, this)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.insanusmokrassar.postssystem.ktor.server
|
package com.insanusmokrassar.postssystem.ktor.server
|
||||||
|
|
||||||
|
import com.insanusmokrassar.postssystem.ktor.fromHex
|
||||||
import com.insanusmokrassar.postssystem.ktor.standardKtorSerialFormat
|
import com.insanusmokrassar.postssystem.ktor.standardKtorSerialFormat
|
||||||
import io.ktor.application.ApplicationCall
|
import io.ktor.application.ApplicationCall
|
||||||
import io.ktor.http.HttpStatusCode
|
import io.ktor.http.HttpStatusCode
|
||||||
@ -28,12 +29,7 @@ suspend fun <T> ApplicationCall.uniload(
|
|||||||
fun <T> ApplicationCall.uniloadFromQuery(
|
fun <T> ApplicationCall.uniloadFromQuery(
|
||||||
parameterName: String,
|
parameterName: String,
|
||||||
deserializer: DeserializationStrategy<T>
|
deserializer: DeserializationStrategy<T>
|
||||||
): T? {
|
): T? = getQueryParameter(parameterName) ?.fromHex(deserializer)
|
||||||
return standardKtorSerialFormat.decodeFromHexString(
|
|
||||||
deserializer,
|
|
||||||
getQueryParameter(parameterName) ?: return null
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun <T> ApplicationCall.uniloadFromQueryOrSendError(
|
suspend fun <T> ApplicationCall.uniloadFromQueryOrSendError(
|
||||||
parameterName: String,
|
parameterName: String,
|
||||||
|
Loading…
Reference in New Issue
Block a user