commonMain.dev.gitlive.firebase.database.ServerValue.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of firebase-database-js Show documentation
Show all versions of firebase-database-js Show documentation
The Firebase Kotlin SDK is a Kotlin-first SDK for Firebase. It's API is similar to the Firebase Android SDK Kotlin Extensions but also supports multiplatform projects, enabling you to use Firebase directly from your common source targeting iOS, Android or JS.
package dev.gitlive.firebase.database
import dev.gitlive.firebase.FirebaseDecoder
import dev.gitlive.firebase.FirebaseEncoder
import dev.gitlive.firebase.SpecialValueSerializer
import kotlinx.serialization.KSerializer
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
/** Represents a Firebase ServerValue. */
@Serializable(with = ServerValueSerializer::class)
expect class ServerValue internal constructor(nativeValue: Any){
internal val nativeValue: Any
companion object {
val TIMESTAMP: ServerValue
fun increment(delta: Double): ServerValue
}
}
/** Serializer for [ServerValue]. Must be used with [FirebaseEncoder]/[FirebaseDecoder].*/
object ServerValueSerializer: KSerializer by SpecialValueSerializer(
serialName = "ServerValue",
toNativeValue = ServerValue::nativeValue,
fromNativeValue = { raw ->
raw?.let(::ServerValue) ?: throw SerializationException("Cannot deserialize $raw")
}
)
© 2015 - 2024 Weber Informatics LLC | Privacy Policy