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

public Class DelimiterBasedFrameDecoder

extends ByteToMessageDecoder
Class Inheritance
Imports
io.netty5.buffer.Buffer, io.netty5.channel.ChannelHandlerContext

A decoder that splits the received Buffers by one or more delimiters. It is particularly useful for decoding the frames which ends with a delimiter such as NUL or newline characters.

Predefined delimiters

Delimiters defines frequently used delimiters for convenience' sake.

Specifying more than one delimiter

DelimiterBasedFrameDecoder allows you to specify more than one delimiter. If more than one delimiter is found in the buffer, it chooses the delimiter which produces the shortest frame. For example, if you have the following data in the buffer:

+--------------+
| ABC\nDEF\r\n |
+--------------+
a DelimiterBasedFrameDecoder(Delimiters.lineDelimiter()) will choose '\n' as the first delimiter and produce two frames:
+-----+-----+
| ABC | DEF |
+-----+-----+
rather than incorrectly choosing '\r\n' as the first delimiter:
+----------+
| ABC\nDEF |
+----------+

Field Summary

Modifier and TypeField and Description
private final Buffer[]
private boolean
private final boolean
private final LineBasedFrameDecoder
lineBasedDecoder

Set only when decoding with "\n" and "\r\n" as the delimiter.

private final int
private final boolean
private int
Inherited from io.netty5.handler.codec.ByteToMessageDecoder:
COMPOSITE_CUMULATORMERGE_CUMULATOR

Constructor Summary

AccessConstructor and Description
public
DelimiterBasedFrameDecoder(int
the maximum length of the decoded frame. A TooLongFrameException is thrown if the length of the frame exceeds this value.
maxFrameLength
,
Buffer...
the delimiters
delimiters
)

Creates a new instance.

public
DelimiterBasedFrameDecoder(int
the maximum length of the decoded frame. A TooLongFrameException is thrown if the length of the frame exceeds this value.
maxFrameLength
,
boolean
whether the decoded frame should strip out the delimiter or not
stripDelimiter
,
Buffer...
the delimiters
delimiters
)

Creates a new instance.

public
DelimiterBasedFrameDecoder(int
the maximum length of the decoded frame. A TooLongFrameException is thrown if the length of the frame exceeds this value.
maxFrameLength
,
boolean
whether the decoded frame should strip out the delimiter or not
stripDelimiter
,
boolean
If true, a TooLongFrameException is thrown as soon as the decoder notices the length of the frame will exceed maxFrameLength regardless of whether the entire frame has been read. If false, a TooLongFrameException is thrown after the entire frame that exceeds maxFrameLength has been read.
failFast
,
Buffer...
the delimiters
delimiters
)

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
private static void
closeDelimiters(Buffer[] delimiters)

protected final void
decode(ChannelHandlerContext ctx, Buffer
the Buffer from which to read data
in
)

Implements abstract io.netty5.handler.codec.ByteToMessageDecoder.decode.

Decode the from one Buffer to another.
protected Object

Returns:

frame the Buffer which represent the frame or null if no frame could be created.
decode0
(ChannelHandlerContext ctx, Buffer
the Buffer from which to read data
buffer
)

Create a frame out of the Buffer and return it.

private void
fail(long frameLength)

protected void
handlerRemoved0(ChannelHandlerContext ctx)

Overrides io.netty5.handler.codec.ByteToMessageDecoder.handlerRemoved0.

Gets called after the ByteToMessageDecoder was removed from the actual context and it doesn't handle events anymore.
private static int
indexOf(Buffer haystack, Buffer needle)

Returns the number of bytes between the readerIndex of the haystack and the first needle found in the haystack.

private static boolean
isLineBased(final Buffer[] delimiters)

Returns true if the delimiters are "\n" and "\r\n".

private boolean
isSubclass()

Return true if the current instance is a subclass of DelimiterBasedFrameDecoder

private static void
private static void
validateMaxFrameLength(int maxFrameLength)

Inherited from io.netty5.handler.codec.ByteToMessageDecoder:
actualReadableBytescallDecodechannelInactivechannelInputClosedchannelReadchannelReadCompletechannelShutdowndecodeLastdecodeRemovalReentryProtectiondiscardSomeReadByteshandlerAddedhandlerAdded0handlerRemovedinternalBufferisSharableisSingleDecodesetSingleDecode

