All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.http4k.connect.storage.AutoCodec.kt Maven / Gradle / Ivy

There is a newer version: 5.35.2.0
Show newest version
package org.http4k.connect.storage

import io.lettuce.core.codec.RedisCodec
import io.lettuce.core.codec.StringCodec
import org.http4k.format.AutoMarshalling
import java.nio.ByteBuffer
import java.nio.charset.StandardCharsets.UTF_8

inline fun  AutoRedisCodec(autoMarshalling: AutoMarshalling) = object : RedisCodec {
    override fun decodeKey(bytes: ByteBuffer) = UTF_8.decode(bytes).toString()

    override fun decodeValue(bytes: ByteBuffer) = autoMarshalling.asA(UTF_8.decode(bytes).toString())

    override fun encodeKey(key: String) = StringCodec().encodeKey(key)

    override fun encodeValue(value: T) = UTF_8.encode(autoMarshalling.asFormatString(value))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy