• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.serialization
6 
7 import kotlinx.serialization.modules.*
8 import kotlinx.serialization.protobuf.*
9 import kotlin.native.concurrent.*
10 
11 @Serializable
12 open class PolyBase(@ProtoNumber(1) val id: Int) {
hashCodenull13     override fun hashCode(): Int {
14         return id
15     }
16 
toStringnull17     override fun toString(): String {
18         return "PolyBase(id=$id)"
19     }
20 
equalsnull21     override fun equals(other: Any?): Boolean {
22         if (this === other) return true
23         if (other == null || this::class != other::class) return false
24 
25         other as PolyBase
26 
27         if (id != other.id) return false
28 
29         return true
30     }
31 
32 }
33 
34 @Serializable
35 data class PolyDerived(@ProtoNumber(2) val s: String) : PolyBase(1)
36 
37 @Serializable
38 abstract class SimpleAbstract
39 
40 @Serializable
41 data class SimpleIntInheritor(val i: Int, val s: String) : SimpleAbstract()
42 
43 @Serializable
44 data class SimpleStringInheritor(val s: String, val i: Int) : SimpleAbstract()
45 
46 @Serializable
47 data class PolyBox(@Polymorphic val boxed: SimpleAbstract)
48 
<lambda>null49 val SimplePolymorphicModule = SerializersModule {
50     polymorphic(SimpleAbstract::class) {
51         subclass(SimpleIntInheritor.serializer())
52         subclass(SimpleStringInheritor.serializer())
53     }
54 }
55 
56 @Serializable
57 data class SealedBox(val boxed: List<SimpleSealed>)
58 
59 @Serializable
60 sealed class SimpleSealed {
61     @Serializable
62     public data class SubSealedA(val s: String) : SimpleSealed()
63 
64     @Serializable
65     public data class SubSealedB(val i: Int) : SimpleSealed()
66 }
67 
68