本文整理匯總了Python中msgpack.pack方法的典型用法代碼示例。如果您正苦於以下問題:Python msgpack.pack方法的具體用法?Python msgpack.pack怎麽用?Python msgpack.pack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類msgpack
的用法示例。
在下文中一共展示了msgpack.pack方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: dump
# 需要導入模塊: import msgpack [as 別名]
# 或者: from msgpack import pack [as 別名]
def dump(obj, f, **kwargs):
""" An overload of msgpack.dump that works with pyGSTi types """
enc = encode_obj(obj, msgpack_uses_binary_strs)
_msgpack.pack(enc, f, **kwargs)
示例2: store_trajs
# 需要導入模塊: import msgpack [as 別名]
# 或者: from msgpack import pack [as 別名]
def store_trajs(trajs, store_to):
"""Store trajectories to store_to/trajs.data."""
if not os.path.exists(store_to):
os.makedirs(store_to)
file_path = os.path.join(store_to, 'trajs.data')
with open(file_path, 'wb') as file:
msgpack.pack(trajs, file)
示例3: dump
# 需要導入模塊: import msgpack [as 別名]
# 或者: from msgpack import pack [as 別名]
def dump(obj, fp, default=None):
msgpack.pack(obj, fp, use_bin_type=True, default=default)
示例4: persist
# 需要導入模塊: import msgpack [as 別名]
# 或者: from msgpack import pack [as 別名]
def persist(self):
with open(self.path, 'wb+') as f:
raw = {'count': self.count, 'term': self.term, 'data': self.data}
msgpack.pack(raw, f, use_bin_type=True)
示例5: dump
# 需要導入模塊: import msgpack [as 別名]
# 或者: from msgpack import pack [as 別名]
def dump(obj, fp, registry=None):
"""Serialize ``obj`` as a messagepack formatted stream to ``fp``.
.. versionchanged:: 1.5
Added *registry* parameter.
"""
if registry is None:
registry = default_registry
return msgpack.pack(obj, fp,
default=functools.partial(_serializer, registry),
use_bin_type=True)
示例6: dump
# 需要導入模塊: import msgpack [as 別名]
# 或者: from msgpack import pack [as 別名]
def dump(self, file_path, obj, encoding="utf-8"):
path = self.cache_path / file_path
path.parent.mkdir(parents=True, exist_ok=True)
try:
with open(path.with_suffix(".msgpack"), "wb") as out_file:
msgpack.pack(obj, out_file, encoding=encoding)
except TypeError:
os.remove(path.with_suffix(".msgpack"))
with open(path.with_suffix(".pkl"), "wb") as out_file:
pickle.dump(obj, out_file, protocol=pickle.HIGHEST_PROTOCOL)