All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.jpower.kcp.example.rtt.TcpRttDecoder Maven / Gradle / Ivy

There is a newer version: 1.5.2
Show newest version
package io.jpower.kcp.example.rtt;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * @author szh
 */
public class TcpRttDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception {
        if (in.readableBytes() < 8) {
            return;
        }

        short dataLen = in.getShort(in.readerIndex() + 6);
        if (in.readableBytes() < dataLen) {
            return;
        }

        ByteBuf msg = in.readRetainedSlice(8 + dataLen);
        out.add(msg);
    }

}