Files
picar/DecisionSystem/messages.py
2019-01-17 14:18:09 +10:30

62 lines
1.2 KiB
Python

import umsgpack
class Message:
def __init__(self, sender = None, data = None):
self._sender = sender
self._data = data
@property
def sender(self):
return self._sender
@property
def data(self):
return self._data
@property
def type(self):
return self._type
@type.setter
def type(self, value):
self._type = value
def serialise(self):
return umsgpack.packb({"type":self.type, "sender": self.sender, "data": self.data})
def deserialise(self, obj):
unpacked = umsgpack.unpackb(obj)
self.type = unpacked["type"]
self.sender = unpacked["sender"]
self.data = unpacked["data"]
return self
class RequestLeader(Message):
_type = "RequestLeader"
class ProposeMessage(Message):
_type = "Propose"
class ElectionVote(Message):
_type = "Elect"
class Commit(Message):
_type = "Commit"
class ConnectSwarm(Message):
_type = "connect"
class RequestVote(Message):
_type = "reqvote"
class ConnectResponse(Message):
_type = "accepted"
class VoterWill(Message):
_type = "disconnectedvoter"
class CommanderWill(Message):
_type = "disconnectedcommander"
class SubmitVote(Message):
_type = "vote"