Provide Unit (singleton) codecs

This commit is contained in:
DBotThePony 2025-03-18 18:55:55 +07:00
parent ef2602895b
commit c9dca76870
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -35,6 +35,14 @@ interface MatteryStreamCodec<in S : ByteBuf, V> : StreamCodec<@UnsafeVariance S,
}
}
class MUnit<V>(val value: V) : MatteryStreamCodec<ByteBuf, V> {
override fun decode(stream: ByteBuf): V {
return value
}
override fun encode(stream: ByteBuf, value: V) {}
}
abstract class AbstractPair<in S : ByteBuf, A, B, P>(private val first: MatteryStreamCodec<S, A>, private val second: MatteryStreamCodec<S, B>) : MatteryStreamCodec<S, P> {
protected abstract fun getFirst(value: P): A
protected abstract fun getSecond(value: P): B