Class ProtobufEncoderNano
- java.lang.Object
-
- io.netty5.channel.ChannelHandlerAdapter
-
- io.netty5.handler.codec.MessageToMessageEncoder<com.google.protobuf.nano.MessageNano>
-
- io.netty.contrib.handler.codec.protobuf.ProtobufEncoderNano
-
- All Implemented Interfaces:
io.netty5.channel.ChannelHandler
public class ProtobufEncoderNano extends io.netty5.handler.codec.MessageToMessageEncoder<com.google.protobuf.nano.MessageNano>Encodes the requested Google Protocol BuffersMessageNanointo aBuffer. 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 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 ProtobufEncoderNano()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidencode(io.netty5.channel.ChannelHandlerContext ctx, com.google.protobuf.nano.MessageNano msg, List<Object> out)booleanisSharable()-
Methods inherited from class io.netty5.handler.codec.MessageToMessageEncoder
acceptOutboundMessage, encodeAndClose, write
-
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, channelRead, channelReadComplete, channelRegistered, channelShutdown, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, flush, handlerAdded, handlerRemoved, pendingOutboundBytes, read, register, sendOutboundEvent, shutdown
-
-
-
-
Method Detail
-
encode
protected void encode(io.netty5.channel.ChannelHandlerContext ctx, com.google.protobuf.nano.MessageNano msg, List<Object> out) throws Exception- Overrides:
encodein classio.netty5.handler.codec.MessageToMessageEncoder<com.google.protobuf.nano.MessageNano>- Throws:
Exception
-
isSharable
public boolean isSharable()
-
-