@Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception {
        final int frameSizeValueLength = findFrameSizeValueLength(buffer);

        // We have not found the frame length value byte size yet.
        if (frameSizeValueLength <= 0) {
            return;
        }

        // Convert the frame length value bytes into an integer without mutating the buffer reader index.
        final String lengthString = buffer.slice(buffer.readerIndex(), frameSizeValueLength).toString(StandardCharsets.UTF_8);
        final int length = Integer.parseInt(lengthString);
        final int skipLength = frameSizeValueLength + 1; // Frame length value bytes and the whitespace that follows it.

        // We have to take the skipped bytes (frame size value length + whitespace) into account when checking if
        // the buffer has enough data to read the complete message.
        if (buffer.readableBytes() - skipLength < length) {
            // We cannot read the complete frame yet.
            return;
        } else {
            // Skip the frame length value bytes and the whitespace that follows it.
            buffer.skipBytes(skipLength);
        }

        final ByteBuf frame = buffer.readRetainedSlice(length);
        out.add(frame);
    }
@Test
    public void testDecode() throws Exception {
        final ByteBuf buf1 = Unpooled.copiedBuffer("123 <45>1 2014-10-21T10:21:09+00:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"1\"] syslog-ng starting up; version='3.5.3'\n", StandardCharsets.US_ASCII);
        final ByteBuf buf2 = Unpooled.copiedBuffer("186 <45>1 2014-10-21T10:21:09+00:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"2\"] Syslog connection established; fd='9', server='AF_INET(172.17.42.1:6666)', local='AF_INET(0.0.0.0:0)'\n", StandardCharsets.US_ASCII);
        final ByteBuf buf3 = Unpooled.copiedBuffer(buf1, buf2, buf1);

        assertTrue(channel.writeInbound(buf1, buf2, buf3));

        final ByteBuf actual1 = channel.readInbound();
        assertEquals("<45>1 2014-10-21T10:21:09+00:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"1\"] syslog-ng starting up; version='3.5.3'\n", actual1.toString(StandardCharsets.US_ASCII));
        final ByteBuf actual2 = channel.readInbound();
        assertEquals("<45>1 2014-10-21T10:21:09+00:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"2\"] Syslog connection established; fd='9', server='AF_INET(172.17.42.1:6666)', local='AF_INET(0.0.0.0:0)'\n", actual2.toString(StandardCharsets.US_ASCII));

        final ByteBuf actual3 = channel.readInbound();
        assertEquals("<45>1 2014-10-21T10:21:09+00:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"1\"] syslog-ng starting up; version='3.5.3'\n", actual3.toString(StandardCharsets.US_ASCII));
        final ByteBuf actual4 = channel.readInbound();
        assertEquals("<45>1 2014-10-21T10:21:09+00:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"2\"] Syslog connection established; fd='9', server='AF_INET(172.17.42.1:6666)', local='AF_INET(0.0.0.0:0)'\n", actual4.toString(StandardCharsets.US_ASCII));
        final ByteBuf actual5 = channel.readInbound();
        assertEquals("<45>1 2014-10-21T10:21:09+00:00 c4dc57ba1ebb syslog-ng 7120 - [meta sequenceId=\"1\"] syslog-ng starting up; version='3.5.3'\n", actual5.toString(StandardCharsets.US_ASCII));

        assertNull(channel.readInbound());
    }