本文整理汇总了Python中msgpack.Packer.get_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python Packer.get_bytes方法的具体用法?Python Packer.get_bytes怎么用?Python Packer.get_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类msgpack.Packer
的用法示例。
在下文中一共展示了Packer.get_bytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gen_segment
# 需要导入模块: from msgpack import Packer [as 别名]
# 或者: from msgpack.Packer import get_bytes [as 别名]
def gen_segment(name, method_suffix, arg=None, append_arg_to_name=True):
packer = Packer()
if arg is None:
getattr(packer, 'pack' + method_suffix)()
else:
getattr(packer, 'pack' + method_suffix)(arg)
if append_arg_to_name:
name = name + ' (' + str(arg) + ')'
return OrderedDict(
[('name', name), ('method_suffix', method_suffix), ('b64', packer.get_bytes().encode('base64', 'strict').replace('\n', ''))])
示例2: test_basic_segment
# 需要导入模块: from msgpack import Packer [as 别名]
# 或者: from msgpack.Packer import get_bytes [as 别名]
def test_basic_segment(key):
method_suffix = test_segment['suffix']
read_bytes = test_segment['b64'].decode('base64', 'strict')
unpacker = Unpacker(read_bytes)
read_value = getattr(unpacker, 'unpack' + method_suffix)()
logging.debug('[%s] read %s', key, read_value)
packer = Packer()
if read_value is None:
getattr(packer, 'pack' + method_suffix)()
else:
getattr(packer, 'pack' + method_suffix)(read_value)
write_bytes = packer.get_bytes()
out_b64 = write_bytes.encode('base64', 'strict').replace('\n', '')
if out_b64 != test_segment['b64']:
compare_bytes(convert_bytes(write_bytes), convert_bytes(read_bytes))
assert out_b64 == test_segment['b64']