3
我一直很高兴地在我的一些C++应用程序之间使用protobuf + ZeroMQ一段时间。我需要编写一个C#应用程序。我有Protobuf-NET的工作,并且我相信我终于弄清楚了如何从ZeroMQ消息中反序列化,但是我不能在我的生活中弄清楚如何看到反序列化数据中的消息。 在我的C++应用程序我会反序列化到一个类,我可以简单地做:如何找到我刚刚用protobuf-net反序列化的消息?
if(msg.has_msgTypeX())
blah
我不知道如何做到这一点的protobuf网。
样品.proto文件:
package Messaging;
message Message {
optional string uuid = 1;
optional Map map = 2;
optional Block block = 3;
optional Tile tile = 4;
}
message Map {
repeated Block block = 1;
}
message Block {
repeated Tile tile = 1;
required int32 zCoord = 2;
required int32 version = 3;
}
message Tile {
required int32 xGCoord = 1;
required int32 yGCoord = 2;
required int32 zGCoord = 3;
}
使用这种反序列化:
Messaging.Message msg = ProtoBuf.Serializer.Deserialize<Messaging.Message>(new MemoryStream(zmqMsg.Body));
从这里到?我如何计算消息是否包含Tile,Block或Map消息?
我得到一个意外的符号错误!你能解释继承过程来实现相同的布局吗?我花了很多时间阅读了这个最后一个晚上,并且无法弄清楚Protobuf-NET是如何工作的,因为我是C#的新手(我来自C++)。 –
@ S.Richmond道歉;我的手机肯定已经吃过了= = ...固定 –
那好,编译谢谢。问题得到解答。这是使用protobuf-NET的正确方法吗? –