I am exploring how to add multiple handlers in channel pipelines in SwiftNIO. In Java Netty, I have the following code:
@Component
public class NettyClientFilter extends ChannelInitializer<SocketChannel> {
@Autowired
private NettyClientHandler nettyClientHandler;
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline ph = ch.pipeline();
ph.addLast(new IdleStateHandler(20, 10, 0));
ph.addLast(new LengthFieldBasedFrameDecoder(1024, 0, 4, 0, 4));
ph.addLast(new ProtobufDecoder(IMessage.getDefaultInstance()));
ph.addLast(new LengthFieldPrepender(4));
ph.addLast(new ProtobufEncoder());
ph.addLast("nettyClientHandler",nettyClientHandler);
}
}
In the SwiftNIO, seems there are no similar classes as "LengthFieldBasedFrameDecoder", "ProtobufDecoder", "LengthFieldPrepender", "ProtobufEncoder". How can I get those ones in SwiftNIO?
Right, let me go through all the handlers you add to your pipeline in Netty:
IdleStateHandler: available withimport NIOfrom theswift-niopackageLengthFieldBasedFrameDecoder: right now in a PR but will be available shortly throughimport NIOExtrasfrom theswift-nio-extraspackageProtobufDecoder,LengthFieldPrepender,ProtobufEncoder: all currently unavailable but straightforward to implement:LengthFieldPrepender:ProtobufDecoder:ProtobufEncoder: