Class FixedLengthFrameDecoder

  • All Implemented Interfaces:
    io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler

    public class FixedLengthFrameDecoder
    extends ByteToMessageDecoder
    A decoder that splits the received ByteBufs by the fixed number of bytes. For example, if you received the following four fragmented packets:
     +---+----+------+----+
     | A | BC | DEFG | HI |
     +---+----+------+----+
     
    A FixedLengthFrameDecoder(3) will decode them into the following three packets with the fixed length:
     +-----+-----+-----+
     | ABC | DEF | GHI |
     +-----+-----+-----+
     
    • Constructor Detail

      • FixedLengthFrameDecoder

        public FixedLengthFrameDecoder​(int frameLength)
        Creates a new instance.
        Parameters:
        frameLength - the length of the frame
    • Method Detail

      • decode

        protected final void decode​(io.netty.channel.ChannelHandlerContext ctx,
                                    io.netty.buffer.ByteBuf in,
                                    List<Object> out)
                             throws Exception
        Description copied from class: ByteToMessageDecoder
        Decode the from one ByteBuf to an other. This method will be called till either the input ByteBuf has nothing to read when return from this method or till nothing was read from the input ByteBuf.
        Specified by:
        decode in class ByteToMessageDecoder
        Parameters:
        ctx - the ChannelHandlerContext which this ByteToMessageDecoder belongs to
        in - the ByteBuf from which to read data
        out - the List to which decoded messages should be added
        Throws:
        Exception - is thrown if an error occurs
      • decode

        protected Object decode​(io.netty.channel.ChannelHandlerContext ctx,
                                io.netty.buffer.ByteBuf in)
                         throws Exception
        Create a frame out of the ByteBuf and return it.
        Parameters:
        ctx - the ChannelHandlerContext which this ByteToMessageDecoder belongs to
        in - the ByteBuf from which to read data
        Returns:
        frame the ByteBuf which represent the frame or null if no frame could be created.
        Throws:
        Exception