starwing / lua-protobuf

A Lua module to work with Google protobuf
MIT License
1.75k stars 387 forks source link

int64 decode问题 #179

Open bwb0101 opened 2 years ago

bwb0101 commented 2 years ago

protoc:load [[ message test_type { optional int64 r = 1; } ]]

local chunk = assert(pb.encode("test_type", { r = 10000000000000001 })) print(pb.tohex(chunk)) local t = assert(pb.decode("test_type", chunk)) print(Spb(t))

hex:08 81 80 84 FE A6 DE E1 11 print:LUA: { r = 10000000000000000 } --[[table: 0000026ADFECEE40]]

encode 10000000000000001 并没有问题,hex是正确的,但decode时为啥是10000000000000000,不支持17位长的int64类型吗?

环境: xlua 2.1.15 lua:5.3 lua-protobuf:最新

WangYutian commented 2 years ago

打印一下r的值:print(t.r) -- r = 10000000000000001 说明decode结果也是正确的,应该是serpent打印输出的bug

bwb0101 commented 2 years ago

打印一下r的值:print(t.r) -- r = 10000000000000001 说明decode结果也是正确的,应该是serpent打印输出的bug

是的,的确是serpent的%.17g造成的格式化问题