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

org.zhongweixian.decode.MessageDecoder Maven / Gradle / Ivy

There is a newer version: 2.1.5
Show newest version
package org.zhongweixian.decode;

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

import java.util.List;

/**
 * Created by caoliang on 2020-02-25
 */
public class MessageDecoder extends ByteToMessageDecoder {

    @Override
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List list) throws Exception {
        byte[] bytes = new byte[byteBuf.readableBytes()];
        byteBuf.readBytes(bytes);
        list.add(new String(bytes, "UTF-8"));
    }
}