47 lines
1.0 KiB
Python
47 lines
1.0 KiB
Python
from typing import Any
|
|
|
|
import sys
|
|
|
|
from phasmplatform.common.config import from_toml
|
|
from phasmplatform.common.router import StdOutRouter
|
|
from phasmplatform.common.value import BaseValue, BytesValue
|
|
|
|
from .runners.base import BaseRunner
|
|
from .runners.wasmtime import WasmTimeRunner
|
|
|
|
|
|
def main() -> int:
|
|
with open('config.toml', 'rb') as fil:
|
|
config = from_toml(fil)
|
|
|
|
del config
|
|
|
|
stdout_router = StdOutRouter()
|
|
|
|
foo: BaseRunner
|
|
|
|
with open('/home/johan/projects/idea/phasm/examples/platform.wasm', 'rb') as fil:
|
|
foo = WasmTimeRunner(stdout_router, fil.read())
|
|
|
|
namespace = b'test-namespace'
|
|
topic = b'test-topic'
|
|
kind = b'test-kind'
|
|
body = b'test-body'
|
|
|
|
foo.handle_message(namespace, topic, kind, body)
|
|
|
|
inp = BytesValue(b'Hello, world!')
|
|
print('inp', inp)
|
|
|
|
def on_respond(out: BaseValue[Any]) -> None:
|
|
print('out', out)
|
|
assert out == inp
|
|
|
|
foo.do_call('echo', [inp], on_respond)
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == '__main__':
|
|
sys.exit(main())
|