Skip to content
Browse files

Let ProtobufEncoder extend MessageToByteEncoder which makes more sens…

…e. Related to [#1222]
  • Loading branch information...
1 parent a0fca93 commit 6a9d055f578bc85eb7780dcc5484aa11e9da50f6 @normanmaurer normanmaurer committed Apr 2, 2013
Showing with 6 additions and 8 deletions.
  1. +6 −8 codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufEncoder.java
View
14 codec/src/main/java/io/netty/handler/codec/protobuf/ProtobufEncoder.java
@@ -24,9 +24,7 @@
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.codec.LengthFieldPrepender;
-import io.netty.handler.codec.MessageToMessageEncoder;
-
-import static io.netty.buffer.Unpooled.*;
+import io.netty.handler.codec.MessageToByteEncoder;
/**
* Encodes the requested <a href="http://code.google.com/p/protobuf/">Google
@@ -56,16 +54,16 @@
* </pre>
*/
@Sharable
-public class ProtobufEncoder extends MessageToMessageEncoder<MessageLiteOrBuilder> {
+public class ProtobufEncoder extends MessageToByteEncoder<MessageLiteOrBuilder> {
@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) {
- return wrappedBuffer(((MessageLite) msg).toByteArray());
+ out.writeBytes(((MessageLite) msg).toByteArray());
+ return;
}
if (msg instanceof MessageLite.Builder) {
- return wrappedBuffer(((MessageLite.Builder) msg).build().toByteArray());
+ out.writeBytes(((MessageLite.Builder) msg).build().toByteArray());
}
- return null;
}
}

2 comments on commit 6a9d055

@trustin
The Netty Project member
trustin commented on 6a9d055 Apr 2, 2013

This is incorrect. It should be a MessageToMessageEncoder so that length field prepender can handles the encoded frame.

@normanmaurer
The Netty Project member

Good catch! Reverted

Please sign in to comment.
Something went wrong with that request. Please try again.