Class ProtobufDecoder
- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToMessageDecoder<io.netty5.buffer.Buffer>
-
- io.netty.contrib.handler.codec.protobuf.ProtobufDecoder
-
- All Implemented Interfaces:
io.netty5.channel.ChannelHandler
public class ProtobufDecoder extends io.netty5.handler.codec.MessageToMessageDecoder<io.netty5.buffer.Buffer>Decodes a receivedBufferinto a Google Protocol BuffersMessageandMessageLite. Please note that this decoder must be used with a properByteToMessageDecodersuch asProtobufVarint32FrameDecoderorLengthFieldBasedFrameDecoderif 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", newProtobufDecoder(MyMessage.getDefaultInstance())); // Encoder pipeline.addLast("frameEncoder", newLengthFieldPrepender(4)); pipeline.addLast("protobufEncoder", newProtobufEncoder());MyMessageinstead of aBufferas 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 ProtobufDecoder(com.google.protobuf.MessageLite prototype)Creates a new instance.ProtobufDecoder(com.google.protobuf.MessageLite prototype, com.google.protobuf.ExtensionRegistry extensionRegistry)ProtobufDecoder(com.google.protobuf.MessageLite prototype, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voiddecode(io.netty5.channel.ChannelHandlerContext ctx, io.netty5.buffer.Buffer msg)booleanisSharable()-
Methods inherited from class io.netty5.handler.codec.MessageToMessageDecoder
acceptInboundMessage, channelRead, decodeAndClose
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.netty5.channel.ChannelHandler
bind, channelActive, channelExceptionCaught, channelInactive, channelInboundEvent, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown, write
-
-
-
-
Constructor Detail
-
ProtobufDecoder
public ProtobufDecoder(com.google.protobuf.MessageLite prototype)
Creates a new instance.
-
ProtobufDecoder
public ProtobufDecoder(com.google.protobuf.MessageLite prototype, com.google.protobuf.ExtensionRegistry extensionRegistry)
-
ProtobufDecoder
public ProtobufDecoder(com.google.protobuf.MessageLite prototype, com.google.protobuf.ExtensionRegistryLite extensionRegistry)
-
-