-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
core/src/main/kotlin/com/labijie/caching/kryo/InstantSerializer.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* @author Anders Xiao | ||
* @date 2024-06-19 | ||
*/ | ||
package com.labijie.caching.kryo | ||
|
||
import com.esotericsoftware.kryo.Kryo | ||
import com.esotericsoftware.kryo.Serializer | ||
import com.esotericsoftware.kryo.io.Input | ||
import com.esotericsoftware.kryo.io.Output | ||
import java.time.Instant | ||
|
||
|
||
object InstantSerializer : Serializer<Instant>() { | ||
override fun write(kryo: Kryo, output: Output, instant: Instant) { | ||
output.writeLong(instant.toEpochMilli()) | ||
} | ||
|
||
override fun read(kryo: Kryo, input: Input, instantClass: Class<out Instant>): Instant { | ||
return Instant.ofEpochMilli(input.readLong()) | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
core/src/main/kotlin/com/labijie/caching/kryo/LocalDateTimeSerializer.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* @author Anders Xiao | ||
* @date 2024-06-19 | ||
*/ | ||
package com.labijie.caching.kryo | ||
|
||
import com.esotericsoftware.kryo.Kryo | ||
import com.esotericsoftware.kryo.Serializer | ||
import com.esotericsoftware.kryo.io.Input | ||
import com.esotericsoftware.kryo.io.Output | ||
import java.time.Instant | ||
import java.time.LocalDateTime | ||
import java.time.ZoneOffset | ||
|
||
|
||
object LocalDateTimeSerializer : Serializer<LocalDateTime>() { | ||
override fun write(kryo: Kryo, output: Output, datetime: LocalDateTime) { | ||
output.writeLong(datetime.toInstant(ZoneOffset.UTC).toEpochMilli()) | ||
} | ||
|
||
override fun read(kryo: Kryo, input: Input, datetime: Class<out LocalDateTime>): LocalDateTime { | ||
val instant = Instant.ofEpochMilli(input.readLong()) | ||
return LocalDateTime.ofInstant(instant, ZoneOffset.UTC) | ||
} | ||
} |