starwing / lua-protobuf

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

用c#传给lua的 byte[] decode正常,但是用decode出来的对象再encode byte[],传回c#就不对了 #141

Closed xiaoniaojjj closed 3 years ago

xiaoniaojjj commented 3 years ago

很奇怪的问题,从服务器接收了一个消息数据byte[],通过pb.decode出来的数据是正常的,但是把数据直接encode之后,用pb.decode也是正常,但是把数据传回c#就不对了,encode后的byte[] 和之前c#传过来的完全不一样,c#那边也无法decode,尝试各种utf转码也不行 printf("CSReceiveMsg id=%s data=%s",idMsg,#bytesMsg); local objMsg = assert(pb.decode('GC_ServerConfig', bytesMsg)) printf("objMsg %s",inspect(objMsg));

local bytes = assert(pb.encode('GC_ServerConfig', objMsg));
objMsg = assert(pb.decode('GC_ServerConfig', bytes)) 
printf("objMsg2 %s",inspect(objMsg));
ToolsCS.printLuaBytes(bytes,bytes);
xiaoniaojjj commented 3 years ago

虽然数据不对但是在c#端反序列化没有问题

starwing commented 3 years ago

所以到底有没有问题呢?decode以后不保证bytes完全一致的,能解码就是对的

xiaoniaojjj commented 3 years ago

所以到底有没有问题呢?decode以后不保证bytes完全一致的,能解码就是对的

数据不一致但是反序列化没有问题,因为业务需求需要保证数据一致,所以通过其他方式解决了

YvanWan commented 1 year ago

请问下如何从C#传递byte数组到lua? 我出现的问题: 'decode' (string/buffer/slice expected, got userdata)