aboutsummaryrefslogtreecommitdiff
path: root/netobject.py
diff options
context:
space:
mode:
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())