Protobuf-net - 序列化 .NET GUID - 如何在 C++ 中读取它?

发布于 2024-08-23 18:37:40 字数 302 浏览 5 评论 0原文

我在 .NET 应用程序中使用 Protobuf-net 相对轻松地序列化了一个对象。 我还使用 GetProto() 命令获取 protobuf-net 生成的 .proto 文件。

在 .NET 生成的 .proto 文件中,我的 GUID 字段的类型为“bcl.guid”。

现在我希望用 C++ 编译 .proto 文件,以便可以反序列化数据。

但是,C++ protoc.exe 编译器不知道如何解释 bcl.guid,并抛出错误消息“VideoAudioStructs.proto:11:13:“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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尘世孤行 2024-08-30 18:37:40

protobuf-net 将其编码为字段 1 和 2 处的一对固定长度 64 位值。我还没有出于互操作目的尝试过它,但您可以尝试导入(定制的)bcl.proto(我认为< /em> 这是在部署文件夹中;如果不告诉我,我会添加它;否则它是 在主干)。

但从概念上讲,它只是:

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

如果遇到任何问题,后备方法是通过添加 shim 属性将其作为 bytes 块发送。如果您想要一个例子,请告诉我。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文