public abstract class MessageToMessageCodec<INBOUND_IN,OUTBOUND_IN>
extends io.netty.channel.ChannelDuplexHandler
implements io.netty.channel.ChannelInboundMessageHandler<INBOUND_IN>, io.netty.channel.ChannelOutboundMessageHandler<OUTBOUND_IN>
MessageToMessageDecoder and MessageToMessageEncoder.
Here is an example of a MessageToMessageCodec which just decode from Integer to Long
and encode from Long to Integer.
public class NumberCodec extends
MessageToMessageCodec<Integer, Long, Long, Integer> {
@Override
public Long decode(ChannelHandlerContext ctx, Integer msg)
throws Exception {
return msg.longValue();
}
@Overrride
public Integer encode(ChannelHandlerContext ctx, Long msg)
throws Exception {
return msg.intValue();
}
}
| Modifier | Constructor and Description |
|---|---|
protected |
MessageToMessageCodec() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptInboundMessage(Object msg)
Returns
true if and only if the specified message can be decoded by this codec. |
boolean |
acceptOutboundMessage(Object msg)
Returns
true if and only if the specified message can be encoded by this codec. |
protected abstract Object |
decode(io.netty.channel.ChannelHandlerContext ctx,
INBOUND_IN msg) |
protected abstract Object |
encode(io.netty.channel.ChannelHandlerContext ctx,
OUTBOUND_IN msg) |
void |
flush(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise future) |
void |
freeInboundBuffer(io.netty.channel.ChannelHandlerContext ctx) |
void |
freeOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx) |
void |
inboundBufferUpdated(io.netty.channel.ChannelHandlerContext ctx) |
io.netty.buffer.MessageBuf<INBOUND_IN> |
newInboundBuffer(io.netty.channel.ChannelHandlerContext ctx) |
io.netty.buffer.MessageBuf<OUTBOUND_IN> |
newOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx) |
bind, close, connect, deregister, disconnect, read, sendFilechannelActive, channelInactive, channelReadSuspended, channelRegistered, channelUnregisteredafterAdd, afterRemove, beforeAdd, beforeRemove, exceptionCaught, userEventTriggeredclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitchannelActive, channelInactive, channelReadSuspended, channelRegistered, channelUnregisteredpublic io.netty.buffer.MessageBuf<INBOUND_IN> newInboundBuffer(io.netty.channel.ChannelHandlerContext ctx) throws Exception
newInboundBuffer in interface io.netty.channel.ChannelInboundMessageHandler<INBOUND_IN>Exceptionpublic void freeInboundBuffer(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
Exceptionpublic io.netty.buffer.MessageBuf<OUTBOUND_IN> newOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx) throws Exception
newOutboundBuffer in interface io.netty.channel.ChannelOutboundMessageHandler<OUTBOUND_IN>Exceptionpublic void freeOutboundBuffer(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
Exceptionpublic void inboundBufferUpdated(io.netty.channel.ChannelHandlerContext ctx)
throws Exception
inboundBufferUpdated in interface io.netty.channel.ChannelStateHandlerExceptionpublic void flush(io.netty.channel.ChannelHandlerContext ctx,
io.netty.channel.ChannelPromise future)
throws Exception
flush in interface io.netty.channel.ChannelOperationHandlerExceptionpublic boolean acceptInboundMessage(Object msg) throws Exception
true if and only if the specified message can be decoded by this codec.msg - the messageExceptionpublic boolean acceptOutboundMessage(Object msg) throws Exception
true if and only if the specified message can be encoded by this codec.msg - the messageExceptionprotected abstract Object encode(io.netty.channel.ChannelHandlerContext ctx, OUTBOUND_IN msg) throws Exception
Exceptionprotected abstract Object decode(io.netty.channel.ChannelHandlerContext ctx, INBOUND_IN msg) throws Exception
ExceptionCopyright © 2008-2013 The Netty Project. All Rights Reserved.