diff --git a/src/main/java/org/jboss/netty/handler/codec/oneone/OneToOneDecoder.java b/src/main/java/org/jboss/netty/handler/codec/oneone/OneToOneDecoder.java index b3769d9b78..3a1b8bc8f1 100644 --- a/src/main/java/org/jboss/netty/handler/codec/oneone/OneToOneDecoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/oneone/OneToOneDecoder.java @@ -72,11 +72,16 @@ public abstract class OneToOneDecoder implements ChannelUpstreamHandler { Object decodedMessage = decode(ctx, e.getChannel(), originalMessage); if (originalMessage == decodedMessage) { ctx.sendUpstream(evt); - } else { + } else if (decodedMessage != null) { fireMessageReceived(ctx, decodedMessage, e.getRemoteAddress()); } } + /** + * Transforms the specified received message into another message and return + * the transformed message. Return {@code null} if the received message + * is supposed to be discarded. + */ protected abstract Object decode( ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception; } diff --git a/src/main/java/org/jboss/netty/handler/codec/oneone/OneToOneEncoder.java b/src/main/java/org/jboss/netty/handler/codec/oneone/OneToOneEncoder.java index f1f1cac829..b7652746da 100644 --- a/src/main/java/org/jboss/netty/handler/codec/oneone/OneToOneEncoder.java +++ b/src/main/java/org/jboss/netty/handler/codec/oneone/OneToOneEncoder.java @@ -17,6 +17,7 @@ package org.jboss.netty.handler.codec.oneone; import static org.jboss.netty.channel.Channels.*; +import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelDownstreamHandler; import org.jboss.netty.channel.ChannelEvent; @@ -27,7 +28,7 @@ import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; import org.jboss.netty.handler.codec.frame.Delimiters; /** - * Transforms a received message into another message. A typical setup for + * Transforms a write request into another write request. A typical setup for * TCP/IP would be: *
  * {@link ChannelPipeline} pipeline = ...;
@@ -70,6 +71,12 @@ public abstract class OneToOneEncoder implements ChannelDownstreamHandler {
         }
     }
 
+    /**
+     * Transforms the specified message into another message and return the
+     * transformed message.  Note that you can not return {@code null}, unlike
+     * you can in {@link OneToOneDecoder#decode(ChannelHandlerContext, Channel, Object)};
+     * you must return something, at least {@link ChannelBuffers#EMPTY_BUFFER}.
+     */
     protected abstract Object encode(
             ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception;
 }