public abstract class ByteToMessageCodec<I>
extends io.netty.channel.ChannelDuplexHandler
ByteToMessageDecoder
and MessageToByteEncoder
.
Be aware that sub-classes of ByteToMessageCodec
MUST NOT
annotated with @Sharable
.Modifier | Constructor and Description |
---|---|
protected |
ByteToMessageCodec() |
protected |
ByteToMessageCodec(boolean preferDirect)
Create a new instance which will try to detect the types to match out of the type parameter of the class.
|
protected |
ByteToMessageCodec(Class<? extends I> outboundMessageType) |
protected |
ByteToMessageCodec(Class<? extends I> outboundMessageType,
boolean preferDirect)
Create a new instance
|
Modifier and Type | Method and Description |
---|---|
boolean |
acceptOutboundMessage(Object msg)
Returns
true if and only if the specified message can be encoded by this codec. |
void |
channelRead(io.netty.channel.ChannelHandlerContext ctx,
Object msg) |
protected abstract void |
decode(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
List<Object> out) |
protected void |
decodeLast(io.netty.channel.ChannelHandlerContext ctx,
io.netty.buffer.ByteBuf in,
List<Object> out) |
protected abstract void |
encode(io.netty.channel.ChannelHandlerContext ctx,
I msg,
io.netty.buffer.ByteBuf out) |
void |
write(io.netty.channel.ChannelHandlerContext ctx,
Object msg,
io.netty.channel.ChannelPromise promise) |
bind, close, connect, deregister, disconnect, flush, read
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
handlerAdded, handlerRemoved, isSharable
protected ByteToMessageCodec()
#ByteToMessageCodec(boolean)} with {@code true} as boolean parameter.
protected ByteToMessageCodec(Class<? extends I> outboundMessageType)
#ByteToMessageCodec(Class, boolean)} with {@code true} as boolean value.
protected ByteToMessageCodec(boolean preferDirect)
preferDirect
- true
if a direct ByteBuf
should be tried to be used as target for
the encoded messages. If false
is used it will allocate a heap
ByteBuf
, which is backed by an byte array.protected ByteToMessageCodec(Class<? extends I> outboundMessageType, boolean preferDirect)
outboundMessageType
- The type of messages to matchpreferDirect
- true
if a direct ByteBuf
should be tried to be used as target for
the encoded messages. If false
is used it will allocate a heap
ByteBuf
, which is backed by an byte array.public boolean acceptOutboundMessage(Object msg) throws Exception
true
if and only if the specified message can be encoded by this codec.msg
- the messageException
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception
channelRead
in interface io.netty.channel.ChannelInboundHandler
channelRead
in class io.netty.channel.ChannelInboundHandlerAdapter
Exception
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception
write
in interface io.netty.channel.ChannelOutboundHandler
write
in class io.netty.channel.ChannelDuplexHandler
Exception
protected abstract void encode(io.netty.channel.ChannelHandlerContext ctx, I msg, io.netty.buffer.ByteBuf out) throws Exception
protected abstract void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out) throws Exception
Copyright © 2008–2014 The Netty Project. All rights reserved.