diff --git a/gradle.properties b/gradle.properties index dfabf3e..3d73e82 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ kotlin.code.style=official specifyKotlinAsDependency=false projectGroup=ru.dbotthepony.kommons -projectVersion=2.10.1 +projectVersion=2.10.2 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 c35b48a..da28fc1 100644 --- a/src/main/kotlin/ru/dbotthepony/kommons/io/StreamCodec.kt +++ b/src/main/kotlin/ru/dbotthepony/kommons/io/StreamCodec.kt @@ -213,6 +213,30 @@ interface StreamCodec { return copy.invoke(value) } } + + class Pair(private val left: StreamCodec, private val right: StreamCodec) : StreamCodec> { + override fun read(stream: DataInputStream): kotlin.Pair { + val left = left.read(stream) + val right = right.read(stream) + return left to right + } + + override fun write(stream: DataOutputStream, value: kotlin.Pair) { + left.write(stream, value.first) + right.write(stream, value.second) + } + + override fun copy(value: kotlin.Pair): kotlin.Pair { + val left = left.copy(value.first) + val right = right.copy(value.second) + + if (left !== this.left && right !== this.right) { + return left to right + } else { + return value + } + } + } } fun StreamCodec.map(from: T.() -> R, to: R.() -> T): StreamCodec {