public static int scan(final UnsafeBuffer termBuffer, final int termOffset, final int limitOffset)
    {
        int offset = termOffset;

        while (offset < limitOffset)
        {
            final int frameLength = frameLengthVolatile(termBuffer, offset);
            if (frameLength <= 0)
            {
                break;
            }

            final int alignedFrameLength = align(frameLength, FRAME_ALIGNMENT);

            if (isPaddingFrame(termBuffer, offset))
            {
                if (termOffset == offset)
                {
                    offset += alignedFrameLength;
                }

                break;
            }

            if (offset + alignedFrameLength > limitOffset)
            {
                break;
            }

            offset += alignedFrameLength;
        }

        return offset;
    }
@Test
    void shouldReadFirstMessage()
    {
        final int offset = 0;
        final int limit = termBuffer.capacity();
        final int messageLength = 50;
        final int alignedMessageLength = BitUtil.align(messageLength, FRAME_ALIGNMENT);

        when(termBuffer.getIntVolatile(lengthOffset(offset))).thenReturn(messageLength);
        when(termBuffer.getShort(typeOffset(offset))).thenReturn((short)HDR_TYPE_DATA);

        final int newOffset = TermBlockScanner.scan(termBuffer, offset, limit);
        assertEquals(alignedMessageLength, newOffset);
    }