diff --git a/broker/src/main/kotlin/dev/usbharu/owl/broker/service/DefaultPropertySerializerFactory.kt b/broker/src/main/kotlin/dev/usbharu/owl/broker/service/DefaultPropertySerializerFactory.kt index b78fa47..3e34c65 100644 --- a/broker/src/main/kotlin/dev/usbharu/owl/broker/service/DefaultPropertySerializerFactory.kt +++ b/broker/src/main/kotlin/dev/usbharu/owl/broker/service/DefaultPropertySerializerFactory.kt @@ -1,9 +1,15 @@ package dev.usbharu.owl.broker.service -import dev.usbharu.owl.common.property.CustomPropertySerializerFactory -import dev.usbharu.owl.common.property.IntegerPropertySerializer -import dev.usbharu.owl.common.property.PropertySerializerFactory +import dev.usbharu.owl.common.property.* import org.koin.core.annotation.Singleton @Singleton(binds = [PropertySerializerFactory::class]) -class DefaultPropertySerializerFactory : CustomPropertySerializerFactory(setOf(IntegerPropertySerializer())) \ No newline at end of file +class DefaultPropertySerializerFactory : + CustomPropertySerializerFactory( + setOf( + IntegerPropertySerializer(), + StringPropertyValueSerializer(), + DoublePropertySerializer(), + BooleanPropertySerializer() + ) + ) \ No newline at end of file diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/property/BooleanPropertyValue.kt b/common/src/main/kotlin/dev/usbharu/owl/common/property/BooleanPropertyValue.kt new file mode 100644 index 0000000..0a04685 --- /dev/null +++ b/common/src/main/kotlin/dev/usbharu/owl/common/property/BooleanPropertyValue.kt @@ -0,0 +1,24 @@ +package dev.usbharu.owl.common.property + +class BooleanPropertyValue(override val value: Boolean) : PropertyValue() { + override val type: PropertyType + get() = PropertyType.binary +} + +class BooleanPropertySerializer : PropertySerializer { + 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 { + return BooleanPropertyValue(string.replace("bool:", "").toBoolean()) + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/property/DoublePropertyValue.kt b/common/src/main/kotlin/dev/usbharu/owl/common/property/DoublePropertyValue.kt new file mode 100644 index 0000000..13156f2 --- /dev/null +++ b/common/src/main/kotlin/dev/usbharu/owl/common/property/DoublePropertyValue.kt @@ -0,0 +1,24 @@ +package dev.usbharu.owl.common.property + +class DoublePropertyValue(override val value: Double) : PropertyValue() { + override val type: PropertyType + get() = PropertyType.number +} + +class DoublePropertySerializer : PropertySerializer { + 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 { + return DoublePropertyValue(string.replace("double:", "").toDouble()) + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/property/IntegerPropertyValue.kt b/common/src/main/kotlin/dev/usbharu/owl/common/property/IntegerPropertyValue.kt index 331f8f7..4278206 100644 --- a/common/src/main/kotlin/dev/usbharu/owl/common/property/IntegerPropertyValue.kt +++ b/common/src/main/kotlin/dev/usbharu/owl/common/property/IntegerPropertyValue.kt @@ -18,7 +18,7 @@ package dev.usbharu.owl.common.property class IntegerPropertyValue(override val value: Int) : PropertyValue() { override val type: PropertyType - get() = PropertyType.integer + get() = PropertyType.number } class IntegerPropertySerializer : PropertySerializer { diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertyType.kt b/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertyType.kt index 6694114..c9dabae 100644 --- a/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertyType.kt +++ b/common/src/main/kotlin/dev/usbharu/owl/common/property/PropertyType.kt @@ -17,6 +17,7 @@ package dev.usbharu.owl.common.property enum class PropertyType { - integer, - string + number, + string, + binary } \ No newline at end of file diff --git a/common/src/main/kotlin/dev/usbharu/owl/common/property/StringPropertyValue.kt b/common/src/main/kotlin/dev/usbharu/owl/common/property/StringPropertyValue.kt new file mode 100644 index 0000000..a7030d2 --- /dev/null +++ b/common/src/main/kotlin/dev/usbharu/owl/common/property/StringPropertyValue.kt @@ -0,0 +1,24 @@ +package dev.usbharu.owl.common.property + +class StringPropertyValue(override val value: String) : PropertyValue() { + override val type: PropertyType + get() = PropertyType.string +} + +class StringPropertyValueSerializer : PropertySerializer { + 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 { + return StringPropertyValue(string.replace("str:", "")) + } +} \ No newline at end of file