commonTest.kotlinx.serialization.protobuf.ProtobufUnionEnumTest.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlinx-serialization-protobuf-metadata Show documentation
Show all versions of kotlinx-serialization-protobuf-metadata Show documentation
Kotlin multiplatform serialization runtime library
The newest version!
/*
* Copyright 2017-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.serialization.protobuf
import kotlinx.serialization.*
import kotlin.test.*
class ProtobufUnionEnumTest {
enum class SomeEnum { ALPHA, BETA, GAMMA }
@Serializable
data class WithUnions(@ProtoNumber(5) val s: String,
@ProtoNumber(6) val e: SomeEnum = SomeEnum.ALPHA,
@ProtoNumber(7) val i: Int = 42)
@Test
fun testEnum() {
val data = WithUnions("foo", SomeEnum.BETA)
val hex = ProtoBuf.encodeToHexString(WithUnions.serializer(), data)
val restored = ProtoBuf.decodeFromHexString(WithUnions.serializer(), hex)
assertEquals(data, restored)
}
}