~mdkcore/jackplug

f0c3e84c22923b637fb815c6a92a04df9a2c7e4f — Rodrigo Oliveira 4 years ago c2f5435
PA-2589 - Use jsonapi.load directly on JackBase

This avoids the need to import a json library just to deserialize the
received message.
2 files changed, 5 insertions(+), 3 deletions(-)

M examples/jack.py
M jackplug/jack.py
M examples/jack.py => examples/jack.py +0 -2
@@ 11,7 11,6 @@ to the "server".
import sys
from random import randint

from zmq.utils import jsonapi
from zmq.eventloop import ioloop

from jackplug.jack import JackBase


@@ 36,7 35,6 @@ class JackTest(JackBase):
        print("Timeout occurred!")

    def recv(self, message):
        message = jsonapi.loads(message[0])
        print("Recv: %s" % message)

    def send(self):

M jackplug/jack.py => jackplug/jack.py +5 -1
@@ 14,6 14,7 @@ import signal
import uuid

import zmq
from zmq.utils import jsonapi
from zmq.eventloop import ioloop, zmqstream

from .utils import Configuration


@@ 59,7 60,7 @@ class JackBase(object):
        self.socket.connect(endpoint.endpoint)

        self.socket_stream = zmqstream.ZMQStream(self.socket)
        self.socket_stream.on_recv(self.recv)
        self.socket_stream.on_recv(self._recv)

        self._conf = Configuration.instance()
        self._liveness = self._conf.ping_max_liveness


@@ 85,6 86,9 @@ class JackBase(object):
        """Send a ping message to the other endpoint"""
        JackBase.send(self, {"event": "ping", "data": {'id': self._identity}})

    def _recv(self, message):
        self.recv(jsonapi.loads(message[0]))

    def recv(self, message):
        """Receive a message