diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..1ec6b30 --- /dev/null +++ b/__init__.py @@ -0,0 +1,33 @@ +import sys +import struct + +class PulseWire: + def __init__(self): + ... + + def on_raw_engine_request(self, data: bytes): + ... + + def send_raw(self, data: bytes): + sys.stdout.buffer.write(len(data).to_bytes(8, "little")) + sys.stdout.buffer.write(data) + sys.stdout.flush() + + def start(self): + while True: + len_buf = sys.stdin.buffer.read(struct.calcsize("P")) + + if len(len_buf) == 0: + return None + + length = int.from_bytes(len_buf, "little") + + if length == 0: + return None + + buffer = sys.stdin.buffer.read(length) + + if len(buffer) != length: + raise EOFError("Unexpected EOF while reading payload") + + self.on_raw_engine_request(buffer) \ No newline at end of file