starwing / lua-protobuf

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

int64 不支持吗?解析超过32位的int64的时候显示负数了,有解决方案吗 #50

Closed xinjuncoding closed 6 years ago

starwing commented 6 years ago

你用的什么版本的Lua?5.3应该是不会有负数的,我这里试了下:

local pb = require "pb"
local protoc = require "protoc"

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

local chunk = assert(pb.encode("test_type", { r = 0xFFFFFFFFF }))
print(pb.tohex(chunk))
local t = assert(pb.decode("test_type", chunk))
print(require "serpent".block(t))

输出:

$ lua  -- test1.lua
08 FF FF FF FF FF 01
{
  r = 68719476735
} --[[table: 0x7ffb8d5164c0]]
GetOverMVP commented 6 years ago

luajit2.1和lua5.1有什么解决的办法吗?

starwing commented 6 years ago

可能没什么太好的办法,看你需要怎么用。比如说我输出字符串?或者base64神马的?

xinjuncoding commented 6 years ago

用的lua5.1版本,我改了一下,用字符串形式传递了

abincai commented 5 years ago

用的lua5.1版本,我改了一下,用字符串形式传递了

直接在底层改造吗?能分享下?

starwing commented 5 years ago

@abincai 现在官方支持字符串64位了,直接传递"#12345"就行,12345支持64位数字