From e62c9c1aec2c5866251b58d436d9884e21f96440 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Wed, 7 Jan 2009 12:48:36 +0000 Subject: [PATCH] Simplified the protobuf example in javadoc using LengthFieldPrepender --- .../handler/codec/protobuf/ProtobufDecoder.java | 12 ++---------- .../handler/codec/protobuf/ProtobufEncoder.java | 11 ++--------- 2 files changed, 4 insertions(+), 19 deletions(-) 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}