當前位置: 首頁>>代碼示例>>Python>>正文


Python msgpack_numpy.encode方法代碼示例

本文整理匯總了Python中msgpack_numpy.encode方法的典型用法代碼示例。如果您正苦於以下問題:Python msgpack_numpy.encode方法的具體用法?Python msgpack_numpy.encode怎麽用?Python msgpack_numpy.encode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在msgpack_numpy的用法示例。


在下文中一共展示了msgpack_numpy.encode方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: set_subscriber_topic

# 需要導入模塊: import msgpack_numpy [as 別名]
# 或者: from msgpack_numpy import encode [as 別名]
def set_subscriber_topic(self, topic, subscriber_socket):
        """
        This method sets a subscriber topic.

        You can subscribe to multiple topics by calling this method for
        each topic.

        :param topic: A topic string

        :param subscriber_socket: subscriber socket

        :return:
        """

        # make sure topic is a string
        if not type(topic) is str:
            raise TypeError('Subscriber topic must be python_banyan string')

        # does the subscriber socket exist?
        if subscriber_socket:
            subscriber_socket.setsockopt(zmq.SUBSCRIBE, topic.encode())
        else:
            raise ValueError('set_subscriber_topic: socket is None') 
開發者ID:MrYsLab,項目名稱:python_banyan,代碼行數:25,代碼來源:banyan_base_multi.py

示例2: unsubscribe_topic

# 需要導入模塊: import msgpack_numpy [as 別名]
# 或者: from msgpack_numpy import encode [as 別名]
def unsubscribe_topic(self, topic, subscriber_socket):
        """
        This method un-subscribes from a topic.

        :param topic: A topic string

        :param subscriber_socket: subscriber socket

        :return:
        """

        # make sure topic is a string
        if not type(topic) is str:
            raise TypeError('Subscriber topic must be python_banyan string')

        # make sure that a socket reference has been passed in
        if subscriber_socket:
            subscriber_socket.unsubscribe(topic.encode())
        else:
            raise ValueError('set_subscriber_topic: socket is None') 
開發者ID:MrYsLab,項目名稱:python_banyan,代碼行數:22,代碼來源:banyan_base_multi.py

示例3: publish_payload

# 需要導入模塊: import msgpack_numpy [as 別名]
# 或者: from msgpack_numpy import encode [as 別名]
def publish_payload(self, payload, topic=''):
        """
        This method will publish a python_banyan payload and its associated topic

        :param payload: Protocol message to be published

        :param topic: A string value
        """

        # make sure the topic is a string
        if not type(topic) is str:
            raise TypeError('Publish topic must be python_banyan string', 'topic')

        if self.numpy:
            message = await self.numpy_pack(payload)
        else:
            message = await self.pack(payload)

        pub_envelope = topic.encode()
        await self.publisher.send_multipart([pub_envelope, message])
        # await asyncio.sleep(1) 
開發者ID:MrYsLab,項目名稱:python_banyan,代碼行數:23,代碼來源:banyan_base_aio.py

示例4: publish_payload

# 需要導入模塊: import msgpack_numpy [as 別名]
# 或者: from msgpack_numpy import encode [as 別名]
def publish_payload(self, payload, topic=''):
        """
        This method will publish a python_banyan payload and its associated topic

        :param payload: Protocol message to be published

        :param topic: A string value
        """

        # make sure the topic is a string
        if not type(topic) is str:
            raise TypeError('Publish topic must be python_banyan string', 'topic')

        # create python_banyan message pack payload
        if self.numpy:
            message = msgpack.packb(payload, default=m.encode)
        else:
            message = msgpack.packb(payload, use_bin_type=True)

        pub_envelope = topic.encode()
        self.publisher.send_multipart([pub_envelope, message]) 
開發者ID:MrYsLab,項目名稱:python_banyan,代碼行數:23,代碼來源:banyan_base.py

示例5: _generate_response_channel

# 需要導入模塊: import msgpack_numpy [as 別名]
# 或者: from msgpack_numpy import encode [as 別名]
def _generate_response_channel(self):
        random_hash = hashlib.md5("{}".format(random.randint(0, 10**10)).encode('utf-8')).hexdigest()
        response_channel = "{}::{}::response::{}".format(   self.namespace,
                                                            self.service_id,
                                                            random_hash)
        return response_channel 
開發者ID:stanfordnmbl,項目名稱:osim-rl,代碼行數:8,代碼來源:client.py

示例6: _blocking_request

# 需要導入模塊: import msgpack_numpy [as 別名]
# 或者: from msgpack_numpy import encode [as 別名]
def _blocking_request(self, _request):
        """
            request:
                -command_type
                -payload
                -response_channel
            response: (on response_channel)
                - RESULT
            * Send the payload on command_channel (self.namespace+"::command")
                ** redis-left-push (LPUSH)
            * Keep listening on response_channel (BLPOP)
        """
        assert type(_request) ==type({})
        _request['response_channel'] = self._generate_response_channel()

        _redis = self.get_redis_connection()
        """
            The client always pushes in the left
            and the service always pushes in the right
        """
        if self.verbose: print("Request : ", _response)
        # Push request in command_channels
        payload = msgpack.packb(_request, default=m.encode, use_bin_type=True)
        _redis.lpush(self.command_channel, payload)
        ## TODO: Check if we can use `repr` for json.dumps string serialization
        # Wait with a blocking pop for the response
        _response = _redis.blpop(_request['response_channel'])[1]
        if self.verbose: print("Response : ", _response)
        _response = msgpack.unpackb(_response, object_hook=m.decode, encoding="utf8")
        if _response['type'] == messages.OSIM_RL.ERROR:
            raise Exception(str(_response))
        else:
            return _response 
開發者ID:stanfordnmbl,項目名稱:osim-rl,代碼行數:35,代碼來源:client.py

示例7: publish_payload

# 需要導入模塊: import msgpack_numpy [as 別名]
# 或者: from msgpack_numpy import encode [as 別名]
def publish_payload(self, payload, publisher_socket, topic=''):
        """
        This method will publish a python_banyan payload and its associated topic

        :param payload:  Protocol message to be published

        :param publisher_socket: Publisher socket - handle to socket or "BROADCAST" to send to
                                 all connected publisher sockets

        :param topic: A string value for message topic

        :return:
        """

        # make sure topic is a string
        if not type(topic) is str:
            raise TypeError('Publish topic must be python_banyan string', 'topic')

        # create python_banyan message pack payload
        if self.numpy:
            message = msgpack.packb(payload, default=m.encode)
        else:
            message = umsgpack.packb(payload)

        pub_envelope = topic.encode()
        if publisher_socket == "BROADCAST":
            for element in self.backplane_table:
                if element['publisher']:
                    element['publisher'].send_multipart([pub_envelope, message])
        else:

            if publisher_socket:
                publisher_socket.send_multipart([pub_envelope, message])
            else:
                raise ValueError('Invalid publisher socket') 
開發者ID:MrYsLab,項目名稱:python_banyan,代碼行數:37,代碼來源:banyan_base_multi.py

示例8: numpy_pack

# 需要導入模塊: import msgpack_numpy [as 別名]
# 或者: from msgpack_numpy import encode [as 別名]
def numpy_pack(self, data):
        return msgpack.packb(data, default=m.encode) 
開發者ID:MrYsLab,項目名稱:python_banyan,代碼行數:4,代碼來源:banyan_base_aio.py

示例9: set_subscriber_topic

# 需要導入模塊: import msgpack_numpy [as 別名]
# 或者: from msgpack_numpy import encode [as 別名]
def set_subscriber_topic(self, topic):
        """
        This method sets a subscriber topic.

        You can subscribe to multiple topics by calling this method for
        each topic.

        :param topic: A topic string
        """

        if not type(topic) is str:
            raise TypeError('Subscriber topic must be python_banyan string')

        self.subscriber.setsockopt(zmq.SUBSCRIBE, topic.encode()) 
開發者ID:MrYsLab,項目名稱:python_banyan,代碼行數:16,代碼來源:banyan_base.py

示例10: np_serialize

# 需要導入模塊: import msgpack_numpy [as 別名]
# 或者: from msgpack_numpy import encode [as 別名]
def np_serialize(x):
  import msgpack
  import msgpack_numpy as m
  return msgpack.packb(np.array(x, 'float32'), default=m.encode)
  #return msgpack.packb(x, default=m.encode)
  # f = StringIO.StringIO()
  # np.save(f, x)
  # return f.getvalue() 
開發者ID:andrewowens,項目名稱:multisensory,代碼行數:10,代碼來源:util.py

示例11: serialize

# 需要導入模塊: import msgpack_numpy [as 別名]
# 或者: from msgpack_numpy import encode [as 別名]
def serialize(vector):
        """ Serializer a vector using msgpack.

        :param np.array vector:
        :return bytes:
        """
        return msgpack.packb(vector, default = msgpack_numpy.encode) 
開發者ID:ThoughtRiver,項目名稱:lmdb-embeddings,代碼行數:9,代碼來源:serializers.py


注:本文中的msgpack_numpy.encode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。