starwing / lua-protobuf

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

老版本兼容性问题 #115

Closed johnsGuo closed 2 years ago

johnsGuo commented 4 years ago

我们这边早起就开始使用这个pb库,最近因为和外部对接发现老版本uint64解析出现偏差,故升级了lib(升级到当前最新版),但是发现原来的时间戳解析前面都加了个#,所有的长度超过12的数字类型的数据都被动加了#,请问是否有开关设置默认数字类型解析。文档中也有说明 Note: The string returned by int64_as_string or int64_as_hexstring will prefix a '#' character. Because Lua may convert between string with number, prefix a '#' makes Lua return the string as-is. all routines in all module accepts '#' prefix string/hex string as arguments regardless of the option setting.

这个说是不是就是int64_as_string和int64_as_number的设置实际上是没有必要的。

johnsGuo commented 4 years ago

版本平滑升级问题

starwing commented 4 years ago

使用 pb.option "int64_as_number" 能干掉#,但是这样的话可能会导致数字精度出现问题用不用看你们。最新的提交里,大于4294967295的数字才会加上#。

这里说的是,无论选项怎么设置,所有的函数都接受带#的字符串。但是只有提供了string相关选项,decode才会返回带#的字符串。因此选项仍然是有用的。

如果需要数字,可以自行去掉#,加这个只是为了保证精度。

starwing commented 4 years ago

另外应该默认就是“int64_as_number",#的数字范围也没有缩小(最近做了一次扩大),应该是你们主动设置了选项才会带这个#。