From: FUJITA Tomonori <[email protected]> Signed-off-by: FUJITA Tomonori <[email protected]> Signed-off-by: YAMAMOTO Takashi <[email protected]> --- ryu/lib/rpc.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 ryu/lib/rpc.py
diff --git a/ryu/lib/rpc.py b/ryu/lib/rpc.py new file mode 100644 index 0000000..8455791 --- /dev/null +++ b/ryu/lib/rpc.py @@ -0,0 +1,37 @@ +import msgpack + + +class RpcMessage(object): + REQUEST = 0 + RESPONSE = 1 + NOTIFY = 2 + + +class RpcSession(object): + def __init__(self): + super(RpcSession, self).__init__() + self._packer = msgpack.Packer() + self._unpacker = msgpack.Unpacker() + self._next_msgid = 0 + + def _create_msgid(self): + this_id = self._next_msgid + self._next_msgid += 1 + return this_id + + def create_request(self, method, params): + msgid = self._create_msgid() + return self._packer.pack([RpcMessage.REQUEST, msgid, method, params]) + + def create_response(self, msgid, error, result): + return self._packer.pack([RpcMessage.RESPONSE, msgid, error, result]) + + def create_notification(self, method, params): + return self._packer.pack([RpcMessage.NOTIFY, method, params]) + + def get_messages(self, data): + self._unpacker.feed(data) + messages = [] + for msg in self._unpacker: + messages.append(msg) + return messages -- 1.8.0.1 ------------------------------------------------------------------------------ AlienVault Unified Security Management (USM) platform delivers complete security visibility with the essential security capabilities. Easily and efficiently configure, manage, and operate all of your security controls from a single console and one unified framework. Download a free trial. http://p.sf.net/sfu/alienvault_d2d _______________________________________________ Ryu-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ryu-devel
