static int encode(
        final UnsafeBuffer encodingBuffer,
        final int offset,
        final int captureLength,
        final int length,
        final DirectBuffer srcBuffer,
        final int srcOffset)
    {
        final int encodedLength = encodeLogHeader(encodingBuffer, offset, captureLength, length);
        encodingBuffer.putBytes(offset + encodedLength, srcBuffer, srcOffset, captureLength);
        return encodedLength + captureLength;
    }
@Test
    void encodeBufferBuggerThanMaxCaptureSize()
    {
        final UnsafeBuffer srcBuffer = new UnsafeBuffer(new byte[MAX_EVENT_LENGTH * 2]);
        final int offset = 256;
        final int srcOffset = 20;
        final int length = MAX_EVENT_LENGTH + 1000;
        srcBuffer.setMemory(srcOffset, length, (byte)-5);

        final int encodedLength = encode(buffer, offset, MAX_CAPTURE_LENGTH, length, srcBuffer, srcOffset);

        assertEquals(MAX_EVENT_LENGTH, encodedLength);
        assertEquals(MAX_CAPTURE_LENGTH, buffer.getInt(offset, LITTLE_ENDIAN));
        assertEquals(length, buffer.getInt(offset + SIZE_OF_INT, LITTLE_ENDIAN));
        assertNotEquals(0, buffer.getLong(offset + SIZE_OF_INT * 2, LITTLE_ENDIAN));
        for (int i = 0; i < MAX_CAPTURE_LENGTH; i++)
        {
            assertEquals(-5, buffer.getByte(offset + LOG_HEADER_LENGTH + i));
        }
    }