main.app.cash.backfila.client.misk.hibernate.IdPrimaryKeyCursorAdapter.kt Maven / Gradle / Ivy
package app.cash.backfila.client.misk.hibernate
import misk.hibernate.DbEntity
import misk.hibernate.Id
import okio.ByteString
import okio.ByteString.Companion.encodeUtf8
internal object IdPrimaryKeyCursorAdapter : PrimaryKeyCursorAdapter> {
override fun toByteString(pk: Id<*>): ByteString {
return pk.toString().encodeUtf8()
}
override fun fromByteString(byteString: ByteString): Result> {
val id = byteString.utf8().toLongOrNull()
?: return Result.failure(NumberFormatException())
return Result.success(Id(id))
}
/** This placeholder exists so we can create a backfill without a type parameter. */
private class DbPlaceholder : DbEntity {
override val id: Id get() = throw IllegalStateException("unreachable")
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy