diff --git a/src/main/java/org/jboss/netty/handler/codec/protobuf/ProtobufDecoder.java b/src/main/java/org/jboss/netty/handler/codec/protobuf/ProtobufDecoder.java index 534848abd3..a984ced878 100644 --- a/src/main/java/org/jboss/netty/handler/codec/protobuf/ProtobufDecoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/protobuf/ProtobufDecoder.java @@ -30,8 +30,8 @@ import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipelineCoverage; import org.jboss.netty.handler.codec.frame.FrameDecoder; import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.jboss.netty.handler.codec.frame.LengthFieldPrepender; import org.jboss.netty.handler.codec.oneone.OneToOneDecoder; -import org.jboss.netty.handler.codec.oneone.OneToOneEncoder; import com.google.protobuf.ExtensionRegistry; import com.google.protobuf.Message; @@ -53,15 +53,7 @@ import com.google.protobuf.Message; * new {@link ProtobufDecoder}(MyMessage.getDefaultInstance())); * * // Encoder - * pipeline.addLast("frameEncoder", - * new {@link OneToOneEncoder}() { - * protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) { - * ChannelBuffer header = ChanelBuffers.buffer(4); - * ChannelBuffer body = (ChannelBuffer) msg; - * header.writeInt(body.readableBytes()); - * return ChannelBuffers.wrappedBuffer(header, body); - * } - * }); + * pipeline.addLast("frameEncoder", new {@link LengthFieldPrepender}(4)); * pipeline.addLast("protobufEncoder", new {@link ProtobufEncoder}()); * * and then you can use a {@code MyMessage} instead of a {@link ChannelBuffer} diff --git a/src/main/java/org/jboss/netty/handler/codec/protobuf/ProtobufEncoder.java b/src/main/java/org/jboss/netty/handler/codec/protobuf/ProtobufEncoder.java index 4c0663ff0a..a4b3fa3052 100644 --- a/src/main/java/org/jboss/netty/handler/codec/protobuf/ProtobufEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/protobuf/ProtobufEncoder.java @@ -30,6 +30,7 @@ import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipelineCoverage; import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import org.jboss.netty.handler.codec.frame.LengthFieldPrepender; import org.jboss.netty.handler.codec.oneone.OneToOneEncoder; import com.google.protobuf.Message; @@ -48,15 +49,7 @@ import com.google.protobuf.Message; * new {@link ProtobufDecoder}(MyMessage.getDefaultInstance())); * * // Encoder - * pipeline.addLast("frameEncoder", - * new {@link OneToOneEncoder}() { - * protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) { - * ChannelBuffer header = ChanelBuffers.buffer(4); - * ChannelBuffer body = (ChannelBuffer) msg; - * header.writeInt(body.readableBytes()); - * return ChannelBuffers.wrappedBuffer(header, body); - * } - * }); + * pipeline.addLast("frameEncoder", new {@link LengthFieldPrepender}(4)); * pipeline.addLast("protobufEncoder", new {@link ProtobufEncoder}()); * * and then you can use a {@code MyMessage} instead of a {@link ChannelBuffer}