Fixed wrong encoder setup in protobuf javadoc
This commit is contained in:
parent
c9551fea14
commit
8e94c0cd60
@ -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}
|
||||
|
@ -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}
|
||||
|
Loading…
Reference in New Issue
Block a user