StreamCodec.Pair
This commit is contained in:
parent
58ce191680
commit
f64dcacd63
@ -4,7 +4,7 @@ kotlin.code.style=official
|
|||||||
specifyKotlinAsDependency=false
|
specifyKotlinAsDependency=false
|
||||||
|
|
||||||
projectGroup=ru.dbotthepony.kommons
|
projectGroup=ru.dbotthepony.kommons
|
||||||
projectVersion=2.10.1
|
projectVersion=2.10.2
|
||||||
|
|
||||||
guavaDepVersion=33.0.0
|
guavaDepVersion=33.0.0
|
||||||
gsonDepVersion=2.8.9
|
gsonDepVersion=2.8.9
|
||||||
|
@ -213,6 +213,30 @@ interface StreamCodec<V> {
|
|||||||
return copy.invoke(value)
|
return copy.invoke(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Pair<L, R>(private val left: StreamCodec<L>, private val right: StreamCodec<R>) : StreamCodec<kotlin.Pair<L, R>> {
|
||||||
|
override fun read(stream: DataInputStream): kotlin.Pair<L, R> {
|
||||||
|
val left = left.read(stream)
|
||||||
|
val right = right.read(stream)
|
||||||
|
return left to right
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun write(stream: DataOutputStream, value: kotlin.Pair<L, R>) {
|
||||||
|
left.write(stream, value.first)
|
||||||
|
right.write(stream, value.second)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun copy(value: kotlin.Pair<L, R>): kotlin.Pair<L, R> {
|
||||||
|
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 <T, R> StreamCodec<T>.map(from: T.() -> R, to: R.() -> T): StreamCodec<R> {
|
fun <T, R> StreamCodec<T>.map(from: T.() -> R, to: R.() -> T): StreamCodec<R> {
|
||||||
|
Loading…
Reference in New Issue
Block a user