It's like JSON. but fast and small.
msgpack 支持多种语言,本篇文章主要贴出采用 PYTHON 研究的代码。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# !/usr/bin/env python # encoding:utf-8 import json import msgpack import binascii # 加密 def data_encrypt(data): # msgpack 进行加密 encrypt_result = msgpack.packb(data, use_bin_type=True) # 字符串 转换成 16进制 result = str(binascii.b2a_hex(str(encrypt_result))) # 转换成全大写 return result.upper() # 解密 def data_decrypt(data): # 16 进制 转换成字符串 result = binascii.a2b_hex(data) # msgpack 进行解密 decrypt_result = msgpack.unpackb(result, raw=False) # 返回结果 return decrypt_result if __name__ == '__main__': # 测试数据 data = { "id": 1, "name": "张三", "age": 18 } # 格式成 JSON d = json.dumps(data) print '# 原JSON' print d print "\n# 加密JSON" msg = data_encrypt(data=d) print msg print "\n# 解密JSON" result = data_decrypt(data=msg) print json.loads(result) print "\n# 验证是否JSON格式" print json.loads(result)["name"] |
最新评论
啥时候发啊
等了1年多都没有......
你好 请问thief book安装过程中报错怎么解决
do you have an email to contact ? i got some good NL and LL domains for sale
Hi, so you are a domain investor ?
可以 po 到 https://zhaodao.ai 😄
还以为IP层的C实现 或者是链路层的硬件电路 没想到还是TCP的socket 手动滑稽
加油ヾ(◍°∇°◍)ノ゙
又是技术大佬
他们有专门的机器读取和拷贝,你搜DC-4501电子信息采集。 请问正常卸载能否卸载干净?