Closed llisper closed 6 years ago
貌似问题出在array_int这个repeated类型的值上,如果我删去array_int,那么由python生成的bytes文件使用lua-protobuf解析就没有问题了,尽管生成的二进制文件并不完全一样
pb_ecode_test.zip 这里是一个简洁的例子
知道了...因为proto3中, 对于repeated filed, 默认packed=true。我没有显式设置packed属性,于是会有上面的解析问题。我显式设置packed=true后就可以了。
现在的最新版本的proto3已经是默认packed了,你可以试试看~
涉及的库版本:
问题描述: proto文件定义如下:
填充数据如下(这里我就用lua代码格式来描述了):
使用protoc生成python代码后,使用python代码根据proto定义填充数据并编码写入文件example.bytes, protoc生成的c#代码可以解析example.bytes文件。使用protoc生成FileDescriptorSet(.pb)文件, 在lua中调用pb.load接口载入.pb文件,然后调用pb.decode解析example.bytes文件,会产生报错: type mismatch at offset 39, varint expected for type int32, got bytes 如果我使用lua-protobuf来填充相同的数据并encode写入文件example.bytes, 这个文件就可以同时被lua和c#解析成功。
gen_bytes.zip