public static void insert(
        final UnsafeBuffer termBuffer, final int termOffset, final UnsafeBuffer packet, final int length)
    {
        if (0 == termBuffer.getInt(termOffset))
        {
            termBuffer.putBytes(termOffset + HEADER_LENGTH, packet, HEADER_LENGTH, length - HEADER_LENGTH);

            termBuffer.putLong(termOffset + 24, packet.getLong(24));
            termBuffer.putLong(termOffset + 16, packet.getLong(16));
            termBuffer.putLong(termOffset + 8, packet.getLong(8));

            termBuffer.putLongOrdered(termOffset, packet.getLong(0));
        }
    }
@Test
    void shouldInsertIntoEmptyBuffer()
    {
        final UnsafeBuffer packet = new UnsafeBuffer(ByteBuffer.allocate(256));
        final int termOffset = 0;
        final int srcOffset = 0;
        final int length = 256;
        packet.putInt(srcOffset, length, LITTLE_ENDIAN);

        TermRebuilder.insert(termBuffer, termOffset, packet, length);

        final InOrder inOrder = inOrder(termBuffer);
        inOrder.verify(termBuffer).putBytes(
            termOffset + HEADER_LENGTH, packet, srcOffset + HEADER_LENGTH, length - HEADER_LENGTH);
        inOrder.verify(termBuffer).putLong(termOffset + 24, packet.getLong(24));
        inOrder.verify(termBuffer).putLong(termOffset + 16, packet.getLong(16));
        inOrder.verify(termBuffer).putLong(termOffset + 8, packet.getLong(8));
        inOrder.verify(termBuffer).putLongOrdered(termOffset, packet.getLong(0));
    }