
@ChannelHandler.Sharable public class ProtobufEncoder extends OneToOneEncoder
Message and MessageLite into a
 ChannelBuffer. 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());
MyMessage instead of a ChannelBuffer
 as a message:
 void messageReceived(ChannelHandlerContextctx,MessageEvente) { MyMessage req = (MyMessage) e.getMessage(); MyMessage res = MyMessage.newBuilder().setText( "Did you say '" + req.getText() + "'?").build(); ch.write(res); }
ChannelHandler.Sharable| Constructor and Description | 
|---|
| ProtobufEncoder() | 
| Modifier and Type | Method and Description | 
|---|---|
| protected Object | encode(ChannelHandlerContext ctx,
      Channel channel,
      Object msg)Transforms the specified message into another message and return the
 transformed message. | 
doEncode, handleDownstreamprotected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception
OneToOneEncodernull, unlike
 you can in OneToOneDecoder.decode(ChannelHandlerContext, Channel, Object);
 you must return something, at least ChannelBuffers.EMPTY_BUFFER.encode in class OneToOneEncoderExceptionCopyright © 2008-2014 The Netty Project. All Rights Reserved.