zmq_tools.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:esys-pbi 作者: fsxfreak 项目源码 文件源码
def send(self, topic, payload):
        '''Send a message with topic, payload
`
        Topic is a unicode string. It will be sent as utf-8 encoded byte array.
        Payload is a python dict. It will be sent as a msgpack serialized dict.

        If payload has the key '__raw_data__'
        we pop if of the payload and send its raw contents as extra frames
        everything else need to be serializable
        the contents of the iterable in '__raw_data__'
        require exposing the pyhton memoryview interface.
        '''
        if '__raw_data__' not in payload:
            self.socket.send_string(topic, flags=zmq.SNDMORE)
            self.socket.send(serializer.dumps(payload, use_bin_type=True))
        else:
            extra_frames = payload.pop('__raw_data__')
            assert(isinstance(extra_frames, (list, tuple)))
            self.socket.send_string(topic, flags=zmq.SNDMORE)
            self.socket.send(serializer.dumps(payload), flags=zmq.SNDMORE)
            for frame in extra_frames[:-1]:
                self.socket.send(frame, flags=zmq.SNDMORE, copy=True)
            self.socket.send(extra_frames[-1], copy=True)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号