From 8e94c0cd604053168e17bb1d7a5059a5b9e04c7d Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Wed, 7 Jan 2009 01:48:49 +0000 Subject: [PATCH] Fixed wrong encoder setup in protobuf javadoc --- .../netty/handler/codec/protobuf/ProtobufDecoder.java | 10 ++++++++++ .../netty/handler/codec/protobuf/ProtobufEncoder.java | 9 +++++++++ 2 files changed, 19 insertions(+) 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 21aa5de119..534848abd3 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 @@ -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}()); * * 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 61dc6ab407..4c0663ff0a 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 @@ -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}()); * * and then you can use a {@code MyMessage} instead of a {@link ChannelBuffer}