From 7000fce72fbec34c6f4957a59d4146cc7148ee59 Mon Sep 17 00:00:00 2001 From: Declan Hoare Date: Thu, 16 Apr 2020 22:58:21 +1000 Subject: Initial Release --- netobject.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 netobject.py (limited to 'netobject.py') diff --git a/netobject.py b/netobject.py new file mode 100644 index 0000000..87673d9 --- /dev/null +++ b/netobject.py @@ -0,0 +1,23 @@ + +import io + +from netclass import netclass, binaryformatter +from payload import PayloadStream + +NetObject = netclass("NetSockets.NetObject", + "NetSockets, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null", + [(str, "Name"), (object, "Object")]) + +class NetObjectStream(PayloadStream): + def payloadReceived(self, payload): + with io.BytesIO(payload) as buf: + obj = binaryformatter.deserialise(buf) + if not isinstance(obj, NetObject): + raise TypeError(f"An object was received on the NetObjectStream of type {type(obj)}") + self.netObjectReceived(obj) + def sendNetObject(self, obj): + if not isinstance(obj, NetObject): + raise TypeError(f"The NetObjectStream can only send NetObject, not {type(obj)}") + with io.BytesIO() as buf: + binaryformatter.serialise(buf, obj) + self.sendPayload(buf.getvalue()) -- cgit v1.2.3