Archived
1
0
Fork 0

Add documentation, move ByteBuf extensions into an object and generify SessionContainer

This commit is contained in:
Moritz Ruth 2020-08-13 16:53:02 +02:00
parent 3c85b6c105
commit 6daa459fa6
No known key found for this signature in database
GPG key ID: AFD57E23E753841B
23 changed files with 215 additions and 132 deletions

View file

@ -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
}
}
}
}