protobuf网 - 序列化.NET GUID - 如何在C ++中阅读? [英] Protobuf-net - serializing .NET GUID - how to read this in C++?

查看:233
本文介绍了protobuf网 - 序列化.NET GUID - 如何在C ++中阅读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经系列化使用protobuf网的对象,在我的.NET应用程序,相对容易。 我也得到了protobuf网产生的.proto文件,使用GetProto()命令。

在.NET生成.proto文件,我的GUID领域得到一种bcl.guid。

现在我希望编译在C .proto文件++这样我就可以反序列化的数据。

不过,C ++编译器protoc.exe不知道如何跨preT bcl.guid,并抛出一个错误信息VideoAudioStructs.proto:11:13:GUID没有定义。 我该怎么做这个吗?

解决方案

protobuf网连接codeS这是一对固定长度的64位值的字段1和2。我还没有尝试过的互操作的目的,但你可以尝试导入(定制)bcl.proto(我的认为的,这是在部署文件夹;如果不让我知道,我会添加它,否则它的在后备箱

但在概念上它仅仅是:

 消息GUID {
  可选fixed64 LO = 1; //前8个字节的GUID
  可选fixed64 HI = 2; //第二个8个字节的GUID
}
 

如果你有任何问题,一个备用的做法是为字节发送(代替)块,通过增加垫片财产。让我知道如果你想要一个很好的例子。

I have serialized an object using Protobuf-net , in my .NET application, with relative ease. I also get the .proto file that protobuf-net generated, using GetProto() command.

In the .NET generated .proto file, my GUID fields get a type of "bcl.guid".

Now I wish to compile the .proto file in C++ so I can deserialize the data.

However, C++ protoc.exe compiler does not know how to interpret bcl.guid, and throws an error message "VideoAudioStructs.proto:11:13: "Guid" is not defined." What do I do with this?

解决方案

protobuf-net encodes this as a pair of fixed-length 64 bit values at fields 1 and 2. I haven't tried it for interop purposes, but you could try importing the (bespoke) bcl.proto (I think this is in the deployment folder; if not let me know and I'll add it; otherwise it is in the trunk).

But conceptually it is just:

message guid {
  optional fixed64 lo = 1; // the first 8 bytes of the guid
  optional fixed64 hi = 2; // the second 8 bytes of the guid
}

If you get any problems, a fallback approach would be to send it (instead) as a bytes chunk, by adding a shim property. Let me know if you want an example of that.

这篇关于protobuf网 - 序列化.NET GUID - 如何在C ++中阅读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