2018-03-11 21:58:59 +01:00
|
|
|
@file:JvmMultifileClass
|
|
|
|
@file:JvmName("DomainSerializers")
|
|
|
|
package org.moire.ultrasonic.cache.serializers
|
|
|
|
|
|
|
|
import com.twitter.serial.serializer.ObjectSerializer
|
|
|
|
import com.twitter.serial.serializer.SerializationContext
|
|
|
|
import com.twitter.serial.stream.SerializerInput
|
|
|
|
import com.twitter.serial.stream.SerializerOutput
|
2018-03-18 17:30:55 +01:00
|
|
|
import org.moire.ultrasonic.cache.DomainEntitySerializer
|
2018-03-11 21:58:59 +01:00
|
|
|
import org.moire.ultrasonic.domain.Artist
|
|
|
|
import org.moire.ultrasonic.domain.Indexes
|
|
|
|
|
|
|
|
private const val SERIALIZATION_VERSION = 1
|
|
|
|
|
2018-03-18 17:30:55 +01:00
|
|
|
private val indexesSerializer get() = object : ObjectSerializer<Indexes>(SERIALIZATION_VERSION) {
|
2018-03-11 21:58:59 +01:00
|
|
|
override fun serializeObject(
|
2018-03-24 19:47:55 +01:00
|
|
|
context: SerializationContext,
|
|
|
|
output: SerializerOutput<out SerializerOutput<*>>,
|
|
|
|
item: Indexes
|
2018-03-11 21:58:59 +01:00
|
|
|
) {
|
2018-03-18 17:30:55 +01:00
|
|
|
val artistListSerializer = getArtistListSerializer()
|
2018-03-11 21:58:59 +01:00
|
|
|
output.writeLong(item.lastModified)
|
2020-06-13 19:04:31 +02:00
|
|
|
.writeString(item.ignoredArticles)
|
|
|
|
.writeObject<MutableList<Artist>>(context, item.shortcuts, artistListSerializer)
|
|
|
|
.writeObject<MutableList<Artist>>(context, item.artists, artistListSerializer)
|
2018-03-11 21:58:59 +01:00
|
|
|
}
|
|
|
|
|
2021-04-22 20:51:12 +02:00
|
|
|
@Suppress("ReturnCount")
|
2018-03-11 21:58:59 +01:00
|
|
|
override fun deserializeObject(
|
2018-03-24 19:47:55 +01:00
|
|
|
context: SerializationContext,
|
|
|
|
input: SerializerInput,
|
|
|
|
versionNumber: Int
|
2018-03-11 21:58:59 +01:00
|
|
|
): Indexes? {
|
|
|
|
if (versionNumber != SERIALIZATION_VERSION) return null
|
|
|
|
|
2018-03-18 17:30:55 +01:00
|
|
|
val artistListDeserializer = getArtistListSerializer()
|
2018-03-11 21:58:59 +01:00
|
|
|
val lastModified = input.readLong()
|
|
|
|
val ignoredArticles = input.readString() ?: return null
|
2018-03-18 17:30:55 +01:00
|
|
|
val shortcutsList = input.readObject(context, artistListDeserializer) ?: return null
|
|
|
|
val artistsList = input.readObject(context, artistListDeserializer) ?: return null
|
2020-06-13 19:04:31 +02:00
|
|
|
return Indexes(
|
|
|
|
lastModified, ignoredArticles, shortcutsList.toMutableList(),
|
|
|
|
artistsList.toMutableList()
|
|
|
|
)
|
2018-03-11 21:58:59 +01:00
|
|
|
}
|
|
|
|
}
|
2018-03-18 17:30:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get serializer/deserializer for [Indexes] entity.
|
|
|
|
*/
|
|
|
|
fun getIndexesSerializer(): DomainEntitySerializer<Indexes> = indexesSerializer
|