Top Description Inners Fields Constructors Methods
io.netty5.handler.codec

public abstract Class ByteToMessageCodec<I>

extends ChannelHandlerAdapter
Class Inheritance
Imports
io.netty5.buffer.Buffer, .BufferAllocator, io.netty5.channel.ChannelHandlerAdapter, .ChannelHandlerContext, io.netty5.util.concurrent.Future, io.netty5.util.internal.TypeParameterMatcher

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 @Sharable.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private final ByteToMessageDecoder
private final MessageToByteEncoder<I>
private final TypeParameterMatcher

Constructor Summary

AccessConstructor and Description
protected
ByteToMessageCodec()

see ByteToMessageCodec(BufferAllocator) with true as boolean parameter.

protected
ByteToMessageCodec(Class<? extends I> outboundMessageType)

see ByteToMessageCodec(Class, BufferAllocator) with true as boolean value.

protected
ByteToMessageCodec(BufferAllocator
The allocator to use for allocating buffers. If null, the channel context allocator will be used.
allocator
)

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>
The type of messages to match.
outboundMessageType
,
BufferAllocator
The allocator to use for allocating buffers. If null, the channel context allocator will be used.
allocator
)

Create a new instance

Method Summary

Modifier and TypeMethod and Description
public boolean
acceptOutboundMessage(Object
the message
msg
)

Returns true if and only if the specified message can be encoded by this codec.

