简体   繁体   English

protobuf-csharp-port 和 protobuf-net 如何选择

[英]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 中特定于此实现的一些要点:

  • works with existing types (not just generated types from .proto)适用于现有类型(不仅仅是从 .proto 生成的类型)
  • works under things like WCF and memcached在 WCF 和 memcached 之类的东西下工作
  • can be used to implement ISerializable for existing types可用于为现有类型实现ISerializable
  • supports inheritance* and serialization callback methods支持继承*和序列化回调方法
  • supports common patterns such as ShouldSerialize[name]支持常用模式,例如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)适用于现有的修饰类型( XmlType / XmlElementDataContract / DataMember ) - 意味着(例如)LINQ-to-SQL 模型序列化开箱即用(只要在 DBML 中启用序列化)
  • in v2, works for POCO types without any attributes在 v2 中,适用于没有任何属性的 POCO 类型
  • in v2, works in .NET 1.1 (not sure this is a huge selling feature) and most other frameworks (including monotouch - yay!)在 v2 中,适用于 .NET 1.1(不确定这是一个巨大的销售功能)和大多数其他框架(包括 monotouch - 是的!)
  • possibly (not yet implemented) v2 might support full-graph* serialization (not just tree serialization)可能(尚未实现)v2 可能支持全图* 序列化(不仅仅是树序列化)

(*=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,因为:

  • protobuf-net is more ".net like", ie descriptors to serialise members instead of code generation. protobuf-net 更像“.net”,即序列化成员而不是代码生成的描述符。
  • If you want to compile protobuf-csharp-port .proto files you have to do a 2 step process, ie compile with protoc to .protobin and then compile that with protoGen.如果你想编译 protobuf-csharp-port .proto 文件,你必须做一个 2 步过程,即用 protoc 编译为 .protobin,然后用 protoGen 编译它。 protobuf-net does this in one step. 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.

相关问题 protobuf的-CSHARP端口 - protobuf-csharp-port 如何在 Windows 下在 Mono 上构建 protobuf-csharp-port - How to build protobuf-csharp-port on Mono under Windows protobuf-csharp-port是否支持Windows RT? - Does protobuf-csharp-port support Windows RT? 是否可以在protobuf-csharp-port中检测消息类型? - Is it possible to detect message type in protobuf-csharp-port? 使用带有protobuf-csharp-port的文件记录和重播人类可读的protobuf消息 - Record and replay human-readable protobuf messages using a file with protobuf-csharp-port 使用protobuf-net继承时如何选择字段编号? - How to choose a field number when using protobuf-net inheritance? 有没有办法将protobuf-csharp-port生成的类与servicestack.ormlite一起使用? - Is there way to use protobuf-csharp-port generated classes with servicestack.ormlite? protobuf-csharp-port这些工具最适合今天使用什么版本? - protobuf-csharp-port what version(s) of these tools are best to use today? protobuf-csharp-port-来自文件的流记录有点像LINQ-to-XML中的轴函数 - protobuf-csharp-port - streaming records from a file a bit like an axis function in LINQ-to-XML 协议缓冲区-protobuf-csharp-port:是否存在等效的JAVA API调用CodedInputStream.getBytesUntilLimit()? - Protocol Buffers - protobuf-csharp-port : Does the equivalent of JAVA API call CodedInputStream.getBytesUntilLimit() exist?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM