如何在 protobuf-csharp-port 和 protobuf-net 之间进行选择

发布于 2024-08-26 20:24:51 字数 598 浏览 8 评论 0 原文

我最近不得不寻找最初由 Google 开发的 Protocol Buffers 库的 C# 移植。你猜怎么着,我在这里发现了两个由两个非常知名的人拥有的项目: protobuf- csharp-port,由 Jon SkeetJon Skeet 编写。 google.com/p/protobuf-net/" rel="noreferrer">protobuf-net,作者:Marc格拉维尔。我的问题很简单:我必须选择哪一个?

我非常喜欢 Marc 的解决方案,因为它在我看来更接近 C# 哲学(例如,您可以只向现有类的属性添加属性),并且看起来它可以支持 .NET 内置类型,例如 System.Guid。

我确信它们都是很棒的项目,但您有何看法?

I've recently had to look for a C# porting of the Protocol Buffers library originally developped by Google. And guess what, I found two projects owned both by two very well known persons here: protobuf-csharp-port, written by Jon Skeet and protobuf-net, written by Marc Gravell. My question is simple: which one do I have to choose ?

I quite like Marc's solution as it seems to me closer to C# philisophy (for instance, you can just add attributes to the properties of existing class) and it looks like it can support .NET built-in types such as System.Guid.

I am sure both of them are really great projects but what's your oppinion?

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

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

发布评论

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

评论(5

明明#如月 2024-09-02 20:24:51

我同意乔恩的观点;如果您在多个环境中进行编码,那么他的版本为您提供了与其他“核心”实现类似的 API。 protobuf-net 与大多数 .NET 序列化器的实现方式更加相似,因此 .NET 开发人员更熟悉(IMO)。正如 Jon 指出的那样 - 原始二进制输出应该相同,以便您可以在以后需要时使用不同的 API 重新实现。

protobuf-net 的一些要点特定于此实现:

  • 适用于现有类型(不仅仅是从 .proto 生成的类型)
  • 在 WCF 和 memcached 等环境下工作
  • 可以 为现有类型实现 ISerialized
  • 支持继承*,并且序列化回调方法
  • 支持常见模式,例如 ShouldSerialize[name]
  • 适用于现有修饰类型 (XmlType /XmlElementDataContract/DataMember) - 表示(例如)LINQ-to-SQL 模型序列化开箱即用(只要在
  • v2 中的 DBML 中启用序列化,适用于 v2 中没有任何属性的 POCO 类型
  • ,适用于 .NET 1.1(不确定这是一个巨大的卖点)和大多数其他框架(包括 monotouch - 耶!)
  • < em>可能(尚未实现)v2 可能支持全图*序列化(不仅仅是树序列化)

(*=这些功能使用 100% 有效的 protobuf 二进制文件,但可能很难从其他语言中使用)

I agree with Jon's points; if you are coding over multiple environments, then his version gives you a similar API to the other "core" implementations. protobuf-net is much more similar to how most of the .NET serializers are implemented, so is more familiar (IMO) to .NET devs. And as Jon notes - the raw binary output should be identical so you can re-implement with a different API if you need to later.

Some points re protobuf-net that are specific to this implementation:

  • works with existing types (not just generated types from .proto)
  • works under things like WCF and memcached
  • can be used to implement ISerializable for existing types
  • supports inheritance* and serialization callback methods
  • supports common patterns such as ShouldSerialize[name]
  • works with existing decorated types (XmlType/XmlElement or DataContract/DataMember) - meaning (for example) that LINQ-to-SQL models serialize out-of-the-box (as long as serialization is enabled in the DBML)
  • in v2, works for POCO types without any attributes
  • in v2, works in .NET 1.1 (not sure this is a huge selling feature) and most other frameworks (including monotouch - yay!)
  • possibly (not yet implemented) v2 might support full-graph* serialization (not just tree serialization)

(*=these features use 100% valid protobuf binary, but which might be hard to consume from other languages)

固执像三岁 2024-09-02 20:24:51

您在项目中也在使用其他语言吗?如果是这样,我的 C# 端口将允许您在所有平台上编写类似的代码。如果没有,Marc 的移植可能是更惯用的 C#。 (我试图让我的代码“感觉”像普通的 C#,但设计显然是基于 Java 代码开始的,故意让那些使用 Java 的人也熟悉它。

)这是因为您可以稍后改变主意,并确信您的所有数据仍然通过其他项目有效 - 据我所知,它们应该是绝对二进制兼容的(就序列化数据而言)。

Are you using other languages in your project as well? If so, my C# port will let you write similar code on all platforms. If not, Marc's port is probably more idiomatic C# to start with. (I've tried to make my code "feel" like normal C#, but the design is clearly based on the Java code to start with, deliberately so that it's familiar to those using Java as well.)

Of course one of the beauties of this is that you can change your mind later and be confident that all your data will still be valid via the other project - they should be absolutely binary compatible (in terms of serialized data), as far as I'm aware.

酒绊 2024-09-02 20:24:51

根据它的 GitHub 项目站点 protobuf-csharp-port 现在已被折叠到主要的 Google Protocol Buffers 项目,因此它将是 protobuf 3 的官方 .NET 实现。然而,protobuf-net 是 最后一次更新是在 2013 年,尽管已经有一些最近在 GitHub 上提交

According to it's GitHub project site protobuf-csharp-port has now been folded into the main Google Protocol Buffers project, so it will be the official .NET implementation of protobuf 3. protobuf-net however was last updated in 2013, although there have been some commits recently in GitHub.

吻安 2024-09-02 20:24:51

我刚刚从 protobuf-csharp-port 切换到 protobuf-net,因为:

  • protobuf-net 更像“.net”,即用于序列化成员的描述符而不是代码生成。
  • 如果你想编译 protobuf-csharp-port .proto 文件,你必须执行两步过程,即使用 protoc 编译为 .protobin,然后使用 protoGen 编译它。 protobuf-net 一步完成此操作。

I just switched from protobuf-csharp-port to protobuf-net because:

  • protobuf-net is more ".net like", i.e. descriptors to serialise members instead of code generation.
  • If you want to compile protobuf-csharp-port .proto files you have to do a 2 step process, i.e. compile with protoc to .protobin and then compile that with protoGen. protobuf-net does this in one step.
意中人 2024-09-02 20:24:51

就我而言,我想使用协议缓冲区来替换 .net 客户端和 j2ee 后端之间基于 xml 的通信模型。由于我已经在使用代码生成,因此我将采用 Jon 的实现。

对于不需要 java 互操作的项目,我会选择 Marc 的实现,特别是因为 v2 允许在没有注释的情况下工作。

In my case I want to use protocol buffers to replace an xml based communication model between a .net client and a j2ee backend. Since I'm already using code generation I'll go for Jon's implementation.

For projects not requiring java interop I'd choose Marc's implementation, especially since v2 allows working without annotations.

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