从 skynet 序列化 protobuf 和在 C# 中序列化给出不同的字节
Serializing protobuf from skynet and Serializing in C# gives different bytes
我不负责也不熟悉Skynet,但我确定它使用的是Protobuf 3.14.0版本,应该是c语言版本。
我负责 C#(unity3d) 端,Protobuf 版本 3.14.0,从 Nuget 下载。
这是.proto的一部分:
syntax = "proto3";
...
message tookPoint {
points point = 1;
int32 mid = 2;
int32 capital = 3;
}
message points {
int32 offset = 1;
repeated int32 color = 2;
int32 flag = 3;
}
当我发送
{ "point": { "offset": 5097, "color": [ 7 ], "flag": 1 }, "mid": 1, "capital": 1 }
到服务器,它记录
{point={offset=5097, flag=1, color={5}}, mid=1, capital=1}
我已经搜索了关于C++和lua的答案,但它们对解决problem.I没有用,需要更多帮助T T.I已经花费了3天多的时间。
如何将正确的字节发送到服务器 T T?谢谢~~
Debug.{point={offset=2204, flag=1, color={8}}, mid=1, capital=1}
,server reuslt is 10 01 18 10 0A 07 10 08 08 9c 11 18 01
.C# result is 0A 08 08 9C 11 12 01 08 18 01 10 01 18 10
.两者都可以在C#中正确反序列化.
天网protobuf版本是libprotoc 3.14.0
我已经找到问题的原因和解决方法了。 Protobuf的C#class库默认重复对象全部打包,libprotoc 3.14.0还是按照配置前的编码方案解码。因此,libprotoc 3.14.0 无法解码正确的结果。解决方法是配置libprotoc 3.14.
我不负责也不熟悉Skynet,但我确定它使用的是Protobuf 3.14.0版本,应该是c语言版本。 我负责 C#(unity3d) 端,Protobuf 版本 3.14.0,从 Nuget 下载。 这是.proto的一部分:
syntax = "proto3";
...
message tookPoint {
points point = 1;
int32 mid = 2;
int32 capital = 3;
}
message points {
int32 offset = 1;
repeated int32 color = 2;
int32 flag = 3;
}
当我发送
{ "point": { "offset": 5097, "color": [ 7 ], "flag": 1 }, "mid": 1, "capital": 1 }
到服务器,它记录
{point={offset=5097, flag=1, color={5}}, mid=1, capital=1}
我已经搜索了关于C++和lua的答案,但它们对解决problem.I没有用,需要更多帮助T T.I已经花费了3天多的时间。
如何将正确的字节发送到服务器 T T?谢谢~~
Debug.{point={offset=2204, flag=1, color={8}}, mid=1, capital=1}
,server reuslt is 10 01 18 10 0A 07 10 08 08 9c 11 18 01
.C# result is 0A 08 08 9C 11 12 01 08 18 01 10 01 18 10
.两者都可以在C#中正确反序列化.
天网protobuf版本是libprotoc 3.14.0
我已经找到问题的原因和解决方法了。 Protobuf的C#class库默认重复对象全部打包,libprotoc 3.14.0还是按照配置前的编码方案解码。因此,libprotoc 3.14.0 无法解码正确的结果。解决方法是配置libprotoc 3.14.