Let ProtobufEncoder extend MessageToByteEncoder which makes more sense. Related to [#1222]

This commit is contained in:
Norman Maurer 2013-04-02 07:17:45 +02:00
parent a0fca93128
commit 6a9d055f57

View File

@ -24,9 +24,7 @@ import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline; import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder; import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.LengthFieldPrepender; import io.netty.handler.codec.LengthFieldPrepender;
import io.netty.handler.codec.MessageToMessageEncoder; import io.netty.handler.codec.MessageToByteEncoder;
import static io.netty.buffer.Unpooled.*;
/** /**
* Encodes the requested <a href="http://code.google.com/p/protobuf/">Google * Encodes the requested <a href="http://code.google.com/p/protobuf/">Google
@ -56,16 +54,16 @@ import static io.netty.buffer.Unpooled.*;
* </pre> * </pre>
*/ */
@Sharable @Sharable
public class ProtobufEncoder extends MessageToMessageEncoder<MessageLiteOrBuilder> { public class ProtobufEncoder extends MessageToByteEncoder<MessageLiteOrBuilder> {
@Override @Override
protected Object encode(ChannelHandlerContext ctx, MessageLiteOrBuilder msg) throws Exception { protected void encode(ChannelHandlerContext ctx, MessageLiteOrBuilder msg, ByteBuf out) throws Exception {
if (msg instanceof MessageLite) { if (msg instanceof MessageLite) {
return wrappedBuffer(((MessageLite) msg).toByteArray()); out.writeBytes(((MessageLite) msg).toByteArray());
return;
} }
if (msg instanceof MessageLite.Builder) { if (msg instanceof MessageLite.Builder) {
return wrappedBuffer(((MessageLite.Builder) msg).build().toByteArray()); out.writeBytes(((MessageLite.Builder) msg).build().toByteArray());
} }
return null;
} }
} }