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:
ChannelHandler
,ChannelInboundHandler
,ChannelOutboundHandler
A Codec for on-the-fly encoding/decoding of bytes to messages and vise-versa.
This can be thought of as a combination of
}.
ByteToMessageDecoder
and MessageToByteEncoder
.
Be aware that sub-classes of ByteToMessageCodec
MUST NOT
annotated with
invalid @link
{@link @Sharable
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ByteToMessageDecoder
private final MessageToByteEncoder
<I> private final TypeParameterMatcher
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
seeByteToMessageCodec(boolean)
withtrue
as boolean parameter.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) seeByteToMessageCodec(Class, boolean)
withtrue
as boolean value.protected
ByteToMessageCodec
(Class<? extends I> outboundMessageType, boolean preferDirect) Create a new instance -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if and only if the specified message can be encoded by this codec.void
CallsChannelHandlerContext.fireChannelInactive()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
channelRead
(ChannelHandlerContext ctx, Object msg) CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
.void
CallsChannelHandlerContext.fireChannelReadComplete()
to forward to the nextChannelInboundHandler
in theChannelPipeline
.protected abstract void
decode
(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) protected void
decodeLast
(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) protected abstract void
encode
(ChannelHandlerContext ctx, I msg, ByteBuf out) void
Do nothing by default, sub-classes may override this method.void
Do nothing by default, sub-classes may override this method.void
write
(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) CallsChannelOutboundInvoker.write(Object, ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
.Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, read
Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
Methods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Field Details
-
outboundMsgMatcher
-
encoder
-
decoder
-
-
Constructor Details
-
ByteToMessageCodec
protected ByteToMessageCodec()seeByteToMessageCodec(boolean)
withtrue
as boolean parameter. -
ByteToMessageCodec
seeByteToMessageCodec(Class, boolean)
withtrue
as 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. -
ByteToMessageCodec
Create a new instance
-
-
Method Details
-
acceptOutboundMessage
Returnstrue
if and only if the specified message can be encoded by this codec.- Parameters:
msg
- the message- Throws:
Exception
-
channelRead
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelRead(Object)
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelRead
in interfaceChannelInboundHandler
- Overrides:
channelRead
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
write
Description copied from class:ChannelDuplexHandler
CallsChannelOutboundInvoker.write(Object, ChannelPromise)
to forward to the nextChannelOutboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
write
in interfaceChannelOutboundHandler
- Overrides:
write
in classChannelDuplexHandler
- Parameters:
ctx
- theChannelHandlerContext
for which the write operation is mademsg
- the message to writepromise
- theChannelPromise
to notify once the operation completes- Throws:
Exception
- thrown if an error occurs
-
channelReadComplete
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelReadComplete()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelReadComplete
in interfaceChannelInboundHandler
- Overrides:
channelReadComplete
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
channelInactive
Description copied from class:ChannelInboundHandlerAdapter
CallsChannelHandlerContext.fireChannelInactive()
to forward to the nextChannelInboundHandler
in theChannelPipeline
. Sub-classes may override this method to change behavior.- Specified by:
channelInactive
in interfaceChannelInboundHandler
- Overrides:
channelInactive
in classChannelInboundHandlerAdapter
- Throws:
Exception
-
handlerAdded
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerAdded
in interfaceChannelHandler
- Overrides:
handlerAdded
in classChannelHandlerAdapter
- Throws:
Exception
-
handlerRemoved
Description copied from class:ChannelHandlerAdapter
Do nothing by default, sub-classes may override this method.- Specified by:
handlerRemoved
in interfaceChannelHandler
- Overrides:
handlerRemoved
in classChannelHandlerAdapter
- Throws:
Exception
-
encode
- Throws:
Exception
- See Also:
-
decode
protected abstract void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception - Throws:
Exception
- See Also:
-
decodeLast
- Throws:
Exception
- See Also:
-