在基于netty的项目中使用protobuf,需要处理不同的消息,因此需要不同的编码和解码方式(如下) p.addLast("protobufDecoder", new ProtobufDecoder(Communication.TRequest.getDefaultInstance())); p.addLast("protobufDecoder", new ProtobufDecoder(Communication.TResponse.getDefaultInstance())); 但netty中每个管道仅能注册一个解码和编码的方式,经过研究,想到把这些不同的消息封装成一个消息组,在不同的处理逻辑中再get相应的消息即可,而管道注册那边只需要注册一个消息格式: p.addLast("protobufDecoder", new ProtobufDecoder(Communication.ProtocolMessage.getDefaultInstance()));proto文件: //封装Request和Response消息,这样netty可以统一编码和解码 message ProtocolMessage { optional TRequest tRequest=1; optional TResponse tResponse=2; }终于成功解决了问题!