MessagePack库
此库来自这里.
MessagePack API
导入
local msgpack = require "msgpack"
msgpack.encode(table)
将table序列化为msgpack二进制数据.
msgpack.decode(msgpack_string)
将msgpack二进制数据反序列化为lua table.
示例
参考script/test_msgpack.lua
local Log = require ("logging"):new()
local msgpack = require "msgpack"
local msg = msgpack.encode({1, 2, 3, 4, name = "CandyMi"})
Log:DEBUG("序列化完成:"..msg)
Log:DEBUG(msgpack.decode(msg))
输出结果:
[candy@MacBookPro:~/Documents/core_framework] $ ./cfadmin
[2019-07-17 11:36:19,911] [@script/main.lua:6] [DEBUG] : 序列化完成:��name�CandyMi
[2019-07-17 11:36:19,911] [@script/main.lua:8] [DEBUG] : {[1]=1, [2]=2, [3]=3, [4]=4, ["name"]="CandyMi"}
注意
int64
大整数的精度损失.不支持稀疏数组与
null
填充字段.空表(
{}
)默认转换为数组类型.