aboutsummaryrefslogtreecommitdiff
path: root/netobject.py
diff options
context:
space:
mode:
authorDeclan Hoare <[email protected]>2020-04-16 22:58:21 +1000
committerDeclan Hoare <[email protected]>2020-04-16 23:10:44 +1000
commit7000fce72fbec34c6f4957a59d4146cc7148ee59 (patch)
tree5affe93d68a7fbcc6cf85a4d9a3eedecc730d1f7 /netobject.py
downloadshiftgears-7000fce72fbec34c6f4957a59d4146cc7148ee59.tar.gz
shiftgears-7000fce72fbec34c6f4957a59d4146cc7148ee59.tar.bz2
shiftgears-7000fce72fbec34c6f4957a59d4146cc7148ee59.zip
Initial Release
Diffstat (limited to 'netobject.py')
-rw-r--r--netobject.py23
1 files changed, 23 insertions, 0 deletions
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())