Closed heyukun4 closed 10 months ago
运行代码
local pb = require "pb" local protoc = require "protoc" -- 直接载入schema (这么写只是方便, 生产环境推荐使用 protoc.new() 接口) assert(protoc:load [[ message Phone { optional string name = 1; optional sfixed64 phonenumber = 2; } message Person { optional string name = 1; optional int32 age = 2; optional string address = 3; repeated Phone contacts = 4; } ]]) -- lua 表数据 local data = { name = "ilse", age = 18, contacts = { { name = "alice", phonenumber = 12312341234 }, { name = "bob", phonenumber = 7822518873084182062 } } } -- 将Lua表编码为二进制数据 local bytes = assert(pb.encode("Person", data)) print(pb.tohex(bytes)) -- 再解码回Lua表 local data2 = assert(pb.decode("Person", bytes)) print(require "serpent".block(data2))
输出结果:
10 12 22 10 11 F2 6A DF DD 02 00 00 00 0A 05 61 6C 69 63 65 22 0E 11 2E BE F8 36 78 2B 8F 6C 0A 03 62 6F 62 0A 04 69 6C 73 65 { age = 18, contacts = { { name = "alice", phonenumber = 12312341234 } --[[table: 0x7f99f310bee0]], { name = "bob", phonenumber = 7.8225188730841825e+18 } --[[table: 0x7f99f310bf50]] } --[[table: 0x7f99f310bea0]], name = "ilse" } --[[table: 0x7f99f310bd10]]
我的lua版本是5.4.6 正常的number输出是没有问题的
有好心人能帮忙看下嘛
没事了, print(require "serpent".block(data2))的问题 :((
运行代码
输出结果:
我的lua版本是5.4.6 正常的number输出是没有问题的
有好心人能帮忙看下嘛