Package io.netty.handler.codec.protobuf
Class ProtobufDecoderNano
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.handler.codec.MessageToMessageDecoder<io.netty.buffer.ByteBuf>
-
- io.netty.handler.codec.protobuf.ProtobufDecoderNano
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler
@Sharable public class ProtobufDecoderNano extends io.netty.handler.codec.MessageToMessageDecoder<io.netty.buffer.ByteBuf>Decodes a receivedByteBufinto a Google Protocol BuffersMessageNano. Please note that this decoder must be used with a properByteToMessageDecodersuch asLengthFieldBasedFrameDecoderif you are using a stream-based transport such as TCP/IP. A typical setup for TCP/IP would be:
and then you can use aChannelPipelinepipeline = ...; // Decoders pipeline.addLast("frameDecoder", newLengthFieldBasedFrameDecoder(1048576, 0, 4, 0, 4)); pipeline.addLast("protobufDecoder", newProtobufDecoderNano(MyMessage.getDefaultInstance())); // Encoder pipeline.addLast("frameEncoder", newLengthFieldPrepender(4)); pipeline.addLast("protobufEncoder", newProtobufEncoderNano());MyMessageinstead of aByteBufas a message:void channelRead(
ChannelHandlerContextctx, Object msg) { MyMessage req = (MyMessage) msg; MyMessage res = MyMessage.newBuilder().setText( "Did you say '" + req.getText() + "'?").build(); ch.write(res); }
-
-
Constructor Summary
Constructors Constructor Description ProtobufDecoderNano(Class<? extends com.google.protobuf.nano.MessageNano> clazz)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddecode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf msg, List<Object> out)-
Methods inherited from class io.netty.handler.codec.MessageToMessageDecoder
acceptInboundMessage, channelRead, channelReadComplete
-
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
-
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharable
-
-
-
-
Constructor Detail
-
ProtobufDecoderNano
public ProtobufDecoderNano(Class<? extends com.google.protobuf.nano.MessageNano> clazz)
Creates a new instance.
-
-