Package io.netty.handler.codec
Class ByteToMessageCodec<I>
- java.lang.Object
-
- io.netty.channel.ChannelHandlerAdapter
-
- io.netty.channel.ChannelInboundHandlerAdapter
-
- io.netty.channel.ChannelDuplexHandler
-
- io.netty.handler.codec.ByteToMessageCodec<I>
-
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler
public abstract class ByteToMessageCodec<I> extends io.netty.channel.ChannelDuplexHandlerA Codec for on-the-fly encoding/decoding of bytes to messages and vise-versa. This can be thought of as a combination ofByteToMessageDecoderandMessageToByteEncoder. Be aware that sub-classes ofByteToMessageCodecMUST NOT annotated with {@link @Sharable}.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedByteToMessageCodec()seeByteToMessageCodec(boolean)withtrueas boolean parameter.protectedByteToMessageCodec(boolean preferDirect)Create a new instance which will try to detect the types to match out of the type parameter of the class.protectedByteToMessageCodec(Class<? extends I> outboundMessageType)seeByteToMessageCodec(Class, boolean)withtrueas boolean value.protectedByteToMessageCodec(Class<? extends I> outboundMessageType, boolean preferDirect)Create a new instance
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanacceptOutboundMessage(Object msg)Returnstrueif and only if the specified message can be encoded by this codec.voidchannelInactive(io.netty.channel.ChannelHandlerContext ctx)voidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg)voidchannelReadComplete(io.netty.channel.ChannelHandlerContext ctx)protected abstract voiddecode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out)protected voiddecodeLast(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out)protected abstract voidencode(io.netty.channel.ChannelHandlerContext ctx, I msg, io.netty.buffer.ByteBuf out)voidhandlerAdded(io.netty.channel.ChannelHandlerContext ctx)voidhandlerRemoved(io.netty.channel.ChannelHandlerContext ctx)voidwrite(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)-
Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read
-
-
-
-
Constructor Detail
-
ByteToMessageCodec
protected ByteToMessageCodec()
seeByteToMessageCodec(boolean)withtrueas boolean parameter.
-
ByteToMessageCodec
protected ByteToMessageCodec(Class<? extends I> outboundMessageType)
seeByteToMessageCodec(Class, boolean)withtrueas boolean value.
-
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.- Parameters:
preferDirect-trueif a directByteBufshould be tried to be used as target for the encoded messages. Iffalseis used it will allocate a heapByteBuf, which is backed by an byte array.
-
ByteToMessageCodec
protected ByteToMessageCodec(Class<? extends I> outboundMessageType, boolean preferDirect)
Create a new instance- Parameters:
outboundMessageType- The type of messages to matchpreferDirect-trueif a directByteBufshould be tried to be used as target for the encoded messages. Iffalseis used it will allocate a heapByteBuf, which is backed by an byte array.
-
-
Method Detail
-
acceptOutboundMessage
public boolean acceptOutboundMessage(Object msg) throws Exception
Returnstrueif and only if the specified message can be encoded by this codec.- Parameters:
msg- the message- Throws:
Exception
-
channelRead
public void channelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) throws Exception- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception- Specified by:
writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
writein classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-
channelReadComplete
public void channelReadComplete(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelReadCompletein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadCompletein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
channelInactive
public void channelInactive(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
channelInactivein interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelInactivein classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
handlerAdded
public void handlerAdded(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerAddedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerAddedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
handlerRemoved
public void handlerRemoved(io.netty.channel.ChannelHandlerContext ctx) throws Exception- Specified by:
handlerRemovedin interfaceio.netty.channel.ChannelHandler- Overrides:
handlerRemovedin classio.netty.channel.ChannelHandlerAdapter- Throws:
Exception
-
encode
protected abstract void encode(io.netty.channel.ChannelHandlerContext ctx, I msg, io.netty.buffer.ByteBuf out) throws Exception- Throws:
Exception- See Also:
MessageToByteEncoder.encode(ChannelHandlerContext, Object, ByteBuf)
-
decode
protected abstract void decode(io.netty.channel.ChannelHandlerContext ctx, io.netty.buffer.ByteBuf in, List<Object> out) throws Exception- Throws:
Exception- See Also:
ByteToMessageDecoder.decode(ChannelHandlerContext, ByteBuf, List)
-
-