[英]How to choose between protobuf-csharp-port and protobuf-net
I've recently had to look for a C# porting of the Protocol Buffers library originally developped by Google.我最近不得不寻找最初由 Google 开发的 Protocol Buffers 库的 C# 移植。 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 .
猜猜看,我在这里发现了两个非常有名的人拥有的两个项目: protobuf-csharp-port ,由Jon Skeet编写和protobuf-net ,由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.我非常喜欢 Marc 的解决方案,因为在我看来它更接近 C# 哲学(例如,您可以只向现有类的属性添加属性),并且看起来它可以支持 .NET 内置类型,例如 System.Guid。
I am sure both of them are really great projects but what's your oppinion?我相信他们两个都是非常棒的项目,但你有什么看法?
I agree with Jon's points;我同意 Jon 的观点; if you are coding over multiple environments, then his version gives you a similar API to the other "core" implementations.
如果您在多个环境中编码,那么他的版本为您提供了与其他“核心”实现类似的 API。 protobuf-net is much more similar to how most of the .NET serializers are implemented, so is more familiar (IMO) to .NET devs.
protobuf-net 与大多数 .NET 序列化程序的实现方式更相似,因此 .NET 开发人员更熟悉 (IMO)。 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.
正如 Jon 所指出的那样 - 原始二进制输出应该是相同的,因此您可以在以后需要时使用不同的 API 重新实现。
Some points re protobuf-net that are specific to this implementation: protobuf-net 中特定于此实现的一些要点:
ISerializable
for existing typesISerializable
ShouldSerialize[name]
ShouldSerialize[name]
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)XmlType
/ XmlElement
或DataContract
/ DataMember
) - 意味着(例如)LINQ-to-SQL 模型序列化开箱即用(只要在 DBML 中启用序列化) (*=these features use 100% valid protobuf binary, but which might be hard to consume from other languages) (*=这些功能使用 100% 有效的 protobuf 二进制文件,但其他语言可能难以使用)
Are you using other languages in your project as well?您是否也在项目中使用其他语言? If so, my C# port will let you write similar code on all platforms.
如果是这样,我的 C# 端口将允许您在所有平台上编写类似的代码。 If not, Marc's port is probably more idiomatic C# to start with.
如果没有,Marc 的端口可能更符合 C# 习惯。 (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.)
(我试图让我的代码“感觉”像普通的 C#,但设计显然是基于 Java 代码开始的,故意让那些使用 Java 的人也熟悉它。)
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.当然,这样做的好处之一是您可以稍后改变主意,并确信您的所有数据仍将通过另一个项目有效 - 它们应该是绝对二进制兼容的(就序列化数据而言),就我而言我知道。
根据它的GitHub 项目站点protobuf-csharp-port现在已被合并到主要的 Google Protocol Buffers 项目中,因此它将成为 protobuf 3 的官方 .NET 实现。然而,protobuf-net最后一次更新是在 2013 年,尽管已经有最近在 GitHub 上的一些提交。
I just switched from protobuf-csharp-port to protobuf-net because:我刚刚从 protobuf-csharp-port 切换到 protobuf-net,因为:
In my case I want to use protocol buffers to replace an xml based communication model between a .net client and a j2ee backend.就我而言,我想使用协议缓冲区来替换 .net 客户端和 j2ee 后端之间基于 xml 的通信模型。 Since I'm already using code generation I'll go for Jon's implementation.
由于我已经在使用代码生成,因此我将使用 Jon 的实现。
For projects not requiring java interop I'd choose Marc's implementation, especially since v2 allows working without annotations.对于不需要 java interop 的项目,我会选择 Marc 的实现,特别是因为 v2 允许在没有注释的情况下工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.