liugl
2020-08-11 68d7250b95451272aaa7cf359fd68b98d91b4d56
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package cn.sinata.rxnetty.pipeline;
 
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.LengthFieldPrepender;
import io.reactivex.netty.pipeline.PipelineConfigurator;
 
public class LengthFieldConfigurator implements PipelineConfigurator<ByteBuf,ByteBuf> {
 
    @Override
    public void configureNewPipeline(ChannelPipeline pipeline) {
        pipeline.addLast("decoder", new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
        pipeline.addLast("encoder", new LengthFieldPrepender(4));
    }
}