Parcelable: Support CharSequence, IBinder/IInterface, objects, enums. Serialize Parcelable efficiently if possible
This commit is contained in:
+25
@@ -0,0 +1,25 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
package test
|
||||
|
||||
import kotlinx.android.parcel.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import android.text.SpannableString
|
||||
|
||||
@MagicParcel
|
||||
data class Test(val simple: CharSequence, val spanned: CharSequence) : Parcelable
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
val test = Test("John", SpannableString("Smith"))
|
||||
test.writeToParcel(parcel, 0)
|
||||
|
||||
val bytes = parcel.marshall()
|
||||
parcel.unmarshall(bytes, 0, bytes.size)
|
||||
|
||||
val test2 = readFromParcel<Test>(parcel)
|
||||
|
||||
assert(test.simple.toString() == test2.simple.toString())
|
||||
assert(test.spanned.toString() == test2.spanned.toString())
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
package test
|
||||
|
||||
import kotlinx.android.parcel.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
enum class Color {
|
||||
BLACK, WHITE
|
||||
}
|
||||
|
||||
@MagicParcel
|
||||
data class Test(val name: String, val color: Color) : Parcelable
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
val test = Test("John", Color.WHITE)
|
||||
test.writeToParcel(parcel, 0)
|
||||
|
||||
val bytes = parcel.marshall()
|
||||
parcel.unmarshall(bytes, 0, bytes.size)
|
||||
|
||||
val test2 = readFromParcel<Test>(parcel)
|
||||
assert(test == test2)
|
||||
}
|
||||
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
package test
|
||||
|
||||
import kotlinx.android.parcel.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
// Starts with A, should be loaded before other classes
|
||||
abstract class AParcelable : Parcelable
|
||||
|
||||
@MagicParcel
|
||||
data class P1(val a: String) : AParcelable()
|
||||
|
||||
sealed class Sealed : AParcelable()
|
||||
|
||||
@MagicParcel
|
||||
data class Sealed1(val a: Int) : Sealed()
|
||||
|
||||
@MagicParcel
|
||||
data class Test(val a: P1, val b: AParcelable, val c: Sealed, val d: Sealed1) : Parcelable
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
val test = Test(P1(""), P1("My"), Sealed1(1), Sealed1(5))
|
||||
test.writeToParcel(parcel, 0)
|
||||
|
||||
val bytes = parcel.marshall()
|
||||
parcel.unmarshall(bytes, 0, bytes.size)
|
||||
|
||||
val test2 = readFromParcel<Test>(parcel)
|
||||
assert(test == test2)
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
@file:JvmName("TestKt")
|
||||
package test
|
||||
|
||||
import kotlinx.android.parcel.*
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
|
||||
object Obj1 {
|
||||
object Obj2
|
||||
}
|
||||
|
||||
@MagicParcel
|
||||
data class Test(val o1: Obj1, val o2: Obj1.Obj2, val com: Com) : Parcelable {
|
||||
companion object Com {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fun box() = parcelTest { parcel ->
|
||||
val test = Test(Obj1, Obj1.Obj2, Test.Com)
|
||||
test.writeToParcel(parcel, 0)
|
||||
|
||||
val bytes = parcel.marshall()
|
||||
parcel.unmarshall(bytes, 0, bytes.size)
|
||||
|
||||
val test2 = readFromParcel<Test>(parcel)
|
||||
assert(test == test2)
|
||||
}
|
||||
Reference in New Issue
Block a user