Fixed wrong encoder setup in protobuf javadoc

This commit is contained in:
Trustin Lee 2009-01-07 01:48:49 +00:00
parent c9551fea14
commit 8e94c0cd60
2 changed files with 19 additions and 0 deletions

View File

@ -31,6 +31,7 @@ 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.oneone.OneToOneDecoder;
import org.jboss.netty.handler.codec.oneone.OneToOneEncoder;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
@ -52,6 +53,15 @@ 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("protobufEncoder", new {@link ProtobufEncoder}());
* </pre>
* and then you can use a {@code MyMessage} instead of a {@link ChannelBuffer}

View File

@ -48,6 +48,15 @@ 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("protobufEncoder", new {@link ProtobufEncoder}());
* </pre>
* and then you can use a {@code MyMessage} instead of a {@link ChannelBuffer}