mirror of https://github.com/usbharu/Hideout.git
feat: PropertySerializerを追加
This commit is contained in:
parent
f917809b77
commit
20d6cf3c32
|
@ -1,9 +1,15 @@
|
||||||
package dev.usbharu.owl.broker.service
|
package dev.usbharu.owl.broker.service
|
||||||
|
|
||||||
import dev.usbharu.owl.common.property.CustomPropertySerializerFactory
|
import dev.usbharu.owl.common.property.*
|
||||||
import dev.usbharu.owl.common.property.IntegerPropertySerializer
|
|
||||||
import dev.usbharu.owl.common.property.PropertySerializerFactory
|
|
||||||
import org.koin.core.annotation.Singleton
|
import org.koin.core.annotation.Singleton
|
||||||
|
|
||||||
@Singleton(binds = [PropertySerializerFactory::class])
|
@Singleton(binds = [PropertySerializerFactory::class])
|
||||||
class DefaultPropertySerializerFactory : CustomPropertySerializerFactory(setOf(IntegerPropertySerializer()))
|
class DefaultPropertySerializerFactory :
|
||||||
|
CustomPropertySerializerFactory(
|
||||||
|
setOf(
|
||||||
|
IntegerPropertySerializer(),
|
||||||
|
StringPropertyValueSerializer(),
|
||||||
|
DoublePropertySerializer(),
|
||||||
|
BooleanPropertySerializer()
|
||||||
|
)
|
||||||
|
)
|
|
@ -0,0 +1,24 @@
|
||||||
|
package dev.usbharu.owl.common.property
|
||||||
|
|
||||||
|
class BooleanPropertyValue(override val value: Boolean) : PropertyValue<Boolean>() {
|
||||||
|
override val type: PropertyType
|
||||||
|
get() = PropertyType.binary
|
||||||
|
}
|
||||||
|
|
||||||
|
class BooleanPropertySerializer : PropertySerializer<Boolean> {
|
||||||
|
override fun isSupported(propertyValue: PropertyValue<*>): Boolean {
|
||||||
|
return propertyValue.value is Boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSupported(string: String): Boolean {
|
||||||
|
return string.startsWith("bool:")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(propertyValue: PropertyValue<*>): String {
|
||||||
|
return "bool:" + propertyValue.value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun deserialize(string: String): PropertyValue<Boolean> {
|
||||||
|
return BooleanPropertyValue(string.replace("bool:", "").toBoolean())
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package dev.usbharu.owl.common.property
|
||||||
|
|
||||||
|
class DoublePropertyValue(override val value: Double) : PropertyValue<Double>() {
|
||||||
|
override val type: PropertyType
|
||||||
|
get() = PropertyType.number
|
||||||
|
}
|
||||||
|
|
||||||
|
class DoublePropertySerializer : PropertySerializer<Double> {
|
||||||
|
override fun isSupported(propertyValue: PropertyValue<*>): Boolean {
|
||||||
|
return propertyValue.value is Double
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSupported(string: String): Boolean {
|
||||||
|
return string.startsWith("double:")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(propertyValue: PropertyValue<*>): String {
|
||||||
|
return "double:" + propertyValue.value.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun deserialize(string: String): PropertyValue<Double> {
|
||||||
|
return DoublePropertyValue(string.replace("double:", "").toDouble())
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,7 +18,7 @@ package dev.usbharu.owl.common.property
|
||||||
|
|
||||||
class IntegerPropertyValue(override val value: Int) : PropertyValue<Int>() {
|
class IntegerPropertyValue(override val value: Int) : PropertyValue<Int>() {
|
||||||
override val type: PropertyType
|
override val type: PropertyType
|
||||||
get() = PropertyType.integer
|
get() = PropertyType.number
|
||||||
}
|
}
|
||||||
|
|
||||||
class IntegerPropertySerializer : PropertySerializer<Int> {
|
class IntegerPropertySerializer : PropertySerializer<Int> {
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package dev.usbharu.owl.common.property
|
package dev.usbharu.owl.common.property
|
||||||
|
|
||||||
enum class PropertyType {
|
enum class PropertyType {
|
||||||
integer,
|
number,
|
||||||
string
|
string,
|
||||||
|
binary
|
||||||
}
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package dev.usbharu.owl.common.property
|
||||||
|
|
||||||
|
class StringPropertyValue(override val value: String) : PropertyValue<String>() {
|
||||||
|
override val type: PropertyType
|
||||||
|
get() = PropertyType.string
|
||||||
|
}
|
||||||
|
|
||||||
|
class StringPropertyValueSerializer : PropertySerializer<String> {
|
||||||
|
override fun isSupported(propertyValue: PropertyValue<*>): Boolean {
|
||||||
|
return propertyValue.value is String
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSupported(string: String): Boolean {
|
||||||
|
return string.startsWith("str:")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun serialize(propertyValue: PropertyValue<*>): String {
|
||||||
|
return "str:" + propertyValue.value
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun deserialize(string: String): PropertyValue<String> {
|
||||||
|
return StringPropertyValue(string.replace("str:", ""))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue