代码之家  ›  专栏  ›  技术社区  ›  Joel in Gö

Protobuf网不适用于哪些情况?

  •  5
  • Joel in Gö  · 技术社区  · 16 年前

    我们已经在C应用程序中使用了Binaryserialization,但是需要序列化的类的大小和复杂性会导致Slooooow(反序列化)序列化和大型文件。

    我们怀疑我们应该只编写自己的自定义序列化程序;但是Protobuf NET声称与标准的.NET二进制序列化相比具有显著的速度和大小优势,并且可能比大量定制序列化程序更容易添加到我们的应用程序中。

    在花大量的时间和精力让它为我们工作之前,我想知道是否有任何交易破坏者。我们正在使用接口、抽象子类的通用列表、自定义位标志枚举等定义的属性。什么会阻止protobuf net为我们工作?

    3 回复  |  直到 16 年前
        1
  •  6
  •   Marc Gravell    16 年前

    protobuf net尽其所能遵循核心protobuf规范,然后一些(例如,它包含继承),但是:

    • v1在基于接口的属性(即 ICustomer 等等);我正在努力在第2版中改进这一点
    • v1喜欢有一个无参数的构造函数(这个要求在v2中被提升)
    • 您需要告诉它如何将模型映射到字段;在v1中,这需要在类型(或那里)上进行修饰 是 从名字中推断一些东西的选项;在V2中,这可以从外部完成。
    • 在v1中,标志枚举是一种痛苦;在v2中,有一个选项可以将枚举作为原始整数传递,使其更适合falgs
    • 抽象和继承是可以的,但是你 必须 能够提前确定所有具体类型(将其映射到整数键)
    • 仿制药应该没问题
    • 交错数组/嵌套列表 没有 中间类型不好-您可以通过在中间引入中间类型来填充这一点。
    • 并非所有的核心类型都有内置的支持(例如,新的日期/时间偏移类型);在“v2”中,您可以在必要时为此引入自己的垫片
    • 这是一个 树 序列化程序,而不是 图表 序列化程序;我有一些想法,但还没有实现

    如果您想要序列化的内容有一些有限的例子,我会很高兴地看看它是否可行(我是作者)。

        2
  •  0
  •   Ben Voigt    16 年前

    当您必须与现有软件/现有标准进行交互时,这是不合适的。例如,您不能使用它与SMTP服务器通信。

        3
  •  0
  •   t0mm13b    16 年前

    请在这里读这个 blog 关于Protobuf网,引用

    What’s the catch?
    
    In the most part, that’s it. WCF will use protobuf-net for any suitable 
    objects (data-contracts etc). Note that this is a coarser brush than the 
    per-operation control, though (you could always split the interface into 
    different endpoints, of course).
    
    Also, protobuf-net does have some subtle differences (especially regarding empty 
    objects), so run your unit tests etc.
    
    Note that it only works on the full-fat WCF; it won’t help Silverlight etc, since 
    it lacks the extension features – but that isn’t new here.
    
    Finally, the resolver in WCF is a pain, and AFAIK wants the full assembly details 
    including version number; so one more thing to maintain when you get new versions. 
    If anyone knows how to get around this?