本文整理汇总了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)