Add documentation, move ByteBuf extensions into an object and generify SessionContainer
This commit is contained in:
parent
3c85b6c105
commit
6daa459fa6
23 changed files with 215 additions and 132 deletions
|
@ -8,24 +8,27 @@ class FramingCodec: ByteToMessageCodec<ByteBuf>() {
|
|||
private var currentLength: Int? = null
|
||||
|
||||
override fun encode(ctx: ChannelHandlerContext, msg: ByteBuf, out: ByteBuf) {
|
||||
out.writeVarInt(msg.readableBytes())
|
||||
with(MinecraftDataTypes) { out.writeVarInt(msg.readableBytes()) }
|
||||
msg.readerIndex(0)
|
||||
out.writeBytes(msg)
|
||||
}
|
||||
|
||||
override fun decode(ctx: ChannelHandlerContext, msg: ByteBuf, out: MutableList<Any>) {
|
||||
var length = currentLength
|
||||
if (length == null) {
|
||||
if (msg.varIntReadable()) {
|
||||
length = msg.readVarInt()
|
||||
currentLength = length
|
||||
}
|
||||
else return
|
||||
}
|
||||
with(MinecraftDataTypes) {
|
||||
var length = currentLength
|
||||
|
||||
if (msg.readableBytes() >= length) {
|
||||
out.add(msg.readBytes(length))
|
||||
currentLength = null
|
||||
if (length == null) {
|
||||
if (msg.varIntReadable()) {
|
||||
length = msg.readVarInt()
|
||||
currentLength = length
|
||||
}
|
||||
else return
|
||||
}
|
||||
|
||||
if (msg.readableBytes() >= length) {
|
||||
out.add(msg.readBytes(length))
|
||||
currentLength = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue