From 672f185584ef2ce930b1ab9dd0aa0a8ae219901d Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 24 Feb 2024 23:22:16 +0700 Subject: [PATCH] RGBA stream codec --- gradle.properties | 2 +- .../kotlin/ru/dbotthepony/kommons/io/StreamCodec.kt | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 1bbd1bb..8d38b7a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ kotlin.code.style=official specifyKotlinAsDependency=false projectGroup=ru.dbotthepony.kommons -projectVersion=2.9.0 +projectVersion=2.9.1 guavaDepVersion=33.0.0 gsonDepVersion=2.8.9 diff --git a/src/main/kotlin/ru/dbotthepony/kommons/io/StreamCodec.kt b/src/main/kotlin/ru/dbotthepony/kommons/io/StreamCodec.kt index 2eafee5..e03b256 100644 --- a/src/main/kotlin/ru/dbotthepony/kommons/io/StreamCodec.kt +++ b/src/main/kotlin/ru/dbotthepony/kommons/io/StreamCodec.kt @@ -1,5 +1,6 @@ package ru.dbotthepony.kommons.io +import ru.dbotthepony.kommons.math.RGBAColor import java.io.DataInputStream import java.io.DataOutputStream import java.util.* @@ -195,6 +196,14 @@ val VarIntValueCodec = StreamCodec.Impl(DataInputStream::readSignedVarInt, DataO val VarLongValueCodec = StreamCodec.Impl(DataInputStream::readSignedVarLong, DataOutputStream::writeSignedVarLong) val BinaryStringCodec = StreamCodec.Impl(DataInputStream::readBinaryString, DataOutputStream::writeBinaryString) +val RGBCodec: StreamCodec = StreamCodec.Impl( + { s -> RGBAColor(s.readFloat(), s.readFloat(), s.readFloat()) }, + { s, v -> s.writeFloat(v.red); s.writeFloat(v.green); s.writeFloat(v.blue) }) + +val RGBACodec: StreamCodec = StreamCodec.Impl( + { s -> RGBAColor(s.readFloat(), s.readFloat(), s.readFloat(), s.readFloat()) }, + { s, v -> s.writeFloat(v.red); s.writeFloat(v.green); s.writeFloat(v.blue); s.writeFloat(v.alpha) }) + val OptionalBooleanValueCodec = StreamCodec.Optional(BooleanValueCodec) val OptionalByteValueCodec = StreamCodec.Optional(ByteValueCodec) val OptionalShortValueCodec = StreamCodec.Optional(ShortValueCodec) @@ -208,6 +217,8 @@ val OptionalUUIDValueCodec = StreamCodec.Optional(UUIDValueCodec) val OptionalVarIntValueCodec = StreamCodec.Optional(VarIntValueCodec) val OptionalVarLongValueCodec = StreamCodec.Optional(VarLongValueCodec) val OptionalBinaryStringCodec = StreamCodec.Optional(BinaryStringCodec) +val OptionalRGBCodec = StreamCodec.Optional(RGBCodec) +val OptionalRGBACodec = StreamCodec.Optional(RGBACodec) val KOptionalBooleanValueCodec = StreamCodec.KOptional(BooleanValueCodec) val KOptionalByteValueCodec = StreamCodec.KOptional(ByteValueCodec) @@ -222,6 +233,8 @@ val KOptionalUUIDValueCodec = StreamCodec.KOptional(UUIDValueCodec) val KOptionalVarIntValueCodec = StreamCodec.KOptional(VarIntValueCodec) val KOptionalVarLongValueCodec = StreamCodec.KOptional(VarLongValueCodec) val KOptionalBinaryStringCodec = StreamCodec.KOptional(BinaryStringCodec) +val KOptionalRGBCodec = StreamCodec.KOptional(RGBCodec) +val KOptionalRGBACodec = StreamCodec.KOptional(RGBACodec) fun > Class.codec() = StreamCodec.Enum(this) fun > KClass.codec() = StreamCodec.Enum(this.java)