File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
src/jvmMain/kotlin/spp/protocol/util Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ package spp.protocol.util
2+
3+ import com.fasterxml.jackson.core.JsonGenerator
4+ import com.fasterxml.jackson.core.JsonParser
5+ import com.fasterxml.jackson.databind.*
6+ import kotlinx.datetime.Instant
7+
8+ /* *
9+ * Used to serialize/deserialize Kotlin classes.
10+ *
11+ * @since 0.1.0
12+ */
13+ object KSerializers {
14+ class KotlinInstantSerializer : JsonSerializer <Instant >() {
15+ override fun serialize (value : Instant , jgen : JsonGenerator , provider : SerializerProvider ) =
16+ jgen.writeNumber(value.toEpochMilliseconds())
17+ }
18+
19+ class KotlinInstantDeserializer : JsonDeserializer <Instant >() {
20+ override fun deserialize (p : JsonParser , p1 : DeserializationContext ): Instant =
21+ Instant .fromEpochMilliseconds((p.codec.readTree(p) as JsonNode ).longValue())
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ package spp.protocol.util
2+
3+ import io.vertx.core.buffer.Buffer
4+ import io.vertx.core.eventbus.MessageCodec
5+ import java.util.*
6+
7+ /* *
8+ * Used to transmit protocol messages.
9+ *
10+ * @since 0.1.0
11+ */
12+ class LocalMessageCodec <T > : MessageCodec <T , T > {
13+ override fun encodeToWire (buffer : Buffer , o : T ): Unit =
14+ throw UnsupportedOperationException (" Not supported yet." )
15+
16+ override fun decodeFromWire (pos : Int , buffer : Buffer ): T =
17+ throw UnsupportedOperationException (" Not supported yet." )
18+
19+ override fun transform (o : T ): T = o
20+ override fun name (): String = UUID .randomUUID().toString()
21+ override fun systemCodecID (): Byte = - 1
22+ }
You can’t perform that action at this time.
0 commit comments