protobuf-net 生成的二进制文件是否与 Google 规范兼容

发布于 2024-08-28 02:35:36 字数 201 浏览 5 评论 0原文

实际上我想使用 Google 的 java 实现序列化我的数据,然后使用 C# 实现反序列化?
我选择了 protobuf-net,因为它似乎更稳定(proto# 仍然是 v0.9,否则我会选择它)。在开始研究之前,我想确保我可以实现这一目标(使用 java 实现序列化数据并使用 protobuf-net 反序列化)。或者是否有特定于 protobuf-net 实现的方法列表?

Actually I want to serialize my data using Google's java implementation and then deserialize using C# implementation?
I have chosen protobuf-net as it seems to be more stable (proto# is still v0.9 or I would have gone for it). Before I start working on it I wanted to be sure that I can achieve this (serializing data using java implementation and deserializing it using protobuf-net). Or is there any list of methods that are specific to protobuf-net implementation?

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

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

发布评论

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

评论(2

网白 2024-09-04 02:35:36

如果您希望在多个平台上使用相同的 API,Jon Skeet 的实现可能是更适合你。不同之处在于,protobuf-net 是围绕常见的 C# 开发模式设计的,例如,它不要求您使用生成的类型(您可以使用自己的类型,就像使用 DataContractSerializer 一样,< code>XmlSerializer 等) - 并且它直接支持一些 BCL 概念。

两者在线上应 100% 兼容,但存在一些 API 差异:

  • 直接支持 DateTimeTimeSpanGuid< /code> 等(由 zip 中的 bcl.proto 中的合约描述)
  • 支持继承(映射为线路上的嵌套数据)
  • 支持您自己的类型
  • 支持可变类型(而不是构建器) /immutable 对)
  • 对序列化回调的支持
  • (可能还有其他一些 - 您需要 100% 完整的列表吗?)

您最有可能注意到的是继承。简而言之:如果您计划使用互操作,请不要使用此选项。如果您正在做的事情将使用 .NET 特定的技巧,我已尝试在智能感知中使其非常明确,但如果您从 .proto 开始,它无论如何都不会使用这些(它应该便于携带)。

If you want the same API on multiple platforms, Jon Skeet's implementation may be more appropriate to you. The difference is that protobuf-net is designed around common C# development patterns, for example it doesn't demand that you use the generated types (you can use your own, exactly like you can with DataContractSerializer, XmlSerializer, etc) - and it supports some BCL concepts directly.

The two should be 100% compatible on the wire, but here's some API differences:

  • direct support for DateTime, TimeSpan, Guid etc (described by the contracts in bcl.proto in the zip)
  • support for inheritance (mapped as nested data on the wire)
  • support for your own types
  • support for mutable types (rather than the builder/immutable pair)
  • support for serialization callbacks
  • (possibly a few others - do you need a 100% complete list?)

The one you are most likely to notice is inheritance. Simply: don't use this if you are planning to use interop. I have tried to make it very explicit in the intellisense if you are doing something that will use .NET-specific tricks, but if you start from a .proto it won't use these anyway (it should be portable-friendly).

相对绾红妆 2024-09-04 02:35:36

所有 google 序列化都是有线兼容的,尽管 protobuf-net 不是由 Google 编写的,但它 声称与有线兼容

此外,还有一个来自 Google 文档的兼容 C# API 页面。

All the google serializations are wire compatible, and although protobuf-net isn't written by Google, it claims to be wire-compatible.

In addition, there is a page of compatible C# APIs linked from Google's documentation.

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