Netty 4.x怎么处理多个protobuf协议?
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
//解码用
p.addLast("frameDecoder", new ProtobufVarint32FrameDecoder());
//构造函数传递要解码成的类型 这里如果再有一个LocalDates的话应该怎么处理
p.addLast("protobufDecoder", new ProtobufDecoder(LocalTimeProtocol.LocalTimes.getDefaultInstance()));
//编码用
p.addLast("frameEncoder", new ProtobufVarint32LengthFieldPrepender());
p.addLast("protobufEncoder", new ProtobufEncoder());
//业务逻辑用 这里如果再有一个LocalDateClientHandler的话应该怎么处理
p.addLast("handler", new LocalTimeClientHandler());
}
希望给出的方案不是
if (arg1 instanceof Localtime){}
else if (arg1 instanceof LocalDate){}
.
.
.
因为实体太多!目前的想法时根据接收过来的arg1定义一个ID,根据ID调用相应的ProtobufDecoder;下面的Handler也一样。但是由于刚接触Netty不熟,所以特来求助。 查找方案中有看到一遍相似的文章:http://www.cnblogs.com/Solstice/archive/2011/04/03/2004458.html
想法可能不成熟,希望各位踢教!
麻烦各位最好给出Demo或者有类似实现的开源项目地址的,多谢!