static <E extends Enum<E>> int encodeRecordingSessionStateChange(
        final UnsafeBuffer encodingBuffer,
        final int offset,
        final int captureLength,
        final int length,
        final E from,
        final E to,
        final long recordingId,
        final long position,
        final String reason)
    {
        int encodedLength = encodeLogHeader(encodingBuffer, offset, captureLength, length);

        encodingBuffer.putLong(offset + encodedLength, recordingId, LITTLE_ENDIAN);
        encodedLength += SIZE_OF_LONG;
        encodingBuffer.putLong(offset + encodedLength, position, LITTLE_ENDIAN);
        encodedLength += SIZE_OF_LONG;

        encodedLength += encodeStateChange(encodingBuffer, offset + encodedLength, from, to);

        encodedLength += encodeTrailingString(encodingBuffer, offset + encodedLength,
            captureLength + LOG_HEADER_LENGTH - encodedLength, reason);

        return encodedLength;
    }
@Test
    void testEncodeRecordingSessionStateChange()
    {
        int offset = 24;
        final int length = recordingSessionStateChangeLength(State.ALPHA, State.BETA, "reason");
        final int captureLength = captureLength(length);

        encodeRecordingSessionStateChange(buffer, offset, captureLength, length,
            State.ALPHA, State.BETA, 1, 2, "reason");

        assertEquals(captureLength, buffer.getInt(offset, LITTLE_ENDIAN));
        assertEquals(length, buffer.getInt(offset + SIZE_OF_INT, LITTLE_ENDIAN));
        assertNotEquals(0, buffer.getLong(offset + 2 * SIZE_OF_INT, LITTLE_ENDIAN));
        offset += LOG_HEADER_LENGTH;

        assertEquals(1, buffer.getLong(offset, LITTLE_ENDIAN));
        offset += SIZE_OF_LONG;
        assertEquals(2, buffer.getLong(offset, LITTLE_ENDIAN));
        offset += SIZE_OF_LONG;
        assertEquals("ALPHA -> BETA", buffer.getStringAscii(offset));
        offset += SIZE_OF_INT + "ALPHA -> BETA".length();
        assertEquals("reason", buffer.getStringAscii(offset));
    }