Skynet 中序列化的 protobuf 和 C# 中序列化的 protobuf 得到不同的字节

我不负责也不熟悉 Skynet,但我确定它使用的是 protobuf 版本 3.14.0,并且应该使用 C 语言版本。 我负责 C#(unity3d)端,使用的是从 Nuget 下载的 protobuf 版本 3.14.0。 以下是 .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 的答案,但它们都无法解决这个问题。我需要更多的帮助 T T。我已经在上面花费了三天以上。

如何向服务器发送正确的字节 T T?谢谢~


为了调试。{point={offset=2204, flag=1, color={8}}, mid=1, capital=1},服务器结果为 10 01 18 10 0A 07 10 08 08 9c 11 18 01。C# 结果是 0A 08 08 9C 11 12 01 08 18 01 10 01 18 10。它们都可以在 C# 中正确反序列化。


Skynet 中 protobuf 的版本是 libprotoc 3.14.0

点赞
用户15630025
用户15630025

0 to use the non-packed encoding scheme for repeated objects.

我找到了问题的原因和解决方法。 Protobuf的C#类库默认重复对象都是被打包的,并且在配置之前,libprotoc 3.14.0仍会按照先前的编码方案进行解码。因此,libprotoc 3.14.0无法解码正确的结果。解决方法是配置libprotoc 3.14.0,让其使用非打包编码方案来处理重复的对象。

2021-08-24 08:18:53