protobuf-net 生成的二进制文件是否与 Google 规范兼容
实际上我想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您希望在多个平台上使用相同的 API,Jon Skeet 的实现可能是更适合你。不同之处在于,protobuf-net 是围绕常见的 C# 开发模式设计的,例如,它不要求您使用生成的类型(您可以使用自己的类型,就像使用
DataContractSerializer
一样,< code>XmlSerializer 等) - 并且它直接支持一些 BCL 概念。两者在线上应 100% 兼容,但存在一些 API 差异:
DateTime
、TimeSpan
、Guid< /code> 等(由 zip 中的 bcl.proto 中的合约描述)
您最有可能注意到的是继承。简而言之:如果您计划使用互操作,请不要使用此选项。如果您正在做的事情将使用 .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:
DateTime
,TimeSpan
,Guid
etc (described by the contracts in bcl.proto in the zip)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).
所有 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.