Field Detail

delimitersback to summary
private final Buffer[] delimiters
discardingTooLongFrameback to summary
private boolean discardingTooLongFrame
failFastback to summary
private final boolean failFast
lineBasedDecoderback to summary
private final LineBasedFrameDecoder lineBasedDecoder

Set only when decoding with "\n" and "\r\n" as the delimiter.

maxFrameLengthback to summary
private final int maxFrameLength
stripDelimiterback to summary
private final boolean stripDelimiter
tooLongFrameLengthback to summary
private int tooLongFrameLength

Constructor Detail

DelimiterBasedFrameDecoderback to summary
public DelimiterBasedFrameDecoder(int maxFrameLength, Buffer... delimiters)

Creates a new instance.

Parameters
maxFrameLength:int

the maximum length of the decoded frame. A TooLongFrameException is thrown if the length of the frame exceeds this value.

delimiters:Buffer[]

the delimiters

DelimiterBasedFrameDecoderback to summary
public DelimiterBasedFrameDecoder(int maxFrameLength, boolean stripDelimiter, Buffer... delimiters)

Creates a new instance.

Parameters
maxFrameLength:int

the maximum length of the decoded frame. A TooLongFrameException is thrown if the length of the frame exceeds this value.

stripDelimiter:boolean

whether the decoded frame should strip out the delimiter or not

delimiters:Buffer[]

the delimiters

DelimiterBasedFrameDecoderback to summary
public DelimiterBasedFrameDecoder(int maxFrameLength, boolean stripDelimiter, boolean failFast, Buffer... delimiters)

Creates a new instance.

Parameters
maxFrameLength:int

the maximum length of the decoded frame. A TooLongFrameException is thrown if the length of the frame exceeds this value.

stripDelimiter:boolean

whether the decoded frame should strip out the delimiter or not

failFast:boolean

If true, a TooLongFrameException is thrown as soon as the decoder notices the length of the frame will exceed maxFrameLength regardless of whether the entire frame has been read. If false, a TooLongFrameException is thrown after the entire frame that exceeds maxFrameLength has been read.

delimiters:Buffer[]

the delimiters

Method Detail

closeDelimitersback to summary
private static void closeDelimiters(Buffer[] delimiters)
decodeback to summary
protected final void decode(ChannelHandlerContext ctx, Buffer in) throws Exception

Implements abstract io.netty5.handler.codec.ByteToMessageDecoder.decode.

Doc from io.netty5.handler.codec.ByteToMessageDecoder.decode.

Decode the from one Buffer to another. This method will be called till either the input Buffer has nothing to read when return from this method or till nothing was read from the input Buffer.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this ByteToMessageDecoder belongs to

in:Buffer

the Buffer from which to read data

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
decode0back to summary
protected Object decode0(ChannelHandlerContext ctx, Buffer buffer)

Create a frame out of the Buffer and return it.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this ByteToMessageDecoder belongs to

buffer:Buffer

the Buffer from which to read data

Returns:Object

frame the Buffer which represent the frame or null if no frame could be created.

failback to summary
private void fail(long frameLength)
handlerRemoved0back to summary
protected void handlerRemoved0(ChannelHandlerContext ctx) throws Exception

Overrides io.netty5.handler.codec.ByteToMessageDecoder.handlerRemoved0.

Doc from io.netty5.handler.codec.ByteToMessageDecoder.handlerRemoved0.

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

Annotations
@Override
indexOfback to summary
private static int indexOf(Buffer haystack, Buffer needle)

Returns the number of bytes between the readerIndex of the haystack and the first needle found in the haystack. -1 is returned if no needle is found in the haystack.

isLineBasedback to summary
private static boolean isLineBased(final Buffer[] delimiters)

Returns true if the delimiters are "\n" and "\r\n".

isSubclassback to summary
private boolean isSubclass()

Return true if the current instance is a subclass of DelimiterBasedFrameDecoder

validateDelimiterback to summary
private static void validateDelimiter(Buffer delimiter)
validateMaxFrameLengthback to summary
private static void validateMaxFrameLength(int maxFrameLength)