This commit is contained in:
blueloveTH 2022-12-09 21:45:36 +08:00
parent 65d945e1a1
commit 8bc04389c8
2 changed files with 35 additions and 11 deletions

View File

@ -1,18 +1,31 @@
using PlasticPipe.PlasticProtocol.Messages;
using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using System.Threading.Tasks;
public class JsonRpcServer : MonoBehaviour namespace pkpy
{ {
// Start is called before the first frame update public abstract class JsonRpcServer
void Start()
{ {
protected abstract Task<string> dispatch(ThreadedVM vm, string request);
}
// Update is called once per frame public async Task attach(ThreadedVM vm)
void Update() {
{ while (vm.state <= ThreadState.running) await Task.Yield();
switch (vm.state)
{
case ThreadState.suspended:
string request = vm.read_jsonrpc_request();
string response = await dispatch(vm, request);
vm.write_jsonrpc_response(response);
await attach(vm);
break;
case ThreadState.finished:
break;
default:
throw new Exception("Unexpected state");
}
}
} }
} }

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dd15753450212f045aa08d30ba3cca6e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: