c7d4a7e1f1
This commit adds support for the Parcelize plugin to generate default serialization implementation for the kotlin.time.Duration. As Parcelize already supports serializing some of the kotlin library types it makes sense to support more common ones for the user convenience. https://issuetracker.google.com/issues/264614661
43 lines
1.1 KiB
Kotlin
Vendored
43 lines
1.1 KiB
Kotlin
Vendored
// WITH_STDLIB
|
|
|
|
@file:JvmName("TestKt")
|
|
package test
|
|
|
|
import kotlinx.parcelize.*
|
|
import android.os.Parcelable
|
|
import kotlin.time.Duration
|
|
import kotlin.time.Duration.Companion.seconds
|
|
import kotlin.time.Duration.Companion.nanoseconds
|
|
|
|
@Parcelize
|
|
data class Test(
|
|
val basic: Duration,
|
|
val negative: Duration,
|
|
val nullable: Duration?,
|
|
val nullableWithValue: Duration?,
|
|
val noNanoseconds: Duration,
|
|
val noSeconds: Duration,
|
|
val infinite: Duration,
|
|
val negativeInfinite: Duration,
|
|
) : Parcelable
|
|
|
|
|
|
fun box() = parcelTest { parcel ->
|
|
val test = Test(
|
|
basic = 10.seconds + 2.nanoseconds,
|
|
negative = -10.seconds - 2.nanoseconds,
|
|
nullable = null,
|
|
nullableWithValue = 10.seconds + 2.nanoseconds,
|
|
noNanoseconds = 10.seconds,
|
|
noSeconds = 2.nanoseconds,
|
|
infinite = Duration.INFINITE,
|
|
negativeInfinite = -Duration.INFINITE,
|
|
)
|
|
test.writeToParcel(parcel, 0)
|
|
val bytes = parcel.marshall()
|
|
parcel.unmarshall(bytes, 0, bytes.size)
|
|
parcel.setDataPosition(0)
|
|
val got = parcelableCreator<Test>().createFromParcel(parcel)
|
|
assert(test == got)
|
|
}
|