private boolean insertRecord(int index, DBRecord record) throws IOException {

		Field key = record.getKeyField();
		int keyLen = key.length();
		if (keyLen > maxKeyLength)
			throw new AssertException("Key exceeds maximum key length of " + maxKeyLength);

		// Check for use of indirect chained record node(s)
		int len = record.length();
		int maxRecordLength = ((buffer.length() - HEADER_SIZE) >> 2) - ENTRY_SIZE - keyLen; // min 4 records per node
		boolean useIndirect = (len > maxRecordLength);
		if (useIndirect) {
			len = 4;
		}

		if ((len + keyLen + ENTRY_SIZE) > getFreeSpace())
			return false;  // insufficient space for record storage

		// Make room for new record
		int offset = moveRecords(index, -(len + keyLen));

		// Make room for new key/offset entry
		int start = HEADER_SIZE + (index * ENTRY_SIZE);
		len = (keyCount - index) * ENTRY_SIZE;
		buffer.move(start, start + ENTRY_SIZE, len);

		// Store new record key/offset
		buffer.putInt(start, offset);
		setKeyCount(keyCount + 1);
		key.write(buffer, offset);

		// Store record data
		if (useIndirect) {
			ChainedBuffer chainedBuffer =
				new ChainedBuffer(record.length(), nodeMgr.getBufferMgr());
			buffer.putInt(offset + keyLen, chainedBuffer.getId());
			record.write(chainedBuffer, 0);
		}
		else {
			record.write(buffer, offset + keyLen);
		}
		enableIndirectStorage(index, useIndirect);

		return true;
	}
Inserts the record at the given index if there is sufficient space in
the buffer. 
@param index insertion index
@param record record to be inserted
@return true if the record was successfully inserted.
@throws IOException thrown if IO error occurs
Ghidra/Framework/DB/src/main/java/db/VarKeyRecordNode.java