
@ChannelPipelineCoverage(value="all") public class ProtobufEncoder extends OneToOneEncoder
Message 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(ChannelHandlerContext ctx, MessageEvent e) {
MyMessage req = (MyMessage) e.getMessage();
MyMessage res = MyMessage.newBuilder().setText(
"Did you say '" + req.getText() + "'?").build();
ch.write(res);
}
| Constructor and Description |
|---|
ProtobufEncoder()
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected Object |
encode(ChannelHandlerContext ctx,
Channel channel,
Object msg) |
handleDownstreamprotected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception
encode in class OneToOneEncoderExceptionCopyright © 2008-2013 JBoss, by Red Hat. All Rights Reserved.