public void
channelInactive(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.
public void
channelRead(ChannelHandlerContext ctx, Object msg)

Overrides default io.netty5.channel.ChannelHandler.channelRead.

Invoked when the current Channel has read a message from the peer.
public void
channelReadComplete(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.channelReadComplete.

Invoked when the last message read by the current read operation has been consumed by channelRead(ChannelHandlerContext, Object).
protected abstract void
protected void
protected abstract void
public void
handlerAdded(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.
public void
handlerRemoved(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.
public final boolean
isSharable()

Overrides default io.netty5.channel.ChannelHandler.isSharable.

Returns true if this handler is sharable and thus can be added to more than one ChannelPipeline.
public Future<Void>
write(ChannelHandlerContext
the ChannelHandlerContext for which the write operation is made
ctx
,
Object
the message to write
msg
)

Overrides default io.netty5.channel.ChannelHandler.write.

Called once a write operation is made.

Field Detail

decoderback to summary
private final ByteToMessageDecoder decoder
encoderback to summary
private final MessageToByteEncoder<I> encoder
outboundMsgMatcherback to summary
private final TypeParameterMatcher outboundMsgMatcher

Constructor Detail

ByteToMessageCodecback to summary
protected ByteToMessageCodec()

see ByteToMessageCodec(BufferAllocator) with true as boolean parameter.

ByteToMessageCodecback to summary
protected ByteToMessageCodec(Class<? extends I> outboundMessageType)

see ByteToMessageCodec(Class, BufferAllocator) with true as boolean value.

ByteToMessageCodecback to summary
protected ByteToMessageCodec(BufferAllocator allocator)

Create a new instance which will try to detect the types to match out of the type parameter of the class.

Parameters
allocator:BufferAllocator

The allocator to use for allocating buffers. If null, the channel context allocator will be used.

ByteToMessageCodecback to summary
protected ByteToMessageCodec(Class<? extends I> outboundMessageType, BufferAllocator allocator)

Create a new instance

Parameters
outboundMessageType:Class<? extends I>

The type of messages to match.

allocator:BufferAllocator

The allocator to use for allocating buffers. If null, the channel context allocator will be used.

Method Detail

acceptOutboundMessageback to summary
public boolean acceptOutboundMessage(Object msg) throws Exception

Returns true if and only if the specified message can be encoded by this codec.

Parameters
msg:Object

the message

channelInactiveback to summary
public void channelInactive(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelInactive.

Doc from io.netty5.channel.ChannelHandler.channelInactive.

The Channel of the ChannelHandlerContext was registered is now inactive and reached its end of lifetime.

Annotations
@Override
channelReadback to summary
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelRead.

Doc from io.netty5.channel.ChannelHandler.channelRead.

Invoked when the current Channel has read a message from the peer.

Annotations
@Override
channelReadCompleteback to summary
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.channelReadComplete.

Doc from io.netty5.channel.ChannelHandler.channelReadComplete.

Invoked when the last message read by the current read operation has been consumed by channelRead(ChannelHandlerContext, Object). If ChannelOption#AUTO_READ is off, no further attempt to read an inbound data from the current Channel will be made until ChannelOutboundInvoker#read(ReadBufferAllocator) is called.

Annotations
@Override
decodeback to summary
protected abstract void decode(ChannelHandlerContext ctx, Buffer in) throws Exception
See Also
ByteToMessageDecoder#decode(ChannelHandlerContext, Buffer)
decodeLastback to summary
protected void decodeLast(ChannelHandlerContext ctx, Buffer in) throws Exception
See Also
ByteToMessageDecoder#decodeLast(ChannelHandlerContext, Buffer)
encodeback to summary
protected abstract void encode(ChannelHandlerContext ctx, I msg, Buffer out) throws Exception
See Also
MessageToByteEncoder#encode(ChannelHandlerContext, Object, Buffer)
handlerAddedback to summary
public void handlerAdded(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.handlerAdded.

Doc from io.netty5.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Annotations
@Override
handlerRemovedback to summary
public void handlerRemoved(ChannelHandlerContext ctx) throws Exception

Overrides default io.netty5.channel.ChannelHandler.handlerRemoved.

Doc from io.netty5.channel.ChannelHandler.handlerRemoved.

Gets called after the ChannelHandler was removed from the actual context and it doesn't handle events anymore.

Annotations
@Override
isSharableback to summary
public final boolean isSharable()

Overrides default io.netty5.channel.ChannelHandler.isSharable.

Doc from io.netty5.channel.ChannelHandler.isSharable.

Returns true if this handler is sharable and thus can be added to more than one ChannelPipeline. By default, this method returns false. If this method returns false, you have to create a new handler instance every time you add it to a pipeline because it has unshared state such as member variables.

Annotations
@Override
writeback to summary
public Future<Void> write(ChannelHandlerContext ctx, Object msg)

Overrides default io.netty5.channel.ChannelHandler.write.

Doc from io.netty5.channel.ChannelHandler.write.

Called once a write operation is made. The write operation will write the messages through the ChannelPipeline. Those are then ready to be flushed to the actual Channel once Channel#flush() is called.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext for which the write operation is made

msg:Object

the message to write

Returns:Future<Void>

the Future which will be notified once the operation completes.

Annotations
@Override
io.netty5.handler.codec back to summary

private final Class ByteToMessageCodec.Encoder

extends MessageToByteEncoder<I>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final BufferAllocator

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public boolean
acceptOutboundMessage(Object msg)

Overrides io.netty5.handler.codec.MessageToByteEncoder.acceptOutboundMessage.

Returns true if the given message should be handled.
protected Buffer
allocateBuffer(ChannelHandlerContext ctx, I
the message to be encoded
msg
)

Implements abstract io.netty5.handler.codec.MessageToByteEncoder.allocateBuffer.

Allocate a Buffer which will be used as argument of encode(ChannelHandlerContext, I, Buffer).
protected void
encode(ChannelHandlerContext ctx, I
the message to encode
msg
,
Buffer
the Buffer into which the encoded message will be written
out
)

Implements abstract io.netty5.handler.codec.MessageToByteEncoder.encode.

Encode a message into a Buffer.
Inherited from io.netty5.handler.codec.MessageToByteEncoder:
write

Field Detail

allocatorback to summary
private final BufferAllocator allocator

Constructor Detail

Encoderback to summary
pack-priv Encoder(BufferAllocator allocator)

Method Detail

acceptOutboundMessageback to summary
public boolean acceptOutboundMessage(Object msg) throws Exception

Overrides io.netty5.handler.codec.MessageToByteEncoder.acceptOutboundMessage.

Doc from io.netty5.handler.codec.MessageToByteEncoder.acceptOutboundMessage.

Returns true if the given message should be handled. If false it will be passed to the next ChannelHandler in the ChannelPipeline.

Annotations
@Override
allocateBufferback to summary
protected Buffer allocateBuffer(ChannelHandlerContext ctx, I msg) throws Exception

Implements abstract io.netty5.handler.codec.MessageToByteEncoder.allocateBuffer.

Doc from io.netty5.handler.codec.MessageToByteEncoder.allocateBuffer.

Allocate a Buffer which will be used as argument of encode(ChannelHandlerContext, I, Buffer).

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToByteEncoder belongs to

msg:I

the message to be encoded

Annotations
@Override
encodeback to summary
protected void encode(ChannelHandlerContext ctx, I msg, Buffer out) throws Exception

Implements abstract io.netty5.handler.codec.MessageToByteEncoder.encode.

Doc from io.netty5.handler.codec.MessageToByteEncoder.encode.

Encode a message into a Buffer. This method will be called for each written message that can be handled by this encoder.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToByteEncoder belongs to

msg:I

the message to encode

out:Buffer

the Buffer into which the encoded message will be written

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs