Python msgpack_numpy.decode() Examples
The following are 7
code examples of msgpack_numpy.decode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
msgpack_numpy
, or try the search function
.
Example #1
Source File: client.py From osim-rl with MIT License | 5 votes |
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
Example #2
Source File: banyan_base_multi.py From python_banyan with GNU Affero General Public License v3.0 | 5 votes |
def receive_loop(self): """ This is the receive loop for zmq messages. This method may be overwritten to meet the needs of the application before handling received messages. :return: """ for element in itertools.cycle(self.backplane_table): if element['subscriber']: try: data = element['subscriber'].recv_multipart(zmq.NOBLOCK) if self.numpy: payload = msgpack.unpackb(data[1], object_hook=m.decode) self.incoming_message_processing(data[0].decode(), payload) else: self.incoming_message_processing(data[0].decode(), umsgpack.unpackb(data[1])) except zmq.error.Again: try: time.sleep(self.loop_time) except KeyboardInterrupt: self.clean_up() sys.exit(0) except AttributeError: raise
Example #3
Source File: banyan_base_aio.py From python_banyan with GNU Affero General Public License v3.0 | 5 votes |
def numpy_unpack(self, data): return msgpack.unpackb(data[1], object_hook=m.decode)
Example #4
Source File: banyan_base_aio.py From python_banyan with GNU Affero General Public License v3.0 | 5 votes |
def receive_loop(self): """ This is the receive loop for Banyan messages. This method may be overwritten to meet the needs of the application before handling received messages. """ while True: data = await self.subscriber.recv_multipart() if self.numpy: payload2 = {} payload = await self.numpy_unpack(data[1]) # convert keys to strings # this compensates for the breaking change in msgpack-numpy 0.4.1 to 0.4.2 for key, value in payload.items(): if not type(key) == str: key = key.decode('utf-8') payload2[key] = value if payload2: payload = payload2 await self.incoming_message_processing(data[0].decode(), payload) else: payload = await self.unpack(data[1]) await self.incoming_message_processing(data[0].decode(), payload)
Example #5
Source File: banyan_base.py From python_banyan with GNU Affero General Public License v3.0 | 5 votes |
def receive_loop(self): """ This is the receive loop for Banyan messages. This method may be overwritten to meet the needs of the application before handling received messages. """ while True: try: data = self.subscriber.recv_multipart(zmq.NOBLOCK) if self.numpy: payload2 = {} payload = msgpack.unpackb(data[1], object_hook=m.decode) # convert keys to strings # this compensates for the breaking change in msgpack-numpy 0.4.1 to 0.4.2 for key, value in payload.items(): if not type(key) == str: key = key.decode('utf-8') payload2[key] = value if payload2: payload = payload2 self.incoming_message_processing(data[0].decode(), payload) else: self.incoming_message_processing(data[0].decode(), msgpack.unpackb(data[1], raw=False)) # if no messages are available, zmq throws this exception except zmq.error.Again: try: if self.receive_loop_idle_addition: self.receive_loop_idle_addition() time.sleep(self.loop_time) except KeyboardInterrupt: self.clean_up() raise KeyboardInterrupt
Example #6
Source File: util.py From multisensory with Apache License 2.0 | 5 votes |
def np_deserialize(s): import msgpack import msgpack_numpy as m return msgpack.unpackb(s, object_hook=m.decode) # return np.load(StringIO.StringIO(s))
Example #7
Source File: serializers.py From lmdb-embeddings with GNU General Public License v3.0 | 5 votes |
def unserialize(self, serialized_vector): """ Unserialize a vector using msgpack. :param bytes serialized_vector: :return np.array: """ return msgpack.unpackb( serialized_vector, object_hook = msgpack_numpy.decode, raw = self._raw )