static int internalEncodeLogHeader(
        final MutableDirectBuffer encodingBuffer,
        final int offset,
        final int captureLength,
        final int length,
        final NanoClock nanoClock)
    {
        if (captureLength < 0 || captureLength > length || captureLength > MAX_CAPTURE_LENGTH)
        {
            throw new IllegalArgumentException("invalid input: captureLength=" + captureLength + ", length=" + length);
        }

        int encodedLength = 0;
        /*
         * Stream of values:
         * - capture buffer length (int)
         * - total buffer length (int)
         * - timestamp (long)
         * - buffer (until end)
         */

        encodingBuffer.putInt(offset + encodedLength, captureLength, LITTLE_ENDIAN);
        encodedLength += SIZE_OF_INT;

        encodingBuffer.putInt(offset + encodedLength, length, LITTLE_ENDIAN);
        encodedLength += SIZE_OF_INT;

        encodingBuffer.putLong(offset + encodedLength, nanoClock.nanoTime(), LITTLE_ENDIAN);
        encodedLength += SIZE_OF_LONG;

        return encodedLength;
    }
@Test
    void encodeLogHeaderThrowsIllegalArgumentExceptionIfLengthIsNegative()
    {
        assertThrows(IllegalArgumentException.class,
            () -> internalEncodeLogHeader(buffer, 0, 20, -2, () -> 0));
    }