本文整理汇总了Python中msgpack_numpy.decode方法的典型用法代码示例。如果您正苦于以下问题:Python msgpack_numpy.decode方法的具体用法?Python msgpack_numpy.decode怎么用?Python msgpack_numpy.decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msgpack_numpy
的用法示例。
在下文中一共展示了msgpack_numpy.decode方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _blocking_request
# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [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
示例2: receive_loop
# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
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
示例3: numpy_unpack
# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
def numpy_unpack(self, data):
return msgpack.unpackb(data[1], object_hook=m.decode)
示例4: receive_loop
# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
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)
示例5: receive_loop
# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
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
示例6: np_deserialize
# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
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))
示例7: unserialize
# 需要导入模块: import msgpack_numpy [as 别名]
# 或者: from msgpack_numpy import decode [as 别名]
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
)