Created
May 4, 2020 15:10
-
-
Save mel4tonin4/1605d28e9bd2471c5bfb013b2d31f0ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.arrowkt.example.inline_serialization | |
import kotlinx.serialization.* | |
import io.arrowkt.example.ChannelCount | |
@Serializer(forClass = ChannelCount::class) | |
class ChannelCountSerializer : KSerializer<ChannelCount> { | |
override val descriptor: SerialDescriptor = | |
PrimitiveDescriptor("ChannelCount", PrimitiveKind.INT) | |
override fun serialize(encoder: Encoder, value: ChannelCount) { | |
encoder.encodeInt(value.value) | |
} | |
override fun deserialize(decoder: Decoder): ChannelCount { | |
return ChannelCount(decoder.decodeInt()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.arrowkt.example | |
//metadebug | |
@InlineSerializable | |
data class ChannelCount(val value : Int) { | |
override fun toString(): String = "$value channels" | |
operator fun plus(other : ChannelCount) = | |
ChannelCount(value + other.value) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.arrowkt.example | |
//meta: Mon May 04 16:52:49 CEST 2020 | |
@arrow.synthetic | |
@kotlinx.serialization.Serializable(with = io.arrowkt.example.inline_serialization.ChannelCountSerializer::class) | |
@InlineSerializable | |
data class ChannelCount(val value: Int) { | |
override fun toString(): String = "$value channels" | |
operator fun plus(other: ChannelCount) = ChannelCount(value + other.value) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.arrowkt.example.inline_serialization | |
import kotlinx.serialization.* | |
import io.arrowkt.example.UserId | |
@Serializer(forClass = UserId::class) | |
class UserIdSerializer : KSerializer<UserId> { | |
override val descriptor: SerialDescriptor = | |
PrimitiveDescriptor("UserId", PrimitiveKind.STRING) | |
override fun serialize(encoder: Encoder, value: UserId) { | |
encoder.encodeString(value.value) | |
} | |
override fun deserialize(decoder: Decoder): UserId { | |
return UserId(decoder.decodeString()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.arrowkt.example | |
@InlineSerializable | |
data class UserId(val value : String) { | |
companion object { | |
fun unique() = | |
UserId(java.util.UUID.randomUUID().toString()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment