本文整理匯總了Python中msgpack.unpack方法的典型用法代碼示例。如果您正苦於以下問題:Python msgpack.unpack方法的具體用法?Python msgpack.unpack怎麽用?Python msgpack.unpack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類msgpack
的用法示例。
在下文中一共展示了msgpack.unpack方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load
# 需要導入模塊: import msgpack [as 別名]
# 或者: from msgpack import unpack [as 別名]
def load(f, **kwargs):
""" An overload of msgpack.load that works with pyGSTi types """
decoded_msgpack = _msgpack.unpack(f, **kwargs) # load normal MSGPACK
return decode_obj(decoded_msgpack, msgpack_uses_binary_strs) # makes pygsti objects
示例2: load_stored_trajs
# 需要導入模塊: import msgpack [as 別名]
# 或者: from msgpack import unpack [as 別名]
def load_stored_trajs(load_from):
"""Return trajectories storead at load_from/trajs.data."""
file_path = os.path.join(load_from, 'trajs.data')
with open(file_path, 'rb') as file:
trajs = msgpack.unpack(file)
# convert byte keys back to string keys:
trajs = [{
key.decode('utf-8') if isinstance(key, bytes) else key: traj[key]
for key in traj.keys()
} for traj in trajs]
return trajs
示例3: load
# 需要導入模塊: import msgpack [as 別名]
# 或者: from msgpack import unpack [as 別名]
def load(fp, object_hook=None):
return msgpack.unpack(fp, object_hook=object_hook, encoding='utf8')
示例4: __init__
# 需要導入模塊: import msgpack [as 別名]
# 或者: from msgpack import unpack [as 別名]
def __init__(self, count=0, term=None, data={}):
self.count = count
self.term = term
self.data = data
self.path = os.path.join(config.storage, 'compact')
# load
logger.debug('Initializing compactor')
if count or term or data:
self.persist()
logger.debug('Using parameters')
elif os.path.isfile(self.path):
with open(self.path, 'rb') as f:
self.__dict__.update(msgpack.unpack(f, encoding='utf-8'))
logger.debug('Using persisted data')
示例5: _load_msgpack
# 需要導入模塊: import msgpack [as 別名]
# 或者: from msgpack import unpack [as 別名]
def _load_msgpack(self, path, encoding):
with open(path, "rb") as in_file:
return msgpack.unpack(in_file, encoding=encoding)
示例6: parse
# 需要導入模塊: import msgpack [as 別名]
# 或者: from msgpack import unpack [as 別名]
def parse(self, stream, media_type=None, parser_context=None):
if not msgpack:
raise _import_error
return msgpack.unpack(stream, use_list=False, encoding='utf-8')