Simplified the protobuf example in javadoc using LengthFieldPrepender

This commit is contained in:
Trustin Lee 2009-01-07 12:48:36 +00:00
parent a865090d7a
commit e62c9c1aec
2 changed files with 4 additions and 19 deletions

View File

@ -30,8 +30,8 @@ import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineCoverage; import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.handler.codec.frame.FrameDecoder; import org.jboss.netty.handler.codec.frame.FrameDecoder;
import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; 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.OneToOneDecoder;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
import com.google.protobuf.ExtensionRegistry; import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message; import com.google.protobuf.Message;
@ -53,15 +53,7 @@ import com.google.protobuf.Message;
* new {@link ProtobufDecoder}(MyMessage.getDefaultInstance())); * new {@link ProtobufDecoder}(MyMessage.getDefaultInstance()));
* *
* // Encoder * // Encoder
* pipeline.addLast("frameEncoder", * pipeline.addLast("frameEncoder", new {@link LengthFieldPrepender}(4));
* 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("protobufEncoder", new {@link ProtobufEncoder}()); * pipeline.addLast("protobufEncoder", new {@link ProtobufEncoder}());
* </pre> * </pre>
* and then you can use a {@code MyMessage} instead of a {@link ChannelBuffer} * and then you can use a {@code MyMessage} instead of a {@link ChannelBuffer}

View File

@ -30,6 +30,7 @@ import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelPipeline; import org.jboss.netty.channel.ChannelPipeline;
import org.jboss.netty.channel.ChannelPipelineCoverage; import org.jboss.netty.channel.ChannelPipelineCoverage;
import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; 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 org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
import com.google.protobuf.Message; import com.google.protobuf.Message;
@ -48,15 +49,7 @@ import com.google.protobuf.Message;
* new {@link ProtobufDecoder}(MyMessage.getDefaultInstance())); * new {@link ProtobufDecoder}(MyMessage.getDefaultInstance()));
* *
* // Encoder * // Encoder
* pipeline.addLast("frameEncoder", * pipeline.addLast("frameEncoder", new {@link LengthFieldPrepender}(4));
* 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("protobufEncoder", new {@link ProtobufEncoder}()); * pipeline.addLast("protobufEncoder", new {@link ProtobufEncoder}());
* </pre> * </pre>
* and then you can use a {@code MyMessage} instead of a {@link ChannelBuffer} * and then you can use a {@code MyMessage} instead of a {@link ChannelBuffer